PHP 5.6のセキュリティーサポートは2018年末まで延長されたこともありますが、PHP 7系の案件も、ここ最近ではボチボチ見られるようにもなってきました。

かなり前にセットアップしたまま放置していたAWSのAmazon Machine Imagesで、PHPのバージョンの古いものがありましたので7.1にアップデートしたいと思います。

まず、インストール済みのPHPを削除したいと思いますので、PHP関連のものでインストールされているものを削除しておきます。

[root@ip-172-30-0-75 html]# yum remove php *
Loaded plugins: priorities, update-motd, upgrade-helper



Resolving Dependencies
–> Running transaction check
—> Package php.x86_64 0:5.3.29-1.8.amzn1 will be erased
–> Finished Dependency Resolution

Dependencies Resolved

================================================================================
Package Arch Version Repository Size
================================================================================
Removing:
php x86_64 5.3.29-1.8.amzn1 @amzn-main 7.4 M

Transaction Summary
================================================================================
Remove 1 Package

Installed size: 7.4 M
Is this ok [y/N]: y
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Erasing : php-5.3.29-1.8.amzn1.x86_64 1/1
Verifying : php-5.3.29-1.8.amzn1.x86_64 1/1

Removed:
php.x86_64 0:5.3.29-1.8.amzn1

Complete!

なんと、この環境はPHP 5.3でした。。。

とりあえず、バージョンを確認してみましょう。

[root@ip-172-30-0-75 html]# php -v
PHP 5.3.29 (cli) (built: May 12 2015 22:42:19)
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2014 Zend Technologies

完全には削除されていないみたいです。
試しにPHP 7.0をインストールする直前まで試してみたいと思います。

[root@ip-172-30-0-75 html]# yum install php70
Loaded plugins: priorities, update-motd, upgrade-helper
Resolving Dependencies
–> Running transaction check
—> Package php70.x86_64 0:7.0.16-1.21.amzn1 will be installed
–> Processing Dependency: php70-cli(x86-64) = 7.0.16-1.21.amzn1 for package: php70-7.0.16-1.21.amzn1.x86_64
–> Processing Dependency: php70-common(x86-64) = 7.0.16-1.21.amzn1 for package: php70-7.0.16-1.21.amzn1.x86_64
–> Processing Dependency: httpd-mmn = 20120211×86-64 for package: php70-7.0.16-1.21.amzn1.x86_64
–> Processing Dependency: php70-common for package: php70-7.0.16-1.21.amzn1.x86_64
–> Processing Dependency: httpd24 for package: php70-7.0.16-1.21.amzn1.x86_64
–> Running transaction check
—> Package httpd24.x86_64 0:2.4.25-1.68.amzn1 will be installed
–> Processing Dependency: httpd24-tools = 2.4.25-1.68.amzn1 for package: httpd24-2.4.25-1.68.amzn1.x86_64
—> Package php70-cli.x86_64 0:7.0.16-1.21.amzn1 will be installed
—> Package php70-common.x86_64 0:7.0.16-1.21.amzn1 will be installed
–> Processing Dependency: php70-xml(x86-64) = 7.0.16-1.21.amzn1 for package: php70-common-7.0.16-1.21.amzn1.x86_64
–> Processing Dependency: php70-process(x86-64) = 7.0.16-1.21.amzn1 for package: php70-common-7.0.16-1.21.amzn1.x86_64
–> Processing Dependency: php70-json(x86-64) for package: php70-common-7.0.16-1.21.amzn1.x86_64
–> Running transaction check
—> Package httpd24-tools.x86_64 0:2.4.25-1.68.amzn1 will be installed
—> Package php70-json.x86_64 0:7.0.16-1.21.amzn1 will be installed
—> Package php70-process.x86_64 0:7.0.16-1.21.amzn1 will be installed
—> Package php70-xml.x86_64 0:7.0.16-1.21.amzn1 will be installed
–> Processing Conflict: httpd24-2.4.25-1.68.amzn1.x86_64 conflicts httpd < 2.4.25
--> Processing Conflict: php70-cli-7.0.16-1.21.amzn1.x86_64 conflicts php-cli < 5.5.22-1.98
--> Processing Conflict: php70-common-7.0.16-1.21.amzn1.x86_64 conflicts php-common < 5.5.22-1.98
--> Processing Conflict: httpd24-tools-2.4.25-1.68.amzn1.x86_64 conflicts httpd-tools < 2.4.25
--> Finished Dependency Resolution
Error: php70-common conflicts with php-common-5.3.29-1.8.amzn1.x86_64
Error: php70-cli conflicts with php-cli-5.3.29-1.8.amzn1.x86_64
Error: httpd24-tools conflicts with httpd-tools-2.2.32-1.9.amzn1.x86_64
Error: httpd24 conflicts with httpd-2.2.32-1.9.amzn1.x86_64
You could try using –skip-broken to work around the problem
You could try running: rpm -Va –nofiles –nodigest

