本記事のソースコードの利用によって生じた損害について、当方は一切の責任を負いません。ご自身の判断と責任のもとで参照・ご利用ください。
この記事は最終更新から13年以上経過しています。
nginxでcgiが動くようになったので、今度はphpが動くようにするための設定を行いました。
php-fpm.confファイルを設定する
# vi /etc/php-fpm.conf ;;;;;;;;;;;;;;;;;;;;; ; FPM Configuration ; ;;;;;;;;;;;;;;;;;;;;; ; All relative paths in this configuration file are relative to PHP's install ; prefix. ; Include one or more files. If glob(3) exists, it is used to include a bunch of ; files from a glob(3) pattern. This directive can be used everywhere in the ; file. include=/etc/php-fpm.d/*.conf
コード内に下記のような記述があったので/etc/php-fpm.dディレクトリを確認。
ls /etc/php-fpm.d/
www.confという設定ファイルがあるようなのでこのファイルをインクルードするように書き換えます。
vi /etc/php-fpm.conf ;;;;;;;;;;;;;;;;;;;;; ; FPM Configuration ; ;;;;;;;;;;;;;;;;;;;;; ; All relative paths in this configuration file are relative to PHP's install ; prefix. ; Include one or more files. If glob(3) exists, it is used to include a bunch of ; files from a glob(3) pattern. This directive can be used everywhere in the ; file. include=/etc/php-fpm.d/www.conf
ユーザーとかグループがapacheになっているので
vi /etc/php-fpm.d/www.conf ; RPM: apache Choosed to be able to access some dir as httpd user = apache ; RPM: Keep a group allowed to write in log dir. group = apache
www.confを開いてユーザーとグループ名をnginxに変更する。
vi /etc/php-fpm.d/www.conf ; RPM: apache Choosed to be able to access some dir as httpd user = nginx ; RPM: Keep a group allowed to write in log dir. group = nginx
php-fpmを起動する。
/etc/init.d/php-fpm start
PHPが動作するようにdefault.confを修正。参照元のエントリーを失念してしまいました。参照元としてリンクを掲載するのですが...。管理者の方に申し訳ないです...。
# vi /etc/nginx/conf.d/default.conf
server {
listen
80;
server_name
localhost;
charset utf-8;
#charset koi8-r;
#access_log
/var/log/nginx/log/host.access.log
main;
location / {
#root
/usr/share/nginx/html;
root
/var/www/html;
index
index.html index.htm index.php;
}
#error_page
404
/404.html;
# redirect server error pages to the static page /50x.html
#
error_page
500 502 503 504
/50x.html;
location = /50x.html {
root
/usr/share/nginx/html;
}
include /etc/nginx/fcgi-perl.conf;
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
#
proxy_pass
http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
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;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
#
deny
all;
#}
}
nginx再起動
/etc/init.d/nginx restart
phpが動作するようになりました。nginxでは.htaccessというのはなくて、設定ファイルにじかに書かないといけないみたいなので、そのあたりを調べようと思います。 ここら辺りがわかれば完全にnginxに移行できそうですね。