linux服务器存在php7.0的环境下,安装php7.3 多版本共存

问题描述
公司开发服务器linux , 存在多个项目,而不同项目对php的版本要求不一样。故需要在开发机上安装多套php版本。
下面以在php7.0基础上 安装php7.3 为例.[其他版本原理一样]

  1. 查看原php7.0编译参数
$ php -i | grep configure  查看php编译参数命令得到如下编译参数
./configure  --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-config-file-scan-dir=/usr/local/php/etc/php.d --with-fpm-user=www --with-fpm-group=www --enable-fpm --disable-opcache --disable-fileinfo --enable-mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-iconv-dir=/usr/local --with-freetype-dir=/usr/local/freetype --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-exif --enable-sysvsem --enable-inline-optimization --with-curl=/usr/local/curl --enable-mbregex --enable-mbstring --with-password-argon2 --with-sodium=/usr/local --with-gd --with-openssl=/usr/local/openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-ftp --enable-intl --with-xsl --with-gettext --enable-zip --without-libzip --enable-soap --disable-debug
# 从编译结果看出 php 安装目录,php配置文件目录  并且安装了php-fpm 使用nginx服务器
  1. 根据php7.0 编译参数,安装php7.3
    打开 linux php版本下载地址 下载php7.3到服务器
$ wget https://www.php.net/distributions/php-7.3.13.tar.gz
$ tar -zxvf php-7.3.13.tar.gz
$ cd php-7.3.13
#  需要区分 编译目录和配置文件目录不能与原来的php70版本重叠
$ ./configure  --prefix=/usr/local/php73 --with-config-file-path=/usr/local/php73/etc --with-config-file-scan-dir=/usr/local/php73/etc/php.d --with-fpm-user=www --with-fpm-group=www --enable-fpm --disable-opcache --disable-fileinfo --enable-mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-iconv-dir=/usr/local --with-freetype-dir=/usr/local/freetype --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-exif --enable-sysvsem --enable-inline-optimization --with-curl=/usr/local/curl --enable-mbregex --enable-mbstring --with-password-argon2 --with-sodium=/usr/local --with-gd --with-openssl=/usr/local/openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-ftp --enable-intl --with-xsl --with-gettext --enable-zip --without-libzip --enable-soap --disable-debug
# 根据提示进行安装 , 安装过程根据编译参数情况而定,可能需要很久
$ make ZEND_EXTRA_LIBS='-liconv'
$ make install

配置 新安装的版本

# 加入系统变量
$ ln -s /usr/local/php73/bin/php /usr/bin/php73
$ php73 -v # 查看版本
将原来php7.0的版本的 php.ini 和 php-fpn.conf 复制到 php7.3的配置目录 /usr/local/php73/etc 中
根据实际情况 修改新版本的php.ini 和 php-fpm.conf 配置文件
由于原 php.70 的fpm使用 9000 端口。故我在新php73中使用 9003端口
重点查看php.ini中的扩展配置情况
$ cd /usr/local/php73/sbin
$ ./php-fpm 启动fpm ,查看是否成功

配置项目的nginx配置文件,引入不同的fpm端口,而实现使用不同php版本。

php --ri  xxxx # 查看 php的 xxxx扩展信息
php -i | grep configure # 查看安装php的编译参数
php -i | grep extension_dir # 查看php扩展安装目录

yum -y install gcc openssl openssl-devel curl curl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel pcre pcre-devel libxslt libxslt-devel bzip2 bzip2-devel

你可能感兴趣的:(linux服务器存在php7.0的环境下,安装php7.3 多版本共存)