Linux安装PHP(最新版)

  1. 在线文档(安装说明)
    Linux安装PHP(最新版)_第1张图片
  2. 安装依赖
    yum -y install autoconf build-essential curl libtool \
      libssl-dev libcurl4-openssl-dev libxml2-dev libreadline7 \
      libreadline-dev libzip-dev libzip4 nginx openssl \
      pkg-config zlib1g-dev
      
    yum -y install libxml2-devel sqlite-devel libcurl-devel oniguruma-devel postgresql-devel readline-devel
    
    wget https://yum.oracle.com/repo/OracleLinux/OL7/latest/x86_64/getPackage/oniguruma-5.9.5-3.el7.x86_64.rpm
    wget https://yum.oracle.com/repo/OracleLinux/OL7/latest/x86_64/getPackage/oniguruma-devel-5.9.5-3.el7.x86_64.rpm
    yum -y localinstall oniguruma-5.9.5-3.el7.x86_64.rpm
    yum -y localinstall oniguruma-devel-5.9.5-3.el7.x86_64.rpm
    rm -rf oniguruma-5.9.5-3.el7.x86_64.rpm oniguruma-devel-5.9.5-3.el7.x86_64.rpm
  3. 安装目录
    mkdir /opt/php && cd /opt/php
  4. 安装包下载
    wget https://www.php.net/distributions/php-8.1.12.tar.gz
    注意:https://www.php.net/downloads获取最新版本下载链接并替换
  5. 安装包解压
    tar -zxvf php-8.1.12.tar.gz && rm -rf php-8.1.12.tar.gz
  6. 安装配置
    cd /opt/php/php-8.1.12
    ./configure --prefix=/opt/php/php-8.1.12 \
        --enable-mysqlnd \
        --with-pdo-mysql \
        --with-pdo-mysql=mysqlnd \
        --with-pdo-pgsql=/usr/bin/pg_config \
        --enable-bcmath \
        --enable-fpm \
        --with-fpm-user=www-data \
        --with-fpm-group=www-data \
        --enable-mbstring \
        --enable-phpdbg \
        --enable-shmop \
        --enable-sockets \
        --enable-sysvmsg \
        --enable-sysvsem \
        --enable-sysvshm \
        --enable-zip \
        --with-libzip=/usr/lib/x86_64-linux-gnu \
        --with-zlib \
        --with-curl \
        --with-pear \
        --with-openssl \
        --enable-pcntl \
        --with-readline
  7. 编译安装 
    make && make install
  8. 配置文件
    cp /opt/php/php-8.1.12/php.ini-development /opt/php/php-8.1.12/lib/
    mv /opt/php/php-8.1.12/etc/php-fpm.conf.default /opt/php/php-8.1.12/etc/php-fpm.conf
    mv /opt/php/php-8.1.12/etc/php-fpm.d/www.conf.default /opt/php/php-8.1.12/etc/php-fpm.d/www.conf
  9. 环境变量 
    echo "export PHP_HOME=/opt/php/php-8.1.12" >> /etc/profile
    echo "export PATH=\$PHP_HOME/bin:\$PHP_HOME/sbin:\$PATH" >> /etc/profile
    source /etc/profile
  10. 卸载旧版本
    rpm -e --nodeps `rpm -qa | grep -i php`
  11. 查看新版本
    php -v
  12. 常用命令
    添加用户:useradd www-data
    
    启动PHP:php-fpm
    
    查看PHP:ps -ef|grep php
    
    注意:PHP启动时会用到用户www-data

你可能感兴趣的:(php,linux)