LoginSignup
215
221

More than 5 years have passed since last update.

CentOSにてnginxでPHPを動かす

Last updated at Posted at 2014-01-31

http://www.example.com/にアクセスして、ドキュメントルートにあるindex.phpを実行できるようにするまでの手順。

ドキュメントルートは、/var/wwwとする。

index.phpは例のやつ。

/var/www/index.php
<?php
    phpinfo();
?>

1. php-fpmをインストール

なんかremiリポジトリがどうとか色々あったけど、

# yum list | grep php-fpm
php-fpm.x86_64     5.3.3-27.el6_5     updates

あれ?あるぞ?ということで、そのままyumでインストールできた。

# yum -y install php-fpm

2. php-fpmの設定を変更

apacheってなってるところをnginxに変更。

/etc/php-fpm.d/www.conf

- user = apache
+ user = nginx

- group = apache
+ group = nginx

3. nginxの設定を変更

ドキュメントルートの設定と、PHPを実行できるように修正。

/etc/nginx/conf.d/default.conf
  location / {
-     root   /usr/share/nginx/html;
+     root   /var/www;
-     index  index.html index.htm;
+     index  index.php;
  }

- #location ~ \.php$ {
- #    root           html;
- #    fastcgi_pass   127.0.0.1:9000;
- #    fastcgi_index  index.php;
- #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
- #    include        fastcgi_params;
- #}
+ location ~ \.php$ {
+     root           /var/www;
+     fastcgi_pass   127.0.0.1:9000;
+     fastcgi_index  index.php;
+     fastcgi_param  SCRIPT_FILENAME  /var/www$fastcgi_script_name;
+     include        fastcgi_params;
+ }

4. php-fpmの起動

php-fpmの起動。ついでに自動起動の設定をしておく。

# /etc/init.d/php-fpm start
# chkconfig php-fpm on

5. nginxの再起動

default.confを変更したので再起動。

# /etc/init.d/nginx restart

6. index.phpの実行

ブラウザからhttp://www.example.comにアクセス。

phpinfo()の結果が表示されればOK。


Blog URL : http://www.utano.jp/ (Syntax Error.)

215
221
3

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
215
221