我正在尝试执行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信息。我做错什么了吗?你能给我一些建议吗?
发布于 2016-07-25 01:32:09
可能是您的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的内容,并确保它归正确的用户所有,并且该用户有权访问该目录。https://stackoverflow.com/questions/38553174
复制相似问题