Mac 系统php多版本共存
作者:互联网
搜索
brew search php
安装
brew install php@5.6
brew install php@7.4
创建目录
cd ~/
mkdir php_program
cd php_program
mkdir bin
创建软连接
ln -s /opt/homebrew/opt/php@5.6/bin/php ./php56
ln -s /opt/homebrew/opt/php@7.4/bin/php ./php74
将该目录添加到环境变量
echo 'export PATH="/Users/jiqing/php_program/bin:$PATH"' >> ~/.zshrc
source ~/.zshrc
这个时候,就可以使用别称了
php56 -v
php74 -v
修改配置
7.4
vim /opt/homebrew/etc/php/7.4/php-fpm.d/www.conf
listen = 127.0.0.1:9000
↓
listen = 127.0.0.1:9074
5.6
vim /opt/homebrew/etc/php/5.6/php-fpm.conf
listen = 127.0.0.1:9000
↓
listen = 127.0.0.1:9056
修改nginx
enable-php.conf
cp /opt/homebrew/etc/nginx/enable-php.conf enable-php56.conf
cp /opt/homebrew/etc/nginx/enable-php.conf enable-php74.conf
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9056;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9074;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
enable-php-pathinfo.conf
cp enable-php-pathinfo.conf enable-php56-pathinfo.conf
cp enable-php-pathinfo.conf enable-php74-pathinfo.conf
location ~ .php($|/) {
include fastcgi_params;
set $script $uri;
set $path_info "";
if ($uri ~ "^(.+.php)(/.+)") {
set $script $1;
set $path_info $2;
}
fastcgi_pass 127.0.0.1:9056;
fastcgi_index none;
fastcgi_param SCRIPT_FILENAME $document_root$script;
fastcgi_param SCRIPT_NAME $script;
fastcgi_param PATH_INFO $path_info;
}
location ~ .php($|/) {
include fastcgi_params;
set $script $uri;
set $path_info "";
if ($uri ~ "^(.+.php)(/.+)") {
set $script $1;
set $path_info $2;
}
fastcgi_pass 127.0.0.1:9074;
fastcgi_index none;
fastcgi_param SCRIPT_FILENAME $document_root$script;
fastcgi_param SCRIPT_NAME $script;
fastcgi_param PATH_INFO $path_info;
}
具体使用
test56.conf
server
{
listen 80;
#listen [::]:80 default_server ipv6only=on;
server_name local.test56.com;
index index.html index.htm index.php admin.php;
root /opt/homebrew/var/www/test56;
#error_page 404 /404.html;
# php
#include enable-php.conf;
include enable-php56-pathinfo.conf;
location /nginx_status
{
stub_status on;
access_log off;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}
location ~ .*\.(js|css)?$
{
expires 12h;
}
location ~ /\.
{
deny all;
}
location / {
if (!-e $request_filename) {
rewrite ^(.*)$ /index.php?s=/$1 last;
}
}
access_log /opt/homebrew/var/log/nginx/access.log;
}
test74.conf
server
{
listen 80;
#listen [::]:80 default_server ipv6only=on;
server_name local.test74.com;
index index.html index.htm index.php admin.php;
root /opt/homebrew/var/www/test74;
#error_page 404 /404.html;
# php
#include enable-php.conf;
include enable-php74-pathinfo.conf;
location /nginx_status
{
stub_status on;
access_log off;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}
location ~ .*\.(js|css)?$
{
expires 12h;
}
location ~ /\.
{
deny all;
}
location / {
if (!-e $request_filename) {
rewrite ^(.*)$ /index.php?s=/$1 last;
}
}
access_log /opt/homebrew/var/log/nginx/access.log;
}
添加hosts
sudo vim /etc/hosts
127.0.0.1 local.test56.com
127.0.0.1 local.test74.com
重启nginx
sudo nginx -s reload
重启php
brew services restart php@5.6
brew services restart php@7.4
标签:index,enable,共存,Mac,location,conf,php,fastcgi 来源: https://www.cnblogs.com/jiqing9006/p/15484833.html