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
vim /opt/homebrew/etc/php/7.4/php-fpm.d/www.conf
listen = 127.0.0.1:9000 ↓ listen = 127.0.0.1:9074
vim /opt/homebrew/etc/php/5.6/php-fpm.conf
listen = 127.0.0.1:9000 ↓ listen = 127.0.0.1:9056
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; }
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