PHP环境配置

一、更新

  • 2017-08-21:mac 配置php 7.1 作为系统默认php,配置nginx 多php版本支持

这里主要是说明自己机器php环境配置相关问题,涵盖了windows、unix和mac多平台。

二、内容

2.1 2017-08-21更新: mac php 7.1 配置

安装php71

通过系统默认命令brew install php71后php提醒libpng库问题,在执行php --version时报错内容大致如下:

1
2
3
dyld: Library not loaded: /usr/local/opt/libpng/lib/libpng16.16.dylib
Referenced from: /usr/local/bin/php
Reason: Incompatible library version: php requires version 45.0.0 or later, but libpng16.16.dylib provides version 38.0.0

解决方法: 执行命令brew reinstall -s php71可以解决
参考:https://github.com/Homebrew/homebrew-php/issues/3961

配置多端口访问

配置端口及对应的php服务如下

  • php(默认): nginx端口80,php-fpm端口9007
  • php54: nginx端口8054,php-fpm端口9004
  • php56: nginx端口8065,php-fpm端口9000
  • php71: nginx端口8071,php-fpm端口9007

也就是说后面一旦访问域名:端口即可使用对应php版本的服务。下面附上部分nginx fastcgi配置:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# # use php5.6 for php
# location ~ \.php$ {
# try_files $uri = 404;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_intercept_errors on;
# include /usr/local/etc/nginx/fastcgi.conf;
# }
# use php7 for php
location ~ \.php$ {
try_files $uri = 404;
fastcgi_pass 127.0.0.1:9007;
# fastcgi_pass unix:/tmp/php-fpm.sock;
fastcgi_index index.php;
fastcgi_intercept_errors on;
include /usr/local/etc/nginx/fastcgi.conf;
}

修改配置后需要执行以下命令重新加载相关服务:

1
2
3
4
brew services restart homebrew/php/php54
brew services restart homebrew/php/php56
brew services restart homebrew/php/php71
brew services restart nginx