PHP インストール
Nid: 1151
- PHPのインストール
$ export PHP_VERSION='7.2' $ sudo apt-get install -y php"$PHP_VERSION"-{cli,fpm,zip,curl,gd,xml,mbstring,mysql,intl,soap,xmlrpc,bcmath,common} $ php -v PHP 7.2.10-0ubuntu0.18.04.1 (cli) (built: Sep 13 2018 13:45:02) ( NTS ) Copyright (c) 1997-2018 The PHP Group Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies with Zend OPcache v7.2.10-0ubuntu0.18.04.1, Copyright (c) 1999-2018, by Zend Technologies
$ systemctl status php"$PHP_VERSION"-fpm ● php7.2-fpm.service - The PHP 7.2 FastCGI Process Manager Loaded: loaded (/lib/systemd/system/php7.2-fpm.service; enabled; vendor preset: enabled) Active: active (running) since Sat 2018-12-15 09:37:41 UTC; 29s ago Docs: man:php-fpm7.2(8) Main PID: 12196 (php-fpm7.2) Status: "Processes active: 0, idle: 2, Requests: 0, slow: 0, Traffic: 0req/sec" Tasks: 3 (limit: 4915) CGroup: /system.slice/php7.2-fpm.service ├─12196 php-fpm: master process (/etc/php/7.2/fpm/php-fpm.conf) ├─12207 php-fpm: pool www └─12208 php-fpm: pool www
- 設定ファイル
$ php --ini Configuration File (php.ini) Path: /etc/php/7.2/cli Loaded Configuration File: /etc/php/7.2/cli/php.ini Scan for additional .ini files in: /etc/php/7.2/cli/conf.d Additional .ini files parsed: /etc/php/7.2/cli/conf.d/10-mysqlnd.ini, /etc/php/7.2/cli/conf.d/10-opcache.ini, /etc/php/7.2/cli/conf.d/10-pdo.ini, /etc/php/7.2/cli/conf.d/15-xml.ini, /etc/php/7.2/cli/conf.d/20-calendar.ini, /etc/php/7.2/cli/conf.d/20-ctype.ini, /etc/php/7.2/cli/conf.d/20-curl.ini, /etc/php/7.2/cli/conf.d/20-dom.ini, /etc/php/7.2/cli/conf.d/20-exif.ini, /etc/php/7.2/cli/conf.d/20-fileinfo.ini, /etc/php/7.2/cli/conf.d/20-ftp.ini, /etc/php/7.2/cli/conf.d/20-gd.ini, /etc/php/7.2/cli/conf.d/20-gettext.ini, /etc/php/7.2/cli/conf.d/20-iconv.ini, /etc/php/7.2/cli/conf.d/20-json.ini, /etc/php/7.2/cli/conf.d/20-mbstring.ini, /etc/php/7.2/cli/conf.d/20-mysqli.ini, /etc/php/7.2/cli/conf.d/20-pdo_mysql.ini, /etc/php/7.2/cli/conf.d/20-phar.ini, /etc/php/7.2/cli/conf.d/20-posix.ini, /etc/php/7.2/cli/conf.d/20-readline.ini, /etc/php/7.2/cli/conf.d/20-shmop.ini, /etc/php/7.2/cli/conf.d/20-simplexml.ini, /etc/php/7.2/cli/conf.d/20-sockets.ini, /etc/php/7.2/cli/conf.d/20-sysvmsg.ini, /etc/php/7.2/cli/conf.d/20-sysvsem.ini, /etc/php/7.2/cli/conf.d/20-sysvshm.ini, /etc/php/7.2/cli/conf.d/20-tokenizer.ini, /etc/php/7.2/cli/conf.d/20-wddx.ini, /etc/php/7.2/cli/conf.d/20-xmlreader.ini, /etc/php/7.2/cli/conf.d/20-xmlwriter.ini, /etc/php/7.2/cli/conf.d/20-xsl.ini, /etc/php/7.2/cli/conf.d/20-zip.ini
- パラメータ設定
$ sudo vim /etc/php/"$PHP_VERSION"/fpm/php.ini max_execution_time = 300 upload_max_filesize = 128M post_max_size = 256M memory_limit = 512M
- PHP を再起動して設定反映
$ sudo systemctl restart php"$PHP_VERSION"-fpm.service
- 動作確認用のファイル作成
$ sudo tee /var/www/html/info.php <<EOF <?php phpinfo(); ?> EOF
以下コメントイン。一部編集 php7.0->php7.2。ネットワークオーバーヘッドを減らすため、TCP ではなく Unix sockets を使用。
$ sudo vi /etc/nginx/sites-available/default location ~ \.php$ { include snippets/fastcgi-php.conf; fastcgi_pass unix:/var/run/php/php-fpm.sock; }
最低限のNginx設定
$ cat /etc/nginx/sites-available/default server { listen 80 default_server; listen [::]:80 default_server; root /var/www/html; index index.html index.htm; server_name _; location / { try_files $uri $uri/ =404; } location ~ \.php$ { include snippets/fastcgi-php.conf; fastcgi_pass unix:/var/run/php/php-fpm.sock; } }
$ sudo nginx -t && sudo nginx -s reload
確認。
$ lynx --dump http://localhost/info.php | grep -i 'server.*fpm' Server API FPM/FastCGI
動作確認用ファイル削除。
$ sudo mv /var/www/html/info.php /tmp