本文共 2675 字,大约阅读时间需要 8 分钟。
在实际项目中,有时因为老项目的原因而不得不在同一台服务器配置多个 php 环境,本文为配置多 PHP 环境教程
假设:已有 php7 的环境,需要配置一个 PHP5 的环境
sudo wget http://au1.php.net/get/php-5.6.27.tar.gz/from/this/mirror -O php-5.6.27sudo tar -zxvf php-5.6.27 && cd php-5.6.27
sudo ./configure --prefix=/usr/local/php5 \--with-config-file-path=/usr/local/php5/etc \--with-iconv-dir=/usr/local/lib \--enable-fpm \--enable-pcntl \--enable-mysqlnd \--with-pdo-mysql=mysqlnd \--with-zlib \--enable-zip \--with-gd \--with-curl=/usr/bin/curl \--with-mysqli \--with-pdo-mysql
sudo make && sudo make install
sudo cp /usr/local/src/php-5.6.27/php.ini-development /usr/local/php5/etc/php.inisudo cp /usr/local/php5/etc/php-fpm.conf.default /usr/local/php5/etc/php-fpm.conf
# 修改 php.ini
sudo vim /usr/local/php5/etc/php.inicgi.fix_pathinfo=0;
# 修改 php-fpm.conf
user=wwwgroup=wwwlisten.owner = wwwlisten.group = wwwlisten.mode = 0660listen=/var/php/php5-cgi.sock
# 创建 sock 文件
sudo touch /var/php/php5-cgi.sock
# 链接 php 指令
sudo ln -s /usr/local/php5/bin/php /usr/bin/php5
sudo cp /usr/local/src/php-5.6.27/sapi/fpm/init.d.php-fpm /etc/init.d/php5-fpmsudo chmod +x /etc/init.d/php5-fpmsudo systemctl unmask php5-fpm.service # 使 php5-fpm 服务生效sudo sysv-rc-conf php5-fpm on # 设置开机启动
服务管理
service php5-fpm statusservice php5-fpm startservice php5-fpm stopservice php5-fpm restartservice php5-fpm reloadservice php5-fpm helpservice php5-fpm configtest
7.配置 nginx server
sudo touch /var/php/php5-fpm.socksudo vim /usr/local/nginx/conf/vhosts/shop.mt.conf
server { listen 80; server_name shop.mitao.me; #server_name 10.1.16.162; charset utf-8; index index.php index.html index.htm; #access_log logs/host.access.log main; root /mnt/d/xmt-shop; if (!-e $request_filename) { rewrite ^(.*)$ /index.php?s=/$1 last; break; } #error_page 404 /404.html; error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } location ~ \.php$ { #fastcgi_pass 127.0.0.1:9000; fastcgi_pass unix:/var/php/php5-cgi.sock; fastcgi_index index.php; include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param SCRIPT_NAME $fastcgi_script_name; }}
8.分别启动 php5 和 php7
sudo service php-fpm startsudo service php5-fpm startps -ef|grep php-fpm
总结:其实多 PHP 环境配置的关键点就是,通过配置 nginx http server 项,
location ~ .php$ { fastcgi_pass unix:/var/php/php-cgi.sock # fastcgi_pass unix:/var/php/php5-cgi.sock}即通过监听不同的 监听socket套接字 来区分,同时也需要在 php-fpm.conf 配置对应 连接socket 套接字
转载于:https://blog.51cto.com/12750968/2322967