Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
9
Help us understand the problem. What is going on with this article?
@tukiyo3

nginx + php-fpmでphpを動かす

More than 5 years have passed since last update.
  • 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
9
Help us understand the problem. What is going on with this article?
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
tukiyo3

Comments

No comments
Sign up for free and join this conversation.
Sign Up
If you already have a Qiita account Login
9
Help us understand the problem. What is going on with this article?