Nginx啟用PHP功能
過去管理的web server都是apache httpd居多,也有用過lighttpd,基本上安裝完成之後add type之後PHP就可以使用
這次剛好有個需求要來安裝nginx,安裝完成後也需要幾個動作材能使用PHP唷!!
1. 修改nginx設定檔
$ sudo vi /etc/nginx/sites-available/default
內容如下 :
server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/html/laravel/public;
# Add index.php to the list if you are using PHP
index index.html index.htm index.nginx-debian.html;
server_name _;
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:
# fastcgi_pass 127.0.0.1:9000;
# With php7.0-fpm:
# fastcgi_pass unix:/run/php/php7.0-fpm.sock;
}
}
修改如下 :
server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/html/laravel/public;
# Add index.php to the list if you are using PHP
index index.php index.html index.htm index.nginx-debian.html;
server_name _;
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:
# fastcgi_pass 127.0.0.1:9000;
# With php7.0-fpm:
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
}
}
一個是增加index type : index.php,另一個就是透過fastcgi和php7.0-fpm去接收php function
最後重啟一下nginx就好了!!