linux安装php多版本

1:概述

在开发过程中会遇到多个项目,有时候不喜欢安装集成环境phpstudy或者宝塔类的,可以自己手动安装多版本php环境,可以修改多端口监听执行多个不同版本项目,也可以软连接手动切换指定版本,接下来具体实际操作下,我的环境是LTS下的ubuntu22.04具体如下

2:安装php8.2.15

下载安装包

 
wget https://www.php.net/distributions/php-8.2.15.tar.gz

解压安装包 并且进入目录


tar -zxvf php-8.1.15.gz && cd php-8.1.15

安装php其他扩展


apt-get install build-essential autoconf automake libtool libsqlite3-dev pkg-config libjpeg-dev libpng-dev libxml2-dev libbz2-dev libcurl4-gnutls-dev libssl-dev libffi-dev libwebp-dev libonig-dev libzip-dev openssl

编译安装


./configure --prefix=/opt/local/php8 --with-config-file-path=/opt/local/php8/etc --with-curl --with-freetype --enable-gd --with-jpeg --with-gettext --with-kerberos --with-libdir=lib64 --with-libxml --with-mysqli --with-openssl --with-pdo-mysql --with-pdo-sqlite --with-pear --enable-sockets --with-mhash --with-ldap-sasl --with-xsl --with-zlib-with-zip -with-bz2 --with-iconv --with-pcre-jit --with-pdo-pgsql--enable-fpm --enable-pdo --enable-bcmath --enable-mbregex --enable-mbstring --enable-opcache --enable-pcntl --enable-shmop --enable-soap --enable-sockets --enable-sysvsem --enable-xml --enable-sysvsem --enable-cli --enable-intl --enable-calendar --enable-static --enable-mysqlnd


./configure --prefix=/opt/local/php8 # 安装地址
--with-config-file-path=/opt/local/php8/etc #配置文件地址
--with-curl #curl
--with-freetype
--enable-gd   #图像库
--with-jpeg  
--with-gettext
--with-kerberos
--with-libdir=lib64
--with-libxml #xml库
--with-mysqli
--with-openssl #openssl库
--with-pdo-mysql   #mysqlpdo库
--with-pdo-sqlite
--with-pear
--enable-sockets
--with-mhash
--with-ldap-sasl
--with-xsl
--with-zlib
--with-zip
-with-bz2
--with-iconv  
--with-pcre-jit #开启jit
--with-pdo-pgsql #开启pgsql
--enable-fpm
--enable-pdo  
--enable-bcmath  
--enable-mbregex
--enable-mbstring
--enable-opcache
--enable-pcntl  
--enable-shmop
--enable-soap
--enable-sockets
--enable-sysvsem
--enable-xml
--enable-sysvsem
--enable-cli
--enable-intl
--enable-calendar
--enable-static
--enable-mysqlnd

执行安装

make && make install

#安装完成文件路径
Installing shared extensions:     /opt/local/php8/lib/php/extensions/no-debug-non-zts-20220829/
Installing PHP CLI binary:       /opt/local/php8/bin/
Installing PHP CLI man page:     /opt/local/php8/php/man/man1/
Installing phpdbg binary:         /opt/local/php8/bin/
Installing phpdbg man page:       /opt/local/php8/php/man/man1/
Installing PHP CGI binary:       /opt/local/php8/bin/
Installing PHP CGI man page:     /opt/local/php8/php/man/man1/
Installing build environment:     /opt/local/php8/lib/php/build/
Installing header files:         /opt/local/php8/include/php/
Installing helper programs:       /opt/local/php8/bin/
program: phpize
program: php-config
Installing man pages:             /opt/local/php8/php/man/man1/


配置文件路径

配置路径
/etc/php/8.2/fpm

安装路径
/opt/local/php8/

启动文件
/etc/init.d/php8.2-fpm

执行php启动
/etc/init.d/php8.2-fpm start -c /etc/php/8.2/fpm/php.ini

按照以上步骤安装php5、php7

php7配置路径

配置路径
/etc/php/7.4/fpm
运行路径
/usr/bin/php7.4
启动文件
/etc/init.d/php7.4-fpm
启动
/etc/init.d/php7.4-fpm start -c /etc/php/7.4/fpm/php.ini

php5配置路径

配置路径
/etc/php/5.6/fpm
运行路径
/usr/bin/php5.6
启动文件
/etc/init.d/php5.6-fpm
启动
/etc/init.d/php5.6-fpm start -c /etc/php/5.6/fpm/php.ini

修改端口启动多服务

php8使用默认端口 9000
php7使用端口7000
php5使用端口5000

修改/etc/php/7.4/fpm/pool.d/www.conf 文件中的listen=127.0.0.1:7000

修改/etc/php/5.6/fpm/pool.d/www.conf 文件中的listen=127.0.0.1:5000


/etc/init.d/php8.2-fpm restart -c /usr/local/php8/etc/php.ini
/etc/init.d/php7.4-fpm start -c /usr/local/php7/etc/php.ini
/etc/init.d/php5.6-fpm start -c /usr/local/php5/etc/php.ini


取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论