バージョン情報
- CentOS 7.0.1406
- PHP 5.4.16
- Nginx 1.6.2
PHP
インストール
# yum -y install php php-fpm
php-fpmの設定
/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
userとgroupをnginxに変更しておく。初期値はapache。
php-fpmデーモン起動,自動起動
# systemctl start php-fpm # systemctl enable php-fpm
Nginx
インストール
標準リポジトリにはNginxは存在しない。公式でCentOS用のリポジトリが用意されてるので公式のドキュメントに従いリポジトリの追加を行う。
リポジトリ追加後
# yum -y install nginx
設定
/etc/nginx/conf.d/default.confを元に設定ファイルを作る
# cd /etc/nginx/conf.d/ # cp default.conf hoge.conf
/etc/nginx/conf.d/hoge.conf
server {
listen 80;
server_name hogehogehoge;
root /var/www/html;
index index.php index.html index.htm;
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}とりあえず必要な部分だけ残した。PHPの設定はコメントアウトしてfastcgi_paramを少し修正してあげる必要がある。
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
default.confではこのように書いてあるけどscriptsはディレクトリを指しているがドキュメントルート配下のphpを動かしたいので$document_rootに変更した。
起動,自動起動
# systemctl start nginx # systemctl enable nginx
phpinfo()
/etc/www/html/index.phpを作ってあげて該当server_nameにアクセスすると表示されるはず。
<?php phpinfo(); ?>