何かエラーが出ています。
モジュールがコンフリクトしていますので古い方を削除します。

[root@ip-172-30-0-75 html]# yum remove php-common-5.3.29-1.8.amzn1.x86_64
Loaded plugins: priorities, update-motd, upgrade-helper
Resolving Dependencies
–> Running transaction check
—> Package php-common.x86_64 0:5.3.29-1.8.amzn1 will be erased
–> Processing Dependency: php-common(x86-64) = 5.3.29-1.8.amzn1 for package: php-fpm-5.3.29-1.8.amzn1.x86_64
–> Processing Dependency: php-common(x86-64) = 5.3.29-1.8.amzn1 for package: php-mbstring-5.3.29-1.8.amzn1.x86_64
–> Processing Dependency: php-common(x86-64) = 5.3.29-1.8.amzn1 for package: php-cli-5.3.29-1.8.amzn1.x86_64
–> Running transaction check
—> Package php-cli.x86_64 0:5.3.29-1.8.amzn1 will be erased
—> Package php-fpm.x86_64 0:5.3.29-1.8.amzn1 will be erased
—> Package php-mbstring.x86_64 0:5.3.29-1.8.amzn1 will be erased
–> Finished Dependency Resolution

Dependencies Resolved

================================================================================
Package Arch Version Repository Size
================================================================================
Removing:
php-common x86_64 5.3.29-1.8.amzn1 @amzn-main 6.3 M
Removing for dependencies:
php-cli x86_64 5.3.29-1.8.amzn1 @amzn-main 6.4 M
php-fpm x86_64 5.3.29-1.8.amzn1 @amzn-main 3.3 M
php-mbstring x86_64 5.3.29-1.8.amzn1 @amzn-main 4.1 M

Transaction Summary
================================================================================
Remove 1 Package (+3 Dependent packages)

Installed size: 20 M
Is this ok [y/N]: y
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Erasing : php-fpm-5.3.29-1.8.amzn1.x86_64 1/4
warning: /etc/php-fpm.d/www.conf saved as /etc/php-fpm.d/www.conf.rpmsave
Erasing : php-mbstring-5.3.29-1.8.amzn1.x86_64 2/4
Erasing : php-cli-5.3.29-1.8.amzn1.x86_64 3/4
Erasing : php-common-5.3.29-1.8.amzn1.x86_64 4/4
Verifying : php-common-5.3.29-1.8.amzn1.x86_64 1/4
Verifying : php-cli-5.3.29-1.8.amzn1.x86_64 2/4
Verifying : php-mbstring-5.3.29-1.8.amzn1.x86_64 3/4
Verifying : php-fpm-5.3.29-1.8.amzn1.x86_64 4/4

Removed:
php-common.x86_64 0:5.3.29-1.8.amzn1

Dependency Removed:
php-cli.x86_64 0:5.3.29-1.8.amzn1 php-fpm.x86_64 0:5.3.29-1.8.amzn1
php-mbstring.x86_64 0:5.3.29-1.8.amzn1

Complete!

Apache関連のモジュールもコンフリクトするようなので削除します。

