提供:すだちWiki
移動先: 案内検索

ヘルプ:yumでPHP7.1をインストールする方法(CentOS7)

メインページ > ヘルプ:目次 > ヘルプ:自宅サーバー構築(CentOS7)  > yumでPHP7.1をインストールする方法(CentOS7)

CentOSバージョン確認

[root@host2 ~]# cat /etc/redhat-release
CentOS Linux release 7.4.1708 (Core)

PHP7.1用のRemiリポジトリの優先度を1(最大)にする

エラーが出たため、PHP7.1用のRemiリポジトリの優先度を1(最大)にすることで問題を回避しました。

[root@host2 ~]# vi /etc/yum.repos.d/remi-php71.repo

[remi-php71]
priority=1 ← 追加
name=Remi's PHP 7.1 RPM repository for Enterprise Linux 7 - $basearch
#baseurl=http://rpms.remirepo.net/enterprise/7/php71/$basearch/
mirrorlist=http://rpms.remirepo.net/enterprise/7/php71/mirror
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-remi

既に入っているPHPのバージョン確認

自宅サーバー2号機

 [root@host2 ~]# php -v
PHP 7.0.19 (cli) (built: May  9 2017 16:02:11) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies
    with Zend OPcache v7.0.19, Copyright (c) 1999-2017, by Zend Technologies
    with Xdebug v2.5.3, Copyright (c) 2002-2017, by Derick Rethans

自宅サーバー3号機

[root@host3 ~]# php -v

PHP 7.0.11 (cli) (built: Sep 14 2016 08:28:52) ( NTS )
Copyright (c) 1997-2016 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies
    with Zend OPcache v7.0.11, Copyright (c) 1999-2016, by Zend Technologies
    with Xdebug v2.5.3, Copyright (c) 2002-2017, by Derick Rethans

既に入っているPHPをアンインストール

インストール済みパッケージ確認

自宅サーバー2号機

PHP7.1にアップグレード前です。

[root@host2 ~]# rpm -qa | grep php
php-7.0.28-1.el7.remi.x86_64
php-pecl-apcu-5.1.9-1.el7.remi.7.0.x86_64
php-gmp-7.0.28-1.el7.remi.x86_64
php-pear-1.10.5-2.el7.remi.noarch
php-fpm-7.0.28-1.el7.remi.x86_64
php-cli-7.0.28-1.el7.remi.x86_64
php-opcache-7.0.28-1.el7.remi.x86_64
php-devel-7.0.28-1.el7.remi.x86_64
php-mcrypt-7.0.28-1.el7.remi.x86_64
php-pecl-apcu-bc-1.0.3-1.el7.remi.7.0.x86_64
php-common-7.0.28-1.el7.remi.x86_64
php-xml-7.0.28-1.el7.remi.x86_64
php-pecl-xdebug-2.5.5-1.el7.remi.7.0.x86_64
php-pdo-7.0.28-1.el7.remi.x86_64
php-gd-7.0.28-1.el7.remi.x86_64
php-mbstring-7.0.28-1.el7.remi.x86_64
php-json-7.0.28-1.el7.remi.x86_64
php-mysqlnd-7.0.28-1.el7.remi.x86_64
php-process-7.0.28-1.el7.remi.x86_64

自宅サーバー3号機

PHP7.1にアップグレード前です。

[root@host3 ~]# rpm -qa | grep php
php-xml-7.0.11-1.el7.remi.x86_64
php-opcache-7.0.11-1.el7.remi.x86_64
php-devel-7.0.11-1.el7.remi.x86_64
php-pdo-7.0.11-1.el7.remi.x86_64
php-mysqlnd-7.0.11-1.el7.remi.x86_64
php-fpm-7.0.11-1.el7.remi.x86_64
php-mbstring-7.0.11-1.el7.remi.x86_64
php-pecl-apcu-5.1.5-1.el7.remi.7.0.x86_64
php-json-7.0.11-1.el7.remi.x86_64
php-cli-7.0.11-1.el7.remi.x86_64
php-pear-1.10.1-6.el7.remi.noarch
php-mcrypt-7.0.11-1.el7.remi.x86_64
php-pecl-apcu-bc-1.0.3-1.el7.remi.7.0.x86_64
php-common-7.0.11-1.el7.remi.x86_64
php-7.0.11-1.el7.remi.x86_64
php-pecl-xdebug-2.5.3-2.el7.remi.7.0.x86_64
php-process-7.0.11-1.el7.remi.x86_64
php-gmp-7.0.11-1.el7.remi.x86_64
php-gd-7.0.11-1.el7.remi.x86_64

