ansible源码编译安装php7.4,基于fastcgi

该博客介绍了如何使用Ansible自动化工具,在主机10.0.0.171上安装PHP7.4并配置FastCGI。步骤包括安装必要的依赖包、下载并解压PHP和libgd源码、编译安装libgd和PHP、配置环境变量、创建目录、编辑配置文件以及启动PHP-FPM服务。这个过程涵盖了系统包管理、源码编译和服务器配置等多个方面。
摘要由CSDN通过智能技术生成
---
#install php7.4 with fastcgi
- hosts: 10.0.0.171
  gather_facts: no
  vars:
    phpver: php-7.4.20
    phpsrc: "{{phpver}}.tar.gz"
    dir: /data/php
    libgdver: libgd-2.3.1
    libgdsrc: libgd-2.3.1.tar.gz
  tasks: 
    - name: install necessary packs
      yum: 
        name: 
          - libxml2 
          - libxml2-devel
          - openssl 
          - openssl-devel 
          - bzip2 
          - bzip2-devel
          - libcurl
          - libcurl-devel
          - libjpeg 
          - libjpeg-devel 
          - libpng
          - libpng-devel 
          - freetype 
          - freetype-devel
          - gmp 
          - gmp-devel 
          - libmcrypt 
          - libmcrypt-devel 
          - readline
          - readline-devel 
          - libxslt 
          - libxslt-devel 
          - libsqlite3x-devel
          - oniguruma-devel
          - rsync
    - name: download php and unarchive
      unarchive: remote_src=no src={{phpsrc}} dest=/usr/local/src
      register: var1
      until: var1 is succeeded
    - name: download libgd and unarchive
      unarchive: remote_src=no src={{libgdsrc}} dest=/usr/local/src
      register: var2
      until: var2 is succeeded
      retries: 5
    - name: compile libgd
      shell: |
        chdir=/usr/local/src/{{libgdver}}
        ./configure --prefix=/usr/local/{{libgdver}}
        make -j 4
        make install 
    - name: make dir {{dir}}
      file: path={{dir}} state=directory
    - name: configure
      shell: |
        chdir=/usr/local/src/{{phpver}}
        export PKG_CONFIG_PATH=/usr/local/{{libgdver}}/lib/pkgconfig
        ./configure \
        --prefix={{dir}} \
        --with-config-file-path=/etc \
        --with-config-file-scan-dir=/etc/php.d \
        --enable-gd  \
        --with-external-gd  \
        --enable-gd-jis-conv \
        --enable-mysqlnd \
        --with-mysqli=mysqlnd \
        --with-pdo-mysql=mysqlnd \
        --with-openssl   \
        --with-zlib \
        --with-freetype \
        --with-jpeg \
        --with-curl \
        --enable-mbstring \
        --enable-xml \
        --enable-sockets \
        --enable-fpm \
        --enable-maintainer-zts \
        --disable-fileinfo 
        make -j 4 && make install
    - name: path1
      copy: 
        content: "PATH={{dir}}/bin:/apps/httpd/bin:$PATH"
        dest: /etc/profile.d/lamp.sh
    - name: path2
      shell: . /etc/profile.d/lamp.sh
    - name: prepare etc and service
      synchronize: src="{{item.src}}" dest="{{item.dest}}"
      loop:
        - {src: "/usr/local/src/{{phpver}}/php.ini-production" , dest: /etc/php.ini }
        - {src: "/usr/local/src/{{phpver}}/sapi/fpm/php-fpm.service" , dest: /usr/lib/systemd/system/}
        - {src: "{{dir}}/etc/php-fpm.conf.default" , dest: "{{dir}}/etc/php-fpm.conf"}
        - {src: "{{dir}}/etc/php-fpm.d/www.conf.default" , dest: "{{dir}}/etc/php-fpm.d/www.conf"}
      delegate_to: "{{ inventory_hostname }}"
    - name: edit php-fpm1
      lineinfile: path="{{dir}}/etc/php-fpm.d/www.conf" regexp="^user"  line="user = apache"
    - name: edit php-fpm2
      lineinfile: path="{{dir}}/etc/php-fpm.d/www.conf" regexp="^group"  line="group = apache"
    - name: edit php-fpm3
      lineinfile: path="{{dir}}/etc/php-fpm.d/www.conf" regexp="^;pm\.status_path.*"  line="pm.status_path = /fpm_status" 
    - name: edit php-fpm4
      replace: path="{{dir}}/etc/php-fpm.d/www.conf" regexp="^;(ping\.path.*)"  replace="\1" 
    - name: mkdir /etc/php.d
      file: name=/etc/php.d state=directory
    - name: opcache
      copy: 
        content: |
           [opcache]
           zend_extension=opcache.so              
           opcache.enable=1
        dest: /etc/php.d/opcache.ini
    - name: start service
      service: name=php-fpm state=started enabled=yes

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值