CentOS 7 + Nginx + rep2 その5
rep2が要求する PHPは 7.xなので、標準レポジトリの 5.xだと使用できない為
remiレポジトリを追加する
-> http://rpms.famillecollet.com/
事前にEPELレポジトリが追加されていないとダメだが、既に追加済みの為この手順はスキップ
サイトにある、remiレポジトリのURLからインストールを実施
# rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-7.rpm # # ls -l /etc/yum.repos.d/ total 64 -rw-r--r--. 1 root root 1664 Aug 31 2017 CentOS-Base.repo -rw-r--r--. 1 root root 1309 Aug 31 2017 CentOS-CR.repo -rw-r--r--. 1 root root 649 Aug 31 2017 CentOS-Debuginfo.repo -rw-r--r--. 1 root root 314 Aug 31 2017 CentOS-fasttrack.repo -rw-r--r--. 1 root root 630 Aug 31 2017 CentOS-Media.repo -rw-r--r--. 1 root root 1331 Aug 31 2017 CentOS-Sources.repo -rw-r--r--. 1 root root 3830 Aug 31 2017 CentOS-Vault.repo -rw-r--r-- 1 root root 951 Oct 3 2017 epel.repo -rw-r--r-- 1 root root 1050 Oct 3 2017 epel-testing.repo -rw-r--r-- 1 root root 108 Apr 15 21:17 nginx.repo -rw-r--r-- 1 root root 456 Mar 21 22:28 remi-php54.repo -rw-r--r-- 1 root root 1314 Mar 21 22:28 remi-php70.repo -rw-r--r-- 1 root root 1314 Mar 21 22:28 remi-php71.repo -rw-r--r-- 1 root root 1314 Mar 21 22:28 remi-php72.repo -rw-r--r-- 1 root root 2605 Mar 21 22:28 remi.repo -rw-r--r-- 1 root root 750 Mar 21 22:28 remi-safe.repo #
PHP7.2のrepoである、remi-php72.repoの設定をenableに変更
# cat /etc/yum.repos.d/remi-php72.repo # This repository only provides PHP 7.2 and its extensions # NOTICE: common dependencies are in "remi-safe" [remi-php72] name=Remi's PHP 7.2 RPM repository for Enterprise Linux 7 - $basearch #baseurl=http://rpms.remirepo.net/enterprise/7/php72/$basearch/ #mirrorlist=https://rpms.remirepo.net/enterprise/7/php72/httpsmirror mirrorlist=http://cdn.remirepo.net/enterprise/7/php72/mirror enabled=1 gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-remi [remi-php72-debuginfo] name=Remi's PHP 7.2 RPM repository for Enterprise Linux 7 - $basearch - debuginfo baseurl=http://rpms.remirepo.net/enterprise/7/debug-php72/$basearch/ enabled=0 gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-remi [remi-php72-test] name=Remi's PHP 7.2 test RPM repository for Enterprise Linux 7 - $basearch #baseurl=http://rpms.remirepo.net/enterprise/7/test72/$basearch/ #mirrorlist=https://rpms.remirepo.net/enterprise/7/test72/httpsmirror mirrorlist=http://cdn.remirepo.net/enterprise/7/test72/mirror enabled=0 gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-remi [remi-php72-test-debuginfo] name=Remi's PHP 7.2 test RPM repository for Enterprise Linux 7 - $basearch - debuginfo baseurl=http://rpms.remirepo.net/enterprise/7/debug-test72/$basearch/ enabled=0 gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-remi [root@rep2 conf.d]# cat /etc/yum.repos.d/nginx.repo [nginx] name=nginx repo baseurl=http://nginx.org/packages/mainline/centos/7/$basearch/ gpgcheck=0 enabled=1
remiレポジトリをenableにするとそっちが優先されるのね
php72パッケージじゃなくて、phpパッケージが全部remiからインストールされるようになってた
# yum info php php-common php-cli php-json php-mbstring php-pdo php-process php-xml Available Packages Name : php Arch : x86_64 Version : 7.2.4 Release : 1.el7.remi Size : 10 M Repo : remi-php72 Summary : PHP scripting language for creating dynamic web sites URL : http://www.php.net/ License : PHP and Zend and BSD and MIT and ASL 1.0 Description : PHP is an HTML-embedded scripting language. PHP attempts to make it : easy for developers to write dynamically generated web pages. PHP also : offers built-in database integration for several commercial and : non-commercial database management systems, so writing a : database-enabled webpage with PHP is fairly simple. The most common : use of PHP coding is probably as a replacement for CGI scripts. : : The php package contains the module (often referred to as mod_php) : which adds support for the PHP language to Apache HTTP Server. Name : php-cli Arch : x86_64 Version : 7.2.4 Release : 1.el7.remi Size : 15 M Repo : remi-php72 Summary : Command-line interface for PHP URL : http://www.php.net/ License : PHP and Zend and BSD and MIT and ASL 1.0 Description : The php-cli package contains the command-line interface : executing PHP scripts, /usr/bin/php, and the CGI interface. Name : php-common Arch : x86_64 Version : 7.2.4 Release : 1.el7.remi Size : 12 M Repo : remi-php72 Summary : Common files for PHP URL : http://www.php.net/ License : PHP and BSD Description : The php-common package contains files used by both the php : package and the php-cli package. Name : php-json Arch : x86_64 Version : 7.2.4 Release : 1.el7.remi Size : 88 k Repo : remi-php72 Summary : JavaScript Object Notation extension for PHP URL : http://www.php.net/ License : PHP Description : The php-json package provides an extension that will add : support for JavaScript Object Notation (JSON) to PHP. Name : php-mbstring Arch : x86_64 Version : 7.2.4 Release : 1.el7.remi Size : 620 k Repo : remi-php72 Summary : A module for PHP applications which need multi-byte string handling URL : http://www.php.net/ License : PHP and LGPLv2 and BSD and OpenLDAP Description : The php-mbstring package contains a dynamic shared object that will add : support for multi-byte string handling to PHP. Name : php-pdo Arch : x86_64 Version : 7.2.4 Release : 1.el7.remi Size : 390 k Repo : remi-php72 Summary : A database access abstraction module for PHP applications URL : http://www.php.net/ License : PHP Description : The php-pdo package contains a dynamic shared object that will add : a database access abstraction layer to PHP. This module provides : a common interface for accessing MySQL, PostgreSQL or other : databases. Name : php-process Arch : x86_64 Version : 7.2.4 Release : 1.el7.remi Size : 188 k Repo : remi-php72 Summary : Modules for PHP script using system process interfaces URL : http://www.php.net/ License : PHP Description : The php-process package contains dynamic shared objects which add : support to PHP using system interfaces for inter-process : communication. Name : php-xml Arch : x86_64 Version : 7.2.4 Release : 1.el7.remi Size : 855 k Repo : remi-php72 Summary : A module for PHP applications which use XML URL : http://www.php.net/ License : PHP Description : The php-xml package contains dynamic shared objects which add support : to PHP for manipulating XML documents using the DOM tree, : and performing XSL transformations on XML documents.
PHPの幾つかのパッケージは httpd をdependで要求するので、httpdは取り敢えずインストールして Disableにしておくか
# yum install php php-common php-cli php-json php-mbstring php-pdo php-process php-xml
NginxでPHPを動かす為に、CGI型のPHP-FPMを導入する
# yum install php-fpm
PHP-FPMはデフォルトが Apacheの設定になっているので修正
# cd /etc/php-fpm.d # vi www.conf
user と group を、 apache -> nginx に変更
PHP-FPMを自動起動設定
# systemctl enable php-fpm Created symlink from /etc/systemd/system/multi-user.target.wants/php-fpm.service to /usr/lib/systemd/system/php-fpm.service. # systemctl start php-fpm # systemctl status php-fpm ● php-fpm.service - The PHP FastCGI Process Manager Loaded: loaded (/usr/lib/systemd/system/php-fpm.service; enabled; vendor preset: disabled) Active: active (running) since Mon 2018-04-16 00:57:56 JST; 1s ago Main PID: 7723 (php-fpm) Status: "Ready to handle connections" CGroup: /system.slice/php-fpm.service tq7723 php-fpm: master process (/etc/php-fpm.conf) tq7724 php-fpm: pool www tq7725 php-fpm: pool www tq7726 php-fpm: pool www tq7727 php-fpm: pool www mq7728 php-fpm: pool www Apr 16 00:57:56 rep2 systemd[1]: Starting The PHP FastCGI Process Manager... Apr 16 00:57:56 rep2 systemd[1]: Started The PHP FastCGI Process Manager.
NginxがPHPを扱えるように設定変更を実施
# cat /etc/nginx/conf.d/<自ドメイン>.conf server { listen <Port No>; server_name <Domain Name>; #charset koi8-r; #access_log /var/log/nginx/host.access.log main; location / { root /var/www/html; index index.html index.htm index.php; } #error_page 404 /404.html; # redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; location = /50x.html { root /var/www/html; } # proxy the PHP scripts to Apache listening on 127.0.0.1:80 # #location ~ \.php$ { # proxy_pass http://127.0.0.1; #} # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # location ~ \.php$ { root /var/www/html; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } # deny access to .htaccess files, if Apache's document root # concurs with nginx's one # #location ~ /\.ht { # deny all; #} }
Nginxの設定ファイルを変更したので、再起動
# systemctl restart nginx
phpinfoファイルを作成してphpの動作検証
# cat /var/www/html/phpinfo.php <?php phpinfo(); ?>
phpinfo.phpにアクセスして、PHPの動作状況が表示されればOK
(セキュリティの為には、動作チェック終わった後はファイルを削除しておいたほうが良い)