アンインストール

[root@host2 ~]# yum remove php php-* php70-*

[root@host2 ~]# php -v

[root@host2 ~]# rpm -qa | grep php

バージョン情報が出てこなければアンインストール完了です。

インストール

インストール実行

※行の長さの関係で途中に改行が這い入ってます。注意してください。

[root@host2 ~]# yum --enablerepo=remi-php71 install php php-cli php-devel php-common php-mbstring php-mysqlnd 
php-fpm php-gd php-gmp php-mcrypt php-opcache php-pdo php-xml php-json
・
・
依存性を解決しました

================================================================================
 Package            アーキテクチャー
                                 バージョン              リポジトリー      容量
================================================================================
インストール中:
 php                x86_64       7.1.16-1.el7.remi       remi-php71       3.0 M
 php-cli            x86_64       7.1.16-1.el7.remi       remi-php71       4.6 M
 php-common         x86_64       7.1.16-1.el7.remi       remi-php71       1.0 M
 php-devel          x86_64       7.1.16-1.el7.remi       remi-php71       1.1 M
 php-fpm            x86_64       7.1.16-1.el7.remi       remi-php71       1.6 M
 php-gd             x86_64       7.1.16-1.el7.remi       remi-php71        74 k
 php-gmp            x86_64       7.1.16-1.el7.remi       remi-php71        66 k
 php-json           x86_64       7.1.16-1.el7.remi       remi-php71        59 k
 php-mbstring       x86_64       7.1.16-1.el7.remi       remi-php71       577 k
 php-mcrypt         x86_64       7.1.16-1.el7.remi       remi-php71        57 k
 php-mysqlnd        x86_64       7.1.16-1.el7.remi       remi-php71       229 k
 php-opcache        x86_64       7.1.16-1.el7.remi       remi-php71       240 k
 php-pdo            x86_64       7.1.16-1.el7.remi       remi-php71       122 k
 php-xml            x86_64       7.1.16-1.el7.remi       remi-php71       208 k

トランザクションの要約
================================================================================

上記以外のパッケージはインストール出来ませんでした。

インストール出来なかったパッケージをインストール

[root@host2 ~]# yum --enablerepo=remi,remi-php71 install php-pear php-pecl-xdebug
・
・
================================================================================
 Package                  アーキテクチャー
                                    バージョン              リポジトリー   容量
================================================================================
インストール中:
 php-pear                 noarch    1:1.10.5-6.el7.remi     remi-php71    356 k
 php-pecl-xdebug          x86_64    2.6.0-1.el7.remi.7.1    remi-php71    226 k
依存性関連でのインストールをします:
 php-fedora-autoloader    noarch    1.0.0-1.el7.remi        remi          8.9 k
 php-process              x86_64    7.1.16-1.el7.remi       remi-php71     76 k

トランザクションの要約
================================================================================
インストール  2 パッケージ (+2 個の依存関係のパッケージ)

再度インストール済みパッケージ確認

自宅サーバー2号機

