![](/img/trans.png)
[英]PHP not working inside page on Amazon EC2 server with nginx and php-fpm
[英]How to consistently setup PHP-FPM 5.6 with nginx on Amazon EC2 AMI instance
我找不到從頭開始在Amazon AMI EC2實例上的Nginx上設置php-fpm的方法。 我知道這不應該那么困難,但是基於* nix版本找到不同的答案是令人困惑的。
這是我認為可以的精簡步驟,但無效。 有沒有人有一套步驟來在Amazon AMI EC2實例中使用nginx可靠地設置php-fpm?
我故意從這篇文章中省略了nginx.conf等,因為它們是默認yum存儲庫中的“ stock”安裝。
Nginx版本:1.6.2
有沒有人有可靠的步驟在Nginx中為Amazon AMI EC2實例設置php-fpm? 我希望自己進行設置,而不是在為此設置付費的亞馬遜市場中使用AMI。
謝謝
# install packages
yum install -y nginx
yum install -y php56-fpm.x86_64
# enable php in nginx.conf
vi /etc/nginx/nginx.conf
# add index.php at the beginning of index
index index.php index.html index.htm;
# uncomment the php block in nginx.conf
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
include fastcgi_params;
}
# tell php-fpm to run as same account as nginx
vi /etc/php-fpm-5.6.d/www.conf
- change user and group apache to nginx
# allow nginx user to read website files since they are typically owned by root
cd /usr/share/nginx
chown -R nginx:nginx html
# check to see if php works - doesn't with these steps
echo "<?php phpinfo(); ?>" > /usr/share/nginx/info.php
# restart services since we changed things
service nginx restart
service php-fpm-5.6 restart
# verify root path exists and is owned by nginx as we said above
# ls -l /usr/share/nginx/html
-rw-r--r-- 1 nginx nginx 3696 Mar 6 03:53 404.html
-rw-r--r-- 1 nginx nginx 3738 Mar 6 03:53 50x.html
-rw-r--r-- 1 nginx nginx 3770 Mar 6 03:53 index.html
-rw-r--r-- 1 nginx nginx 20 Apr 14 14:01 index.php
# I also verified php-fpm is listening on port 9000 and nginx is setup that way in the nginx.conf
# port 9000 usage is the default and I left it as-is for this question, but I would prefer to use sock once I get this working.
編輯
這就是我在Nginx錯誤日志中看到的
2015/04/14 17:08:25 [error] 916#0: *9 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream,
client: 12.34.56.78, server: localhost, request: "GET /index.php HTTP/1.1",
upstream: "fastcgi://127.0.0.1:9000", host: "12.34.56.90"
您在nginx錯誤日志(/var/log/nginx/errors.log)中看到了什么?
在提供其他信息(日志)之后添加:
在我看來,根應該是服務器部分而不是位置。
server {
...
root /usr/share/nginx/html;
...
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
include fastcgi_params;
}
}
您的index.php文件在哪里? 如果在這里:
/usr/share/nginx/html/index.php
然后改變這行
fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
至:
fastcgi_param SCRIPT_FILENAME /usr/share/nginx/html$fastcgi_script_name;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.