nginx1.11とPHP7.0-FPMを連携して動かす。
CentOS7にyumでPHP7, PHP-FPM, OPcache, APCuをインストール
とりあえずPHPを動かす
nginx1.11のデフォルトの設定では、「/usr/share/nginx/html」が公開ディレクトリ。
ここにphpファイルを置いて、アクセスできるようにする。
sudo vim /usr/share/nginx/html/index.php
<?php echo phpinfo();
nginxの設定を修正。
sudo vim /etc/nginx/conf.d/default.conf
下記箇所のコメントアウトを全て削除。
rootディレクトリとfastcgi_paramを修正する。
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 $document_root/$fastcgi_script_name; include fastcgi_params; }
php-fpm側の修正。
sudo vim /etc/php-fpm.d/www.conf
こっちはuserとgroupをapacheからnginxへ修正するだけでいい。
;user = apache user = nginx ;group = apache group = nginx
再起動する。
sudo systemctl restart nginx
sudo systemctl restart php-fpm
IPアドレス直指定して、作成したPHPファイルにアクセスできれば連携はできるようになっている。
http://xxx.xxx.xxx.xxx/index.php
astCGI sent in stderr: “Primary script unknown” while reading response header from upstream
下記のように、rootをコメントアウトしただけだとエラーが出るぞ。
location ~ \.php$ {
#root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
#fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
include fastcgi_params;
}