PHP7.4のインストール【Amazon Linux 2】

Amazon Linux 2のamazon-linux-extrasはPHP7.3までなので、php7.4はremi-php74を使用して通常通りにインストールします。

1. PHPのインストール

(1) リポジトリのインストール
「epel」、「remi」のリポジトリをインストールする方法は、yumのリポジトリの追加登録方法【Amazon Linux 2】を参照して下さい。

(2) phpのインストール
yumでインストールを行います。
# yum install --enablerepo=epel,remi,remi-php74 php74

(3) php-develのインストール
※php-develのインストールは任意です。
# yum install --enablerepo=epel,remi,remi-php74 php74-devel

2. 関連モジュールのインストール

(1) libmcryptのインストール
# yum install --enablerepo=epel libmcrypt

(2) libargon2のインストール
php-pdoをインストールする場合に必要です。
# yum install --enablerepo=epel libargon2
# yum install --enablerepo=epel libargon2-devel

3. phpのモジュールのインストール

これは任意ですが、必要なモジュールをインストールします。
# yum install --enablerepo=remi,remi-php73 php-mysqlnd
# yum install --enablerepo=remi,remi-php73 php-mbstring
# yum install --enablerepo=remi,remi-php73 php-gd
# yum install --enablerepo=remi,remi-php73 php-xml
# yum install --enablerepo=remi,remi-php73 php-xmlrpc
# yum install --enablerepo=remi,remi-php73 php-pecl-mcrypt
# yum install --enablerepo=remi,remi-php73 php-fpm
# yum install --enablerepo=remi,remi-php73 php-opcache
# yum install --enablerepo=remi,remi-php73 php-apcu
# yum install --enablerepo=remi,remi-php73 php-zip
# yum install --enablerepo=remi,remi-php73 php-pdo
# yum install --enablerepo=remi,remi-php73 php-pear

4. /etc/php.iniの編集

(1) エラーログファイルの作成
「/var/log/httpd/php_errors.log」というファイルを作成しておきます。
# touch /var/log/httpd/php_errors.log
# chmod 777 /var/log/httpd/php_errors.log

(2) php.iniの編集
# vi /etc/php.ini

expose_php = Off
max_execution_time = 60
error_reporting = E_ALL & ~E_NOTICE & ~E_DEPRECATED & ~E_STRICT
error_log = /var/log/httpd/php_errors.log

post_max_size = 20M
upload_max_filesize = 20M
date.timezone = "Asia/Tokyo"
session.gc_maxlifetime = 3600
mbstring.language = Japanese
mbstring.internal_encoding = UTF-8
mbstring.http_input = pass
mbstring.http_output = pass

(2) pearモジュールのインストール
必要に応じて、PEARのモジュールをインストールします。
【例】PEAR Mailモジュールのインストール。
# pear install -a Mail
※「-a」オプションを付けると、依存ファイルもすべてインストールします。

(3) Apacheの再起動
Apacheを再起動して、PHPを有効にします。
# systemctl restart httpd.service

5. php-fpmサービスの起動

# systemctl enable php-fpm.service
# systemctl start php-fpm.service



最終更新:2020年02月10日 17:36