[root@ip-172-30-0-75 html]# yum remove httpd-tools-2.2.32-1.9.amzn1.x86_64
Loaded plugins: priorities, update-motd, upgrade-helper
Resolving Dependencies
–> Running transaction check
—> Package httpd-tools.x86_64 0:2.2.32-1.9.amzn1 will be erased
–> Processing Dependency: httpd-tools = 2.2.32-1.9.amzn1 for package: httpd-2.2.32-1.9.amzn1.x86_64
–> Running transaction check
—> Package httpd.x86_64 0:2.2.32-1.9.amzn1 will be erased
–> Finished Dependency Resolution

Dependencies Resolved

================================================================================
Package Arch Version Repository Size
================================================================================
Removing:
httpd-tools x86_64 2.2.32-1.9.amzn1 @amzn-updates 135 k
Removing for dependencies:
httpd x86_64 2.2.32-1.9.amzn1 @amzn-updates 3.1 M

Transaction Summary
================================================================================
Remove 1 Package (+1 Dependent package)

Installed size: 3.2 M
Is this ok [y/N]: y
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Erasing : httpd-2.2.32-1.9.amzn1.x86_64 1/2
Erasing : httpd-tools-2.2.32-1.9.amzn1.x86_64 2/2
Verifying : httpd-tools-2.2.32-1.9.amzn1.x86_64 1/2
Verifying : httpd-2.2.32-1.9.amzn1.x86_64 2/2

Removed:
httpd-tools.x86_64 0:2.2.32-1.9.amzn1

Dependency Removed:
httpd.x86_64 0:2.2.32-1.9.amzn1

Complete!

依存関係のあるモジュールもあわせて削除されたようです。これでインストールができるはず。
ということで、yumのリポジトリにphp71を参照しているremiを登録します。

[root@ip-172-30-0-75 html]# wget http://rpms.famillecollet.com/enterprise/remi-release-6.rpm
–2017-07-11 02:13:35– http://rpms.famillecollet.com/enterprise/remi-release-6.rpm
Resolving rpms.famillecollet.com (rpms.famillecollet.com)… 195.154.241.117, 2001:bc8:33a1:100::1
Connecting to rpms.famillecollet.com (rpms.famillecollet.com)|195.154.241.117|:80… connected.
HTTP request sent, awaiting response… 200 OK
Length: 11400 (11K) [application/x-rpm]
Saving to: ‘remi-release-6.rpm’

remi-release-6.rpm 100%[===================>] 11.13K –.-KB/s in 0s

2017-07-11 02:13:36 (39.5 MB/s) – ‘remi-release-6.rpm’ saved [11400/11400]
[root@ip-172-30-0-75 html]# rpm -ivh remi-release-6.rpm
warning: remi-release-6.rpm: Header V4 DSA/SHA1 Signature, key ID 00f97f56: NOKEY
Preparing… ################################# [100%]
Updating / installing…
1:remi-release-6.9-1.el6.remi ################################# [100%]

それではPHP 7.1をインストールしてみたいと思います。

[root@ip-172-30-0-75 html]# yum –enablerepo=remi-php71 –disablerepo=amzn-main install php
Loaded plugins: priorities, update-motd, upgrade-helper
remi-php71 | 2.9 kB 00:00
remi-safe | 2.9 kB 00:00
(1/2): remi-php71/primary_db | 171 kB 00:02
(2/2): remi-safe/primary_db | 733 kB 00:05
Resolving Dependencies
–> Running transaction check
—> Package php.x86_64 0:7.1.7-1.el6.remi will be installed
–> Processing Dependency: php-common(x86-64) = 7.1.7-1.el6.remi for package: php-7.1.7-1.el6.remi.x86_64
–> Processing Dependency: php-cli(x86-64) = 7.1.7-1.el6.remi for package: php-7.1.7-1.el6.remi.x86_64
–> Processing Dependency: httpd-mmn = 20051115 for package: php-7.1.7-1.el6.remi.x86_64
–> Processing Dependency: httpd for package: php-7.1.7-1.el6.remi.x86_64
–> Running transaction check
—> Package httpd.x86_64 0:2.2.32-1.9.amzn1 will be installed
–> Processing Dependency: httpd-tools = 2.2.32-1.9.amzn1 for package: httpd-2.2.32-1.9.amzn1.x86_64
—> Package php-cli.x86_64 0:7.1.7-1.el6.remi will be installed
—> Package php-common.x86_64 0:7.1.7-1.el6.remi will be installed
–> Processing Dependency: php-json(x86-64) = 7.1.7-1.el6.remi for package: php-common-7.1.7-1.el6.remi.x86_64
–> Running transaction check
—> Package httpd-tools.x86_64 0:2.2.32-1.9.amzn1 will be installed
—> Package php-json.x86_64 0:7.1.7-1.el6.remi will be installed
–> Finished Dependency Resolution

