CentOS 6.7で使っているPHP5.3をPHP5.6にアップデート

2016年5月15日

サーバー テクノロジー 日記

vagrantで使っているPHP5.3でjson_encodeの「JSON_PRETTY_PRINT」モードが利用できないのでPHP5.4以上にアップする必要があったので、とりあえずPHP7の手前のPHP5.6にアップしてみようと思います。

事前確認

とりあえずセオリーどおりの手順をメモっておきます。

現在バージョンの確認

$ php -v PHP 5.3.3 (cli) (built: Feb 9 2016 10:36:17) Copyright (c) 1997-2010 The PHP Group Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies

インストールできるPHPバージョンの確認

$ yum info php Loaded plugins: fastestmirror, versionlock Loading mirror speeds from cached hostfile * base: ftp.jaist.ac.jp * epel: free.nchc.org.tw * extras: ftp.jaist.ac.jp * updates: ftp.jaist.ac.jp Installed Packages Name : php Arch : x86_64 Version : 5.3.3 Release : 46.el6_7.1 Size : 3.5 M Repo : installed From repo : updates Summary : PHP scripting language for creating dynamic web sites URL : http://www.php.net/ License : PHP Description : PHP is an HTML-embedded scripting language. PHP attempts to make it : easy for developers to write dynamically generated webpages. 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 which adds support for the PHP : language to Apache HTTP Server. このままだと5.3しかインストールできないのでリポジトリを更新する必要があります。

リポジトリ確認

$ rpm -qa | grep epel epel-release-6-8.noarch $ rpm -qa | grep remi remiが無いことが分かりました。

リポジトリを一旦削除

$ rpm -e epel-release-6-8.noarch remiがインストールされていた場合はそちらも削除しておきましょう。

リポジトリのインストール

$ rpm -ivh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm $ rpm -ivh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm

インストールモジュールの確認

$ yum --enablerepo=epel,remi-php56 info php Loaded plugins: fastestmirror, versionlock Loading mirror speeds from cached hostfile * base: ftp.jaist.ac.jp * epel: free.nchc.org.tw * extras: ftp.jaist.ac.jp * remi-php56: mirror.innosol.asia * remi-safe: mirror.innosol.asia * updates: ftp.jaist.ac.jp remi-php56 | 2.9 kB 00:00 remi-php56/primary_db | 204 kB 00:01 Installed Packages Name : php Arch : x86_64 Version : 5.3.3 Release : 46.el6_7.1 Size : 3.5 M Repo : installed From repo : updates Summary : PHP scripting language for creating dynamic web sites URL : http://www.php.net/ License : PHP Description : PHP is an HTML-embedded scripting language. PHP attempts to make it : easy for developers to write dynamically generated webpages. 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 which adds support for the PHP : language to Apache HTTP Server. Available Packages Name : php Arch : x86_64 Version : 5.6.21 Release : 1.el6.remi Size : 2.7 M Repo : remi-php56 Summary : PHP scripting language for creating dynamic web sites URL : http://www.php.net/ License : PHP and Zend and BSD 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. PHP5.6が確認できたらリポジトリの更新完了です。

既存PHPのアンインストール

$ yum erase php* $ yum remove php* 上記どちらでもいいので、実行。

インストール

$ yum --enablerepo=epel,remi-php56 install php php-common php-mbstring php-gd 他にも必要なモジュールがあれば後でもいいので追加インストールしましょう。

標準の手順でインストールできない場合

vertualboxで長く使っていた場合、リポジトリがバカになっている事があり、 上記手順でうまくリポジトリを指定してもPHP5.3以外のバージョンが認識されない場合があります。 $ yum install php56 のようにしてインストールしてもいいんですが、PHPのCLI実行などで $ php56 ***.php のようなコマンドになってしまうため、標準状態でインストールすることをオススメします。 とりあえず、僕の環境でリポジトリがおかしかった場合の対処方法をメモしておきます。

リポジトリファイルの確認

$ ls -lha /etc/yum.repos.d/ total 100K drwxr-xr-x. 2 root root 4.0K 2016-05-13 15:50 . drwxr-xr-x. 91 root root 4.0K 2016-05-13 16:02 .. -rw-r--r-- 1 root root 2.1K 2015-11-03 04:17 CentOS-Base.repo -rw-r--r-- 1 root root 647 2015-08-03 16:13 CentOS-Debuginfo.repo -rw-r--r-- 1 root root 630 2015-08-03 16:13 CentOS-Media.repo -rw-r--r-- 1 root root 6.2K 2015-08-03 16:13 CentOS-Vault.repo -rw-r--r-- 1 root root 289 2015-08-03 16:13 CentOS-fasttrack.repo -rw-r--r-- 1 root root 166 2016-04-14 10:23 docker-main.repo -rw-r--r-- 1 root root 166 2016-04-14 10:21 docker.repo -rw-r--r-- 1 root root 1.1K 2012-11-05 03:52 epel-testing.repo -rw-r--r-- 1 root root 957 2016-05-12 14:17 epel.repo -rw-r--r-- 1 root root 990 2015-11-03 04:17 epel.repo.rpmsave -rw-r--r-- 1 root root 739 2013-03-20 14:24 mirrors-rpmforge -rw-r--r-- 1 root root 717 2013-03-20 14:24 mirrors-rpmforge-extras -rw-r--r-- 1 root root 728 2013-03-20 14:24 mirrors-rpmforge-testing -rw-r--r-- 1 root root 1.2K 2015-12-09 09:14 remi-php70.repo -rw-r--r-- 1 root root 449 2015-12-09 09:14 remi-safe.repo -rw-r--r-- 1 root root 2.3K 2015-12-09 09:14 remi.repo -rw-r--r-- 1 root root 2.3K 2015-12-09 09:14 remi.repo.rpmnew -rw-r--r-- 1 root root 2.3K 2016-05-12 22:23 remi.repo.rpmsave -rw-r--r-- 1 root root 1.2K 2013-03-20 14:24 rpmforge.repo -rw-r--r-- 1 root root 966 2015-07-04 06:59 webtatic-archive.repo -rw-r--r-- 1 root root 966 2015-07-04 06:59 webtatic-testing.repo -rw-r--r-- 1 root root 868 2015-07-04 06:59 webtatic.repo 上記の「CentOS-Base.repo」が標準のリポジトリのようなので、これをリネームして無効にすることで、上記インストール手順で上位バージョンのインストールができました。

既存リポジトリの排除

$ mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak

php5.6のインストール

$ yum --enablerepo=epel,remi-php56 install php php-common php-mbstring php-gd これでできない場合は標準リポジトリのファイルが違う場合が多いので、探してみましょう。

このブログを検索

ごあいさつ

このWebサイトは、独自思考で我が道を行くユゲタの少し尖った思考のTechブログです。 毎日興味がどんどん切り替わるので、テーマはマルチになっています。 もしかしたらアイデアに困っている人の助けになるかもしれません。