安装多版本php(php5.6,php7.2)

2022-08-09 18:14:19 浏览数 (2)

大家好,又见面了,我是你们的朋友全栈君。

说明:之前项目使用laravel5.3 (php版本>=5.5.9)在不影响以前项目的情况下,新项目使用laravel5.7 (php版本>=7.1.3)

安装php7.1.3
(1)下载:

查看下载地址

[root@lnmp ~]# cd /usr/local/src [root@lnmp src]# wget -c http://cn2.php.net/distributions/php-7.2.8.tar.gz

(2)解压:

[root@lnmp src]# tar -zxvf php-7.2.8.tar.gz

(3)安装

安装依赖包

yum install 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

[root@lnmp src]# cd php-7.2.8 [root@lnmp php-7.2.8]#

./configure –prefix=/usr/local/php7 –with-config-file-path=/usr/local/php7/etc –enable-fpm –with-fpm-user=www –with-fpm-group=www –enable-mysqlnd –with-mysqli=mysqlnd –with-pdo-mysql=mysqlnd –enable-mysqlnd-compression-support –with-iconv-dir –with-freetype-dir –with-jpeg-dir –with-png-dir –with-zlib –with-libxml-dir –enable-xml –disable-rpath –enable-bcmath –enable-shmop –enable-sysvsem –enable-inline-optimization –with-curl –enable-mbregex –enable-mbstring –enable-intl –with-mcrypt –with-libmbfl –enable-ftp –with-gd –enable-gd-jis-conv –enable-gd-native-ttf –with-openssl –with-mhash –enable-pcntl –enable-sockets –with-xmlrpc –enable-zip –enable-soap –with-gettext –disable-fileinfo –enable-opcache –with-pear –enable-maintainer-zts –with-ldap=shared –without-gdbm

1,报错:configure: WARNING: unrecognized options: –with-mysql, –with-mcrypt, –with-curlwrappers, –enable-gd-native-ttf 解决:删除–with-mysql –enable-gd-native-ttf –with-mcrypt ,从新安装 安装目录为:–prefix=/usr/local/php7 (可自定义)

./configure –prefix=/usr/local/php7 –with-config-file-path=/usr/local/php7/etc –enable-fpm –with-fpm-user=www –with-fpm-group=www –enable-mysqlnd –with-mysqli=mysqlnd –with-pdo-mysql=mysqlnd –enable-mysqlnd-compression-support –with-iconv-dir –with-freetype-dir –with-jpeg-dir –with-png-dir –with-zlib –with-libxml-dir –enable-xml –disable-rpath –enable-bcmath –enable-shmop –enable-sysvsem –enable-inline-optimization –with-curl –enable-mbregex –enable-mbstring –enable-intl –with-libmbfl –enable-ftp –with-gd –enable-gd-jis-conv –with-openssl –with-mhash –enable-pcntl –enable-sockets –with-xmlrpc –enable-zip –enable-soap –with-gettext –disable-fileinfo –enable-opcache –with-pear –enable-maintainer-zts –with-ldap=shared –without-gdbm

2,报错:configure: error: Cannot find ldap.h

代码语言:javascript复制
[root@lnmp php-7.2.8]yum list | grep openldap

[root@lnmp php-7.2.8]yum install openldap-devel

3,报错:configure: error: Please reinstall readline – I cannot find readline.h

代码语言:javascript复制
yum install readline-devel
代码语言:javascript复制
[root@lnmp php-7.2.8]# make
[root@lnmp php-7.2.8]# echo $?
为0时表示没有问题
[root@lnmp php-7.2.8]# make install
[root@lnmp php-7.2.8]# echo $?

4,报错: collect2: error: ld returned 1 exit status make: *** [sapi/cli/php] Error 1

说明:./configure 」沒抓好一些环境变数值。错误发生点在建立「-o sapi/cli/php」是出错,没給到要 link 的 iconv 函式库参数

解决1: vim Makefile EXTRA_LIBS = … -lcrypt 在最后加上 -liconv

j解决2: make ZEND_EXTRA_LIBS=’-liconv’

ln -s /usr/local/lib/libiconv.so.2 /usr/lib64/

解决完报错执行:make clean && make && make install

5,安装完成后,查看php版本,如下显示安装成功

