ubuntu下nginx+PHP-FPM安裝配置
阿新 • • 發佈:2018-12-27
-
安裝nginx
apt-get install nginx
-
配置nginx
位置: /etc/nginx/nginx.conf ,其中包含了
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
在這兩個配置中的檔案也是生效的。
錯誤日誌 error_log /var/log/nginx/error.log; ,這個非常實用,在後面的配置完成重啟後,可以通過此日誌來快速排錯。
這裡,我們把配置檔案放在 /etc/nginx/sites-enabled/default; 中。
index index.php index.html index.htm;
...
location ~\.php$ { try_files $uri = 404; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; include fastcgi_params; }
儲存檔案,使配置檔案生效
/etc/init.d/nginx reload
nginx相關命令
service nginx start service nginx stop service nginx restart
在 /usr/share/nginx/html 下新建index.php
<?php phpinfo();
-
安裝PHP
sudo apt-get install php5-fpm sudo apt-get install php5-gd # Popular image manipulation library; used extensively by Wordpress and it's plugins. sudo apt-get install php5-cli # Makes the php5 command available to the terminal for php5 scriptingsudo apt-get install php5-curl # Allows curl (file downloading tool) to be called from PHP5 sudo apt-get install php5-mcrypt # Provides encryption algorithms to PHP scripts sudo apt-get install php5-mysql # Allows PHP5 scripts to talk to a MySQL Database sudo apt-get install php5-readline # Allows PHP5 scripts to use the readline function
-
配置php監聽埠
位置: /etc/php5/fpm/pool.d/www.conf
把 listen = /var/run/php5-fpm.sock 改為:
listen = 127.0.0.1:9000
檢視php執行程序
ps -waux | grep php5
php啟動相關命令
service php5-fpm stop service php5-fpm start service php5-fpm restart service php5-fpm status
重啟php程序,訪問檢視效果
curl http://localhost
若是不生效,可通過檢視/var/log/nginx/error.log 日誌來定位
參考文件:https://www.cnblogs.com/Bonker/p/4252588.html