5
5

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 1 year has passed since last update.

PHP FPM の設定

Last updated at Posted at 2021-12-26

前提

次の手順の続きで進める。

手順

  1. 実行用ユーザーを作成する

    # useradd php-fpm
    
    $ sudo adduser --no-create-home php-fpm
    
  2. 使用するディレクトリを作成する

    $ sudo mkdir /var/run/php-fpm /var/log/php-fpm
    $ sudo chown php-fpm:php-fpm /var/run/php-fpm /var/log/php-fpm
    
  3. 必要なファイルをコピーする

    # cp /usr/local/etc/php-fpm.conf.default /usr/local/etc/php-fpm.conf
    # cp /usr/local/etc/php-fpm.d/www.conf.default /usr/local/etc/php-fpm.d/www.conf
    # cp sapi/fpm/php-fpm /usr/local/bin/
    
  4. php.ini ファイルを編集する

    # vi /usr/local/php/php.ini
    
    php.ini
    cgi.fix_pathinfo=0
    
    expose_php = Off
    
  5. php-fpm.confファイルを編集する

    # cp /usr/local/etc/php-fpm.conf /usr/local/etc/php-fpm.conf.org
    # vi /usr/local/etc/php-fpm.conf
    
    php-fpm.conf
    (省略)
    
    (パスの設定を変更)
    pid = /var/run/php-fpm/php-fpm.pid
    
    (パスの設定を変更)
    error_log = /var/log/php-fpm/php-fpm.log
    
    (パスの設定を変更)
    include=/usr/local/etc/php-fpm.d/*.conf
    
  6. php-fpm のサービスファイルを配置する

    # cp ./sapi/fpm/php-fpm.service /usr/lib/systemd/system/
    # vi /usr/lib/systemd/system/php-fpm.service
    
    [Service]
    Type=notify
    User=php-fpm
    PIDFile=/var/run/php-fpm/php-fpm.pid
    ExecStart=/usr/local/sbin/php-fpm --nodaemonize --fpm-config /usr/local/etc/php-fpm.conf
    ExecReload=/bin/kill -USR2 $MAINPID
    
  7. サービスファイルを再読み込みする

    # systemctl daemon-reload
    
  8. Nginx の設定ファイルを作成する

    # cp /etc/nginx/conf.d/default.conf /etc/nginx/conf.d/default.conf.`date +%F`
    # mv /etc/nginx/conf.d/default.conf /etc/nginx/conf.d/wordpress.conf
    # vi /etc/nginx/conf.d/wordpress.conf
    
    wordpress.conf
    server_name localhost;
    root   /usr/share/nginx/html;
    (中略)
    
    location / {
        index  index.php index.html index.htm;
    }
    
    (中略)
    
    location ~* \.php$ {
        fastcgi_index  index.php;
        fastcgi_pass   127.0.0.1:9000;
        include        fastcgi_params;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        fastcgi_param  SCRIPT_NAME      $fastcgi_script_name;
    }
    
  9. 設定ファイルが正しいことを確認する

    # nginx -t
    nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
    nginx: configuration file /etc/nginx/nginx.conf test is successful
    
  10. php-fpm と Nginx を起動する

    # systemctl start php-fpm
    # systemctl start nginx
    

確認

# rm /usr/share/nginx/html/index.html
# echo "<?php phpinfo(); ?>" >> /usr/share/nginx/html/index.php
# systemctl restart nginx

ブラウザからサーバにアクセスして次のような画面になればOK

PHP情報画面(テスト用).png

参考

5
5
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
5
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?