代码语言:javascript复制
[root@lnmp etc]# /usr/local/php7/bin/php -v
PHP 7.2.8 (cli) (built: Mar  9 2019 15:10:06) ( ZTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
(4)配置php.ini
代码语言:javascript复制
[root@lnmp php-7.2.8]# cp php.ini-development /usr/local/php7/lib/php.ini
[root@lnmp php-7.2.8]# vim /usr/local/php7/lib/php.ini

查找 mysqli.default_socket 改成:

mysqli.default_socket = /var/lib/mysql/mysql.sock

根据自己需要修改时区,查找 date.timezone,将前面的 ; 去掉,改成:

date.timezone = PRC

(5)配置php-fpm
代码语言:javascript复制
[root@lnmp php-7.2.8]# cp /usr/local/php7/etc/php-fpm.conf.default /usr/local/php7/etc/php-fpm.conf
[root@lnmp php-7.2.8]# cp /usr/local/php7/etc/php-fpm.d/www.conf.default /usr/local/php7/etc/php-fpm.d/www.conf
[root@lnmp php-7.2.8]# vim /usr/local/php7/etc/php-fpm.d/www.conf

查找 user 将

user = nobody group = nobody

改成

user = nginx group = nginx

查找 listen 将

listen = 127.0.0.1:9000

改成

listen = 127.0.0.1:9001

这里是因为 PHP 7 已经占用了 9000 端口,所以用 9001 端口,可以自定义哦!

(6)配置 php-fpm 服务

因为 PHP 7 的服务文件为 php-fpm.service 所以这里用 php5-fpm.service

代码语言:javascript复制
[root@lnmp php-7.2.8]# cp sapi/fpm/php-fpm.service /usr/lib/systemd/system/php7-fpm.service
[root@lnmp php-7.2.8]# vim /usr/lib/systemd/system/php7-fpm.service

将:

PIDFile=${prefix}/var/run/php-fpm.pid

ExecStart={exec_prefix}/sbin/php-fpm –nodaemonize –fpm-config {prefix}/etc/php-fpm.conf

改成

PIDFile=/usr/local/php7/var/run/php-fpm.pid ExecStart=/usr/local/php7/sbin/php-fpm –nodaemonize –fpm-config /usr/local/php7/etc/php-fpm.conf

(6)启动php-fpm服务

重新载入 systemd

代码语言:javascript复制
 [root@lnmp php-7.2.8]# systemctl daemon-reload

可以设置开机启动:

代码语言:javascript复制
[root@lnmp php-7.2.8]# systemctl enable php7-fpm
Created symlink from /etc/systemd/system/multi-user.target.wants/php7-fpm.service to /usr/lib/systemd/system/php7-fpm.service

立即启动 php-fpm

代码语言:javascript复制
[root@lnmp php-7.2.8]# systemctl start php7-fpm

查看运行状态:

代码语言:javascript复制
[root@lnmp php-7.2.8]# systemctl status php7-fpm
● php7-fpm.service - The PHP FastCGI Process Manager
   Loaded: loaded (/usr/lib/systemd/system/php7-fpm.service; enabled; vendor preset: disabled)
   Active: active (running) since Sat 2019-03-09 18:04:53 CST; 13s ago
 Main PID: 19796 (php-fpm)
   CGroup: /system.slice/php7-fpm.service
           ├─19796 php-fpm: master process (/usr/local/php7/etc/php-fpm.conf)
           ├─19797 php-fpm: pool www
           └─19798 php-fpm: pool www
代码语言:javascript复制
[root@lnmp php-7.2.8]# ps -ef|grep php 或者 ps aux|grep php
root     19796  0.0  0.2 256432 10476 ?        Ss   18:04   0:00 php-fpm: master process (/usr/local/php7/etc/php-fpm.conf)
root      2131  0.0  0.1 300624  6760 ?        Ss    2018   5:32 php-fpm: master process (/usr/local/php/etc/php-fpm.conf)
www       2132  0.0  0.6 406988 26580 ?        S     2018   0:48 php-fpm: pool www
www       2133  0.0  0.6 406672 26136 ?        S     2018   0:50 php-fpm: pool www
www       2134  0.0  0.6 405892 25804 ?        S     2018   0:50 php-fpm: pool www
(7)不同nginx 站点使用不用的 PHP 版本,配置如下
代码语言:javascript复制
[root@lnmp w3c]# cd /w3c/lnmp/
[root@lnmp lnmp]# vim index.php
<?php
echo phpinfo();
代码语言:javascript复制
server { 
   
    listen       80;
    server_name  www.lnmp.cn;
    root         /w3c/lnmp/index.php
    location / { 
   
        index  index.php index.html index.htm;
    }
    location ~ .php$ { 
   
        fastcgi_pass   127.0.0.1:9001;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }
}

php5 6项目配置:

代码语言:javascript复制
fastcgi_pass   127.0.0.1:9000;

php7项目配置

代码语言:javascript复制
fastcgi_pass   127.0.0.1:9001;

读取nginx配置:

代码语言:javascript复制
[root@lnmp vhost]# systemctl reload nginx || /etc/init.d/nginx reload

发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/105876.html原文链接:https://javaforall.cn

0 人点赞