我正在尝试使用php56和Nginx执行php文件,这些文件是由brew安装的。
brew install nginx
brew install php56
所以,/usr/local/etc/nginx/nginx.conf
在这里。
worker_processes 1;
error_log /usr/local/var/log/nginx/error.log;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
server_name localhost;
listen 8080;
root /Users/kent/work;
location ~ .php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+.php)(/.+)$;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
include servers/*;
}
我用一个html文件index.html
创建了一个目录/Users/kent/work/html
。
<h1>this is my first file!</h1>
它在http://localhost:8080/html/index.html
中工作。
我用一个php文件index.php
创建了一个目录/Users/kent/work/php
。
<?php phpinfo();
未在http://localhost:8080/php/index.php
中浏览。奇怪的是,它使得下载index.php文件。
我应该在浏览器中浏览php信息。我做错什么了吗?你能给点建议吗?
可能是您的php brew安装中没有包含fpm支持
$ brew install php56 --with-fpm --without-apache
验证您是否安装了php和php-fpm
$ php -v
$ php-fpm -v
替代
虽然与您最初的问题无关,但OSX附带了apache。这可能是另一种选择。
此外,如果你正在使用Laravel(或者开箱即用支持许多其他框架),你也可以看看Valet,这是一个使用Caddy服务器的不错的开发替代方案。
更新:附加信息
检查php-fpm是否已经实际启动并在端口9000上侦听。根据我的评论,你可以使用进行检查
$ lsof -Pni4 | grep LISTEN | grep php
你应该看到类似的东西
php-fpm 50622 YourUsername 6u IPv4 0xe686e4bdbc1e41b3 0t0 TCP 127.0.0.1:9000 (LISTEN)
php-fpm 50636 YourUsername 0u IPv4 0xe686e4bdbc1e41b3 0t0 TCP 127.0.0.1:9000 (LISTEN)
您可以使用手动启动服务
$ brew services start homebrew/php/php56
您还需要在启动时使用注册启动器
$ mkdir -p ~/Library/LaunchAgents
$ cp /usr/local/opt/php56/homebrew.mxcl.php56.plist ~/Library/LaunchAgents/
$ launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.php56.plist
如果您没有看到来自lsof
的php-fpm条目,请检查以下线索
- 包含字符串
homebrew.mxcl.php56
的事物的/var/log/syslog.log
的内容 - 检查
/usr/local/var/log/php-fpm.log
,并确保它由正确的用户所有,并且该用户可以访问该目录