[root@host2 ~]# rpm -qa | grep php
php-7.1.16-1.el7.remi.x86_64
php-mcrypt-7.1.16-1.el7.remi.x86_64
php-fpm-7.1.16-1.el7.remi.x86_64
php-process-7.1.16-1.el7.remi.x86_64
php-json-7.1.16-1.el7.remi.x86_64
php-mbstring-7.1.16-1.el7.remi.x86_64
php-pecl-xdebug-2.6.0-1.el7.remi.7.1.x86_64
php-mysqlnd-7.1.16-1.el7.remi.x86_64
php-xml-7.1.16-1.el7.remi.x86_64
php-opcache-7.1.16-1.el7.remi.x86_64
php-fedora-autoloader-1.0.0-1.el7.remi.noarch
php-cli-7.1.16-1.el7.remi.x86_64
php-gd-7.1.16-1.el7.remi.x86_64
php-pecl-apcu-5.1.11-1.el7.remi.7.1.x86_64
php-gmp-7.1.16-1.el7.remi.x86_64
php-common-7.1.16-1.el7.remi.x86_64
php-pear-1.10.5-6.el7.remi.noarch
php-pdo-7.1.16-1.el7.remi.x86_64
php-devel-7.1.16-1.el7.remi.x86_64

自宅サーバー3号機

[root@host3 ~]# rpm -qa | grep php
php-pdo-7.1.16-1.el7.remi.x86_64
php-fpm-7.1.16-1.el7.remi.x86_64
php-common-7.1.16-1.el7.remi.x86_64
php-mcrypt-7.1.16-1.el7.remi.x86_64
php-pear-1.10.5-6.el7.remi.noarch
php-json-7.1.16-1.el7.remi.x86_64
php-7.1.16-1.el7.remi.x86_64
php-mbstring-7.1.16-1.el7.remi.x86_64
php-gmp-7.1.16-1.el7.remi.x86_64
php-pecl-xdebug-2.6.0-1.el7.remi.7.1.x86_64
php-cli-7.1.16-1.el7.remi.x86_64
php-devel-7.1.16-1.el7.remi.x86_64
php-gd-7.1.16-1.el7.remi.x86_64
php-process-7.1.16-1.el7.remi.x86_64
php-opcache-7.1.16-1.el7.remi.x86_64
php-fedora-autoloader-1.0.0-1.el7.remi.noarch
php-mysqlnd-7.1.16-1.el7.remi.x86_64
php-xml-7.1.16-1.el7.remi.x86_64

php.iniの設定

[root@host2 ~]# vi /etc/php.ini

# [PHP]ブロック
expose_php = Off ← レスポンスヘッダにPHPのバージョンを表示させない
error_reporting = E_ALL ← 全てのログを出力させる
display_errors = Off ← ブラウザでのエラー表示させない
log_errors = On ← エラーをログに残す
log_errors_max_len = 4096 ← エラーログの長さを設定、念のため大きめに
error_log = "/var/log/php_errors.log" ← エラーログ出力先
default_charset = "UTF-8" ← 文字エンコーディング

#[Date]ブロック
date.timezone = "Asia/Tokyo" ← タイムゾーン

#[mbstring]ブロック
mbstring.language = Japanese ← デフォルト言語
mbstring.internal_encoding = UTF-8 ← 内部文字エンコーディング
mbstring.http_input = auto ← HTTP入力文字エンコーディングのデフォルト
mbstring.detect_order = auto ← 文字エンコーディング検出順序のデフォルト

Webサーバー再起動

[root@host2 ~]# systemctl restart httpd

phpバージョン確認

[root@host2 ~]# php -v                                                                                                          
PHP Warning:  PHP Startup: imagick: Unable to initialize module
Module compiled with module API=20151012
PHP    compiled with module API=20160303
These options need to match
 in Unknown on line 0
PHP 7.1.16 (cli) (built: Mar 28 2018 13:19:29) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2018 Zend Technologies
    with Zend OPcache v7.1.16, Copyright (c) 1999-2018, by Zend Technologies

Imagickをphpで使う

[root@host2 ~]# pecl install imagick

[root@host2 ~]# find / -name imagick.so
/usr/lib64/php/modules/imagick.so

[root@host2 ~]# vi /etc/php.d/imagick.ini
; Enable imagick extension module
extension=imagick.so

[root@host2 ~]# systemctl restart httpd

PHPINFO

phpinfo71.png


今日はここまでです。