依赖安装

  • yum包

    yum install -y autoconf freetype freetype-devel gd libpng libpng-devel \
    libjpeg libjpeg-devel libxml2 libxml2-devel zlib curl curl-devel \
    net-snmp-devel php-ldap openldap-devel openldap-clients gmp-devel \
    libzip libzip-devel sqlite-devel libxslt-devel openssl-devel
  • oniguruma

    yum install autoconf automake libtool -y
    wget https://github.com/kkos/oniguruma/archive/v6.9.4.tar.gz -O oniguruma-6.9.4.tar.gz
    tar xf oniguruma-6.9.4.tar.gz && cd oniguruma-6.9.4
    ./autogen.sh && ./configure --prefix=/usr
    make && make install

php 7.4编译安装

  1. 下载、

    wget https://www.php.net/distributions/php-7.4.28.tar.gz
  2. 解压

    tar zxvf php-7.4.28.tar.gz
  3. 生成配置文件

    ./configure \
    --prefix=/opt/php7.4 \
    --enable-fpm \
    --with-fpm-user=nginx \
    --with-fpm-group=nginx \
    --with-config-file-path=/opt/php7.4/etc \
    --disable-ipv6 \
    --with-libxml-dir \
    --enable-ftp \
    --with-openssl \
    --with-zlib \
    --with-curl \
    --enable-gd \
    --with-jpeg \
    --with-freetype \
    --enable-mbstring \
    --enable-sockets \
    --with-xmlrpc \
    --with-iconv-dir=/usr/local/libiconv \
    --with-mysqli=mysqlnd \
    --with-pdo-mysql=mysqlnd \
    --enable-mysqlnd \
    --enable-mysqlnd-compression-support \
    --enable-static
  4. 编译安装

    make -j12 && make install
    # 参数注解:
    # --prefix=/opt/php7.4 安装位置
    # --enable-fpm 进程管理器
    # --with-fpm-user=nginx 进程管理器进程守护者
    # --with-fpm-group=nginx 进程管理器进程守护者的用户组
    # --with-config-file-path=/opt/php7.4/etc 配置文件位置
    # --disable-ipv6 禁用ipv6
    # --with-libxml-dir XML解析
    # --enable-ftp FTP
    # --with-openssl 加密
    # --with-zlib 压缩
    # --with-curl curl抓取文件
    # --enable-gd gd库(图片相关)
    # --with-jpeg 图片相关
    # --with-freetype 字体
    # --enable-mbstring 编码
    # --enable-soap 编写SOAP服务端和客户端
    # --enable-sockets socket
    # --with-xmlrpc XML-RPC
    # --with-iconv-dir=/usr/local/libiconv iconv函数(字符编码强制转换)
    # --with-mysqli=mysqlnd PHP源码提供的mysql驱动连接代码,它的目的是代替旧的libmysql驱动
    # --with-pdo-mysql=mysqlnd
    # --enable-mysqlnd
    # --enable-mysqlnd-compression-support
    # --enable-static 生成静态链接库
    # --with-gd gd库
    # --with-jpeg-dir
    # --with-png-dir

配置文件

  • 备份并准备配置文件

    cp php.ini-* /opt/php7.4/etc/ # 备份
    cp php.ini-development /opt/php7.4/etc/php.ini # 拷贝配置文件
    
    cp /opt/php7.4/etc/php-fpm.conf.default /opt/php7.4/etc/php-fpm.conf
    cp /opt/php7.4/etc/php-fpm.d/www.conf.default /opt/php7.4/etc/php-fpm.d/www.conf
  • www.conf

    sed -i '/^listen = 127.0.0.1:9000/s/^/;/' /opt/php7.4/etc/php-fpm.d/www.conf
    sed -i '/^;listen = 127.0.0.1:9000/a listen = \/opt\/php7.4\/var\/run\/www.sock' /opt/php7.4/etc/php-fpm.d/www.conf
  • php-fpm.conf

    sed -i '/^;pid = run\/php-fpm.pid/a pid = \/opt\/php7.4\/var\/run\/php-fpm.pid' /opt/php7.4/etc/php-fpm.conf
  • 文件授权

    chown nginx:nginx -R /opt/php7.4
  • 注册系统服务

    # 生成systemctl管理脚本
    cat > /lib/systemd/system/php-fpm-7.4.service << END
    [Unit]
    Description=phpfpm service
    After=network.target syslog.target
    
    [Service]
    Type=forking
    User=nginx
    Group=nginx
    PIDFile=/opt/php7.4/var/run/php-fpm.pid
    ExecStart=/opt/php7.4/sbin/php-fpm
    ExecReload=/bin/kill -s HUP $MAINPID
    ExecStop=/bin/kill -s QUIT $MAINPID
    
    [Install]
    WantedBy=multi-user.target
    END
  • 开机自启动并立即启动

    systemctl enable php-fpm-7.4.service --now

systemctl命令主要有两大功能

控制systemd系统
管理系统上运行的服务
  • systemctl 常用命令
  1. 启动服务

    systemctl start 服务名
  2. 停止服务

    systemctl stop 服务名
  3. 重启服务

    systemctl restart 服务名
  4. 查看服务是否已启动

    systemctl is-active 服务名
  5. 查看服务的状态

    systemctl status 服务名
  6. 启用开机自启动服务

    systemctl enable 服务名
  7. 停用开机自启动服务

    systemctl disable 服务名
  8. 查看服务是否为开机自启动

    systemctl is-enabled 服务名
  9. 只重启正在运行中的服务

    systemctl try-restart 服务名
  10. 显示所有的服务状态—空格翻页 q推出

    systemctl list-units --type service --all
  11. 查看启动成功的服务列表

    systemctl list-unit-files|grep enabled
  12. 查看启动失败的服务列表

    systemctl --failed
  13. 查看所有服务的状态—空格翻页 q推出

    systemctl list-unit-files --type service