Nginx PHP5 インストール
PHP5インストール&設定
[root@centos ~]# yum -y install php php-mbstring php-mysql php-pear php-fpm
[root@centos ~]# vi /etc/php-fpm.d/www.conf
user = apache
↓
user = nginx ←userをnginxに変更
group = apache
↓
group = nginx ←groupをnginxに変更
PHP-FPM起動
[root@centos ~]# systemctl start php-fpm
[root@centos ~]# systemctl enable php-fpm
[root@centos ~]# systemctl is-enabled php-fpm
enabled
Nginx設定
[root@centos ~]# vi /etc/nginx/conf.d/default.conf
location / {
root /usr/share/nginx/html;
index index.html index.htm index.php; ←index.phpを追加
}
// ここからコメント解除
location ~ \.php$ {
root html;
↓
root /usr/share/nginx/html; ←変更(ドキュメントルートを記入)
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
↓
fastcgi_param SCRIPT_FILENAME /usr/share/nginx/html$fastcgi_script_name; ←変更(/scriptsをドキュメントルートに変更)
include fastcgi_params;
}
// ここまでコメント解除
[root@centos ~]# systemctl reload nginx
PHP動作確認
[root@centos ~]# echo "<?php phpinfo(); ?>" > /usr/share/nginx/html/info.php
ブラウザで確認 (http://ドメイン名/info.php にアクセス)
このように表示されたらPHPはちゃんと動作しています。