Mac 系统php多版本共存
2021/10/30 14:10:42
本文主要是介绍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
这篇关于Mac 系统php多版本共存的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-03-29env: php: no such file or directory
- 2024-03-01php foreach break
- 2024-02-26Exception参数 php-icode9专业技术文章分享
- 2023-12-30PHP文件批量上传-icode9专业技术文章分享
- 2023-12-30thinkphp6 withJoin-icode9专业技术文章分享
- 2023-12-27MagicArray:像php一样,让Go业务代码不再卷!
- 2023-11-18centos7编译安装PHP教程。
- 2023-11-18centos7编译安装phpMyAdmin教程。
- 2023-10-13唱衰这么多年,PHP 仍然还是你大爷!
- 2023-07-25PHP8,性能更好,语法更好,类型安全更完善