PHP FPM的配置参数

前提 tí)

可以继续进行下面的步骤。

进行步骤

    1. 创建执行用户

# useradd php-fpm

$ sudo adduser –no-create-home php-fpm

创建要使用的目录

$ sudo mkdir /var/run/php-fpm /var/log/php-fpm
$ sudo chown php-fpm:php-fpm /var/run/php-fpm /var/log/php-fpm

复制必要的文件

# cp /usr/local/etc/php-fpm.conf.default /usr/local/etc/php-fpm.conf
# cp /usr/local/etc/php-fpm.d/www.conf.default /usr/local/etc/php-fpm.d/www.conf
# cp sapi/fpm/php-fpm /usr/local/bin/

编辑php.ini文件

# vi /usr/local/php/php.ini

php.ini
cgi.fix_pathinfo=0
expose_php = Off

编辑php-fpm.conf文件

# cp /usr/local/etc/php-fpm.conf /usr/local/etc/php-fpm.conf.org
# vi /usr/local/etc/php-fpm.conf

php-fpm.conf
(省略)
(更改路径设置)
pid = /var/run/php-fpm/php-fpm.pid
(更改路径设置)
error_log = /var/log/php-fpm/php-fpm.log
(更改路径设置)
include=/usr/local/etc/php-fpm.d/*.conf

放置php-fpm的服务文件

# cp ./sapi/fpm/php-fpm.service /usr/lib/systemd/system/
# vi /usr/lib/systemd/system/php-fpm.service

[Service]
Type=notify
User=php-fpm
PIDFile=/var/run/php-fpm/php-fpm.pid
ExecStart=/usr/local/sbin/php-fpm –nodaemonize –fpm-config /usr/local/etc/php-fpm.conf
ExecReload=/bin/kill -USR2 $MAINPID

重新加载服务文件

# systemctl daemon-reload

创建Nginx的配置文件

# cp /etc/nginx/conf.d/default.conf /etc/nginx/conf.d/default.conf.`date +%F`
# mv /etc/nginx/conf.d/default.conf /etc/nginx/conf.d/wordpress.conf
# vi /etc/nginx/conf.d/wordpress.conf

wordpress.conf
server_name localhost;
root /usr/share/nginx/html;
(中略)

location / {
index index.php index.html index.htm;
}

(中略)

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

确认配置文件是否正确

# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

启动php-fpm和Nginx

# systemctl start php-fpm
# systemctl start nginx

确定

# rm /usr/share/nginx/html/index.html
# echo "<?php phpinfo(); ?>" >> /usr/share/nginx/html/index.php
# systemctl restart nginx

如果从浏览器访问服务器后显示以下屏幕,那就可以了。

PHP情報画面(テスト用).png

请参阅

    • FastCGI Process Manager (FPM) | PHP 公式ドキュメント

 

    • インストール | PHP 公式ドキュメント

 

    設定 | PHP 公式ドキュメント
广告
将在 10 秒后关闭
bannerAds