Dependencies Resolved

================================================================================
Package Arch Version Repository Size
================================================================================
Installing:
php x86_64 7.1.7-1.el6.remi remi-php71 2.8 M
Installing for dependencies:
httpd x86_64 2.2.32-1.9.amzn1 amzn-updates 1.2 M
httpd-tools x86_64 2.2.32-1.9.amzn1 amzn-updates 80 k
php-cli x86_64 7.1.7-1.el6.remi remi-php71 4.1 M
php-common x86_64 7.1.7-1.el6.remi remi-php71 994 k
php-json x86_64 7.1.7-1.el6.remi remi-php71 53 k

Transaction Summary
================================================================================
Install 1 Package (+5 Dependent packages)

Total download size: 9.3 M
Installed size: 32 M
Is this ok [y/d/N]: y
Downloading packages:
(1/6): httpd-2.2.32-1.9.amzn1.x86_64.rpm | 1.2 MB 00:00
(2/6): httpd-tools-2.2.32-1.9.amzn1.x86_64.rpm | 80 kB 00:00
warning: /var/cache/yum/x86_64/latest/remi-php71/packages/php-common-7.1.7-1.el6.remi.x86_64.rpm: Header V4 DSA/SHA1 Signature, key ID 00f97f56: NOKEY
Public key for php-common-7.1.7-1.el6.remi.x86_64.rpm is not installed
(3/6): php-common-7.1.7-1.el6.remi.x86_64.rpm | 994 kB 00:01
(4/6): php-json-7.1.7-1.el6.remi.x86_64.rpm | 53 kB 00:01
(5/6): php-7.1.7-1.el6.remi.x86_64.rpm | 2.8 MB 00:41
(6/6): php-cli-7.1.7-1.el6.remi.x86_64.rpm | 4.1 MB 03:09
——————————————————————————–
Total 50 kB/s | 9.3 MB 03:09
Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-remi
Importing GPG key 0x00F97F56:
Userid : “Remi Collet
Fingerprint: 1ee0 4cce 88a4 ae4a a29a 5df5 004e 6f47 00f9 7f56
Package : remi-release-6.9-1.el6.remi.noarch (installed)
From : /etc/pki/rpm-gpg/RPM-GPG-KEY-remi
Is this ok [y/N]: y
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Warning: RPMDB altered outside of yum.
Installing : php-json-7.1.7-1.el6.remi.x86_64 1/6
Installing : php-common-7.1.7-1.el6.remi.x86_64 2/6
Installing : php-cli-7.1.7-1.el6.remi.x86_64 3/6
Installing : httpd-tools-2.2.32-1.9.amzn1.x86_64 4/6
Installing : httpd-2.2.32-1.9.amzn1.x86_64 5/6
Installing : php-7.1.7-1.el6.remi.x86_64 6/6
Verifying : httpd-tools-2.2.32-1.9.amzn1.x86_64 1/6
Verifying : php-common-7.1.7-1.el6.remi.x86_64 2/6
Verifying : php-json-7.1.7-1.el6.remi.x86_64 3/6
Verifying : php-7.1.7-1.el6.remi.x86_64 4/6
Verifying : php-cli-7.1.7-1.el6.remi.x86_64 5/6
Verifying : httpd-2.2.32-1.9.amzn1.x86_64 6/6

Installed:
php.x86_64 0:7.1.7-1.el6.remi

Dependency Installed:
httpd.x86_64 0:2.2.32-1.9.amzn1 httpd-tools.x86_64 0:2.2.32-1.9.amzn1
php-cli.x86_64 0:7.1.7-1.el6.remi php-common.x86_64 0:7.1.7-1.el6.remi
php-json.x86_64 0:7.1.7-1.el6.remi

