ubuntu 14 nginx php,ubuntu14.04安装nginx+php5-fpm
安裝php5-fpm
# apt-get install php5-fpm
安裝完成以后修改/etc/php5/fpm/conf.d/www.conf:
;listen = /var/run/php5-fpm.sock
listen = 127.0.0.1:9000
重載php5-fpm配置
# /etc/init.d/php5-fpm reload
檢查一下是否監聽了9000端口:
# netstat -tln
如果出現了9000端口,說明php5-fpm正常啟動。
安裝nginx(參考Ubuntu 14.04安裝Nginx1.60)
安裝完成之后配置/etc/nginx/conf.d/default.conf:
要執行php關鍵要修改如下部分:
#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;
# ? ?}
去掉前面的#號,修改root為你自己目錄,修改/scripts$fastcgi_script_name為$document_root$fastcgi_script_name。修改之后如下:
location ~ \.php$ {
root ? ? ? ? ? /var/www;
fastcgi_pass ? 127.0.0.1:9000;
fastcgi_index ?index.php;
fastcgi_param ?SCRIPT_FILENAME ?$document_root$fastcgi_script_name;
include ? ? ? ?fastcgi_params;
}
注意:
root如果不指定會出現找不到文件的錯誤。
/scripts如果不修改會出現如下錯誤
[error] 5152#0: *7 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 127.0.0.1, server: localhost, request: "GET /index.php HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "localhost"
也可以不指定root直接把$document_root寫成真實地址。
如果不修改/etc/php5/fpm/conf.d/www.conf的話,也可以設置fastcgi_pass? 后的127.0.0.1:9000;為unix:/var/run/php5-fpm.sock;
然后重載nginx配置:
# /etc/init.d/nginx reload
在/var/www目錄中新建一個index.php文件,在瀏覽器地址欄輸入localhost,回車!
總結
以上是生活随笔為你收集整理的ubuntu 14 nginx php,ubuntu14.04安装nginx+php5-fpm的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 小米 Redmi Note 12 Tur
- 下一篇: php正则表达式程序,php正则表达式