環境:
系統:Ubuntu16.0.4.1
核心:Linux os 4.7.10-040710-generic #201610220847 SMP Sat Oct 22 12:50:14 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux (想更新核心可以看前篇文章)
apt方式安裝
首先安裝:nginx
apt install nginx
啟動sudo /etc/init.d/nginx start
網頁輸入127.0.0.1測試
安裝資料庫
sudo apt-get install mysql-server
會彈出一個輸入mysql管理者密碼,輸入即可.
#sudo vim /etc/php/7.0/fpm/php.ini (最好先備份php.ini)
将cgi.fix_pathinfo=1 這行去注釋,1改成0
#sudo vim /etc/php/7.0/fpm/pool.d/www.conf
修改
listen=/var/run/php7.0-fpm.sock 或者 listen = 127.0.0.1 (若此方式,則下面的default配置檔案需要改成一樣)
#sudo vim /etc/nginx/sites-available/default (最好先備份default)
修改了以下配置,紅色部分
root /var/www/html;
# Add index.php to the list if you are using PHP
index index.php index.html index.htm index.nginx-debian.html;
#server_name _;
server_name loclhost;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
# include snippets/fastcgi-php.conf;
# # With php7.0-cgi alone:
# # With php7.0-fpm:
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
然後重新開機服務
/etc/init.d/nginx restart
/etc/init.d/php7.0-fpm restart
檢視服務是否配置成功
sudo vim /var/www/html/index.php
<?php
phpinfo();
?>
然後127.0.0.1/index.php
若有錯誤請檢視日志檔案
cd /var/log/
本文轉自 一招拜師 51CTO部落格,原文連結:http://blog.51cto.com/sadoc/1894622