Complete!

関連するPHPのモジュールも合わせてインストールします。

[root@ip-172-30-0-75 html]# yum –enablerepo=remi-php71 –disablerepo=amzn-main install php-pdo php-mbstring php-fpm
Loaded plugins: priorities, update-motd, upgrade-helper
Resolving Dependencies
–> Running transaction check
—> Package php-fpm.x86_64 0:7.1.7-1.el6.remi will be installed
—> Package php-mbstring.x86_64 0:7.1.7-1.el6.remi will be installed
—> Package php-pdo.x86_64 0:7.1.7-1.el6.remi will be installed
–> Finished Dependency Resolution

Dependencies Resolved

================================================================================
Package Arch Version Repository Size
================================================================================
Installing:
php-fpm x86_64 7.1.7-1.el6.remi remi-php71 1.4 M
php-mbstring x86_64 7.1.7-1.el6.remi remi-php71 977 k
php-pdo x86_64 7.1.7-1.el6.remi remi-php71 105 k

Transaction Summary
================================================================================
Install 3 Packages

Total download size: 2.5 M
Installed size: 7.1 M
Is this ok [y/d/N]: y
Downloading packages:
(1/3): php-fpm-7.1.7-1.el6.remi.x86_64.rpm | 1.4 MB 00:01
(2/3): php-pdo-7.1.7-1.el6.remi.x86_64.rpm | 105 kB 00:01
(3/3): php-mbstring-7.1.7-1.el6.remi.x86_64.rpm | 977 kB 00:52
——————————————————————————–
Total 48 kB/s | 2.5 MB 00:52
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : php-fpm-7.1.7-1.el6.remi.x86_64 1/3
Installing : php-mbstring-7.1.7-1.el6.remi.x86_64 2/3
Installing : php-pdo-7.1.7-1.el6.remi.x86_64 3/3
Verifying : php-pdo-7.1.7-1.el6.remi.x86_64 1/3
Verifying : php-mbstring-7.1.7-1.el6.remi.x86_64 2/3
Verifying : php-fpm-7.1.7-1.el6.remi.x86_64 3/3

Installed:
php-fpm.x86_64 0:7.1.7-1.el6.remi php-mbstring.x86_64 0:7.1.7-1.el6.remi
php-pdo.x86_64 0:7.1.7-1.el6.remi

Complete!

あらためてPHPのバージョンを確認してみます。

[root@ip-172-30-0-75 html]# php -v
PHP 7.1.7 (cli) (built: Jul 6 2017 13:46:08) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2017 Zend Technologies

PHP 7.1がインストールされました!

php-fpmのコンフィグがwww.conf.rpmsaveというファイル名でバックアップされており、新しいものも作成されていました。
以前の設定を全て思い出すのが大変なので、一旦バックアップされたwww.conf.rpmsaveをwww.confにリネームしてからphp-fpmを起動させたいと思います。

[root@ip-172-30-0-44 wordpress]# cd /etc/php-fpm.d/
[root@ip-172-30-0-44 php-fpm.d]# ls -lv
total 44
-rw-r–r– 1 root root 9865 Jul 5 2014 www.conf~
-rw-r–r– 1 root root 19129 Jul 6 20:49 www.conf
-rw-r–r– 1 root root 9898 Jun 26 2016 www.conf.rpmsave
[root@ip-172-30-0-44 php-fpm.d]# mv www.conf www.conf.org
[root@ip-172-30-0-44 php-fpm.d]# mv www.conf.rpmsave www.conf

php-fpmを起動します。

[root@ip-172-30-0-75 php-fpm.d]# /etc/rc.d/init.d/php-fpm start
Starting php-fpm: [ OK ]

phpinfoを確認してみると、、、ちゃんとPHP 7.1で起動していることが確認できました!

phpinfo

参考サイト

EC2ですばやくNginx+php7-fpmでPHPを動かす(ちょっとLaravelも) – Qiita
Amazon LinuxでPHP5.6からPHP7にアップデートする – owani.net#markdown
Amazon Linux に php7.1 をインストール | // sakura note

関連記事

Trackback URL