10
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

nginx + php-fpmでphpを動かす

Last updated at Posted at 2016-04-20
  • ubuntu 16.04 にて実施

インストール

apt-get install -y \
    nginx php-fpm

php-fpm サービスの確認

systemctl status php7.0-fpm
  • running, enabled を確認。

socket

  • /etc/php/7.0/fpm/pool.d/www.conf にsocketの記述あり
$ ls -l /run/php/php7.0-fpm.sock
srw-rw---- 1 www-data www-data 0  4月 15 09:51 /run/php/php7.0-fpm.sock

nginxからphpを使えるようにする

/etc/nginx/sites-sites-enabled/default
-       index index.html index.htm index.nginx-debian.html;
+       index index.html index.htm index.nginx-debian.html index.php;
/etc/nginx/sites-sites-enabled/default
+       location ~ \.php$ {
+              include snippets/fastcgi-php.conf;
+       
        #       # With php7.0-cgi alone:
        #       fastcgi_pass 127.0.0.1:9000;
+              # With php7.0-fpm:
+              fastcgi_pass unix:/run/php/php7.0-fpm.sock;
+       }

debian9 + php7の場合は

/etc/nginx/sites-sites-enabled/default
-	#	fastcgi_pass unix:/var/run/php5-fpm.sock;
+       fastcgi_pass unix:/run/php/php7.0-fpm.sock;

動作確認

  • document_root : /var/www/html/
/var/www/html/a.php
<?php
echo "hoge";

hge.png

  • ログは /var/log/php7.0-fpm.log に出力される(?)

404 Not Found時にnginxのバージョンを非表示にする

/etc/nginx/nginx.conf
-	# server_tokens off;
+	server_tokens off;

uploadの上限を変更

初期値が1MB

/etc/nginx/sites-sites-enabled/default
 http {
     server {
+        client_max_body_size 1000m;
     }
 }
/etc/php/7.0/fpm/php.ini
+ memory_limit = 1000M
+ post_max_size = 0
+ upload_max_filesize = 0
10
9
0

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
10
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?