Linux下安裝PHP環境並配置Nginx支持php-fpm模塊

修改php配置

vi /etc/php.ini
打開php配置文件/etc/php.ini找到cgi.fix_pathinfo配置項,這一項默認被註釋而且值爲1,根據官方文檔的說明,這裏爲了當文件不存在時,阻止Nginx將請求發送到後端的PHP-FPM模塊,從而避免惡意腳本注入的攻擊,因此此項應該去掉註釋並設置爲0
重啓php

kill php進程ID

/usr/sbin/php-fpm

修改nginx配置

vi `/etc/nginx/conf.d/default.conf`

修改文件爲:

server {
        listen       80 default_server;
        listen       [::]:80 default_server;
        server_name  _;
        root         /usr/share/nginx/html;

        include /etc/nginx/default.d/*.conf;

        location / {
            root   /usr/share/nginx/html;
            index  index.html index.htm;
        }

        location ~ .*\.php$ {
           root           html;
           fastcgi_pass   127.0.0.1:9000;
           fastcgi_index  index.php;
           fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
           include        fastcgi_params;
        }

        error_page 404 /404.html;
                location = /40x.html {
        }

        error_page 500 502 503 504 /50x.html;
                location = /50x.html {
        }
}
重啓nginx
kill nginx進程ID

/usr/sbin/nginx

測試php能不能用

cd /usr/share/nginx/html

touch a.php
寫如下內容
<?php
echo 12345;
相關文章
相關標籤/搜索