2.PHP7.4のインストールと設定(Buster32bit)

Raspberry Pi OS Lite(32bit) buster時代の記事

Raspberry Pi OSがBuster(32bit)の時代に作成したものですが、当時のノウハウを残すために置いているページです。最新の記事は、ここを参照ください。

WordPressが推奨するPHPのバージョンが7.4です。

Raspberry Pi OSのaptリポジトリには 7.3までしかないので、 SURY PPAリポジトリからインストールします。

PHP8もリリースが進んでいますが、危険なバージョンなので、WordPressが推奨するまでは使用しません。

SURY PPAリポジトリのPHPを追加

SURY PPAリポジトリを使用するため必要なパッケージをインストールします。

ももぶろ
ももぶろ

既にインストール済みの人はこの作業は不要です。

$ sudo apt install lsb-release apt-transport-https ca-certificates
Reading package lists... Done
Building dependency tree
Reading state information... Done
ca-certificates is already the newest version (20200601~deb10u2).
lsb-release is already the newest version (10.2019051400+rpi1).
lsb-release set to manually installed.
The following NEW packages will be installed:
  apt-transport-https
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 149 kB of archives.
After this operation, 156 kB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://ftp.tsukuba.wide.ad.jp/Linux/raspbian/raspbian buster/main armhf apt-transport-https all 1.8.2.3 [149 kB]
Fetched 149 kB in 1s (190 kB/s)
Selecting previously unselected package apt-transport-https.
(Reading database ... 42262 files and directories currently installed.)
Preparing to unpack .../apt-transport-https_1.8.2.3_all.deb ...
Unpacking apt-transport-https (1.8.2.3) ...
Setting up apt-transport-https (1.8.2.3) ...

PHPのGPGキーを取得します。

$ sudo wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg
--2021-09-12 06:50:29--  https://packages.sury.org/php/apt.gpg
Resolving packages.sury.org (packages.sury.org)... 172.67.182.150, 104.21.18.148, 2606:4700:3037::6815:1294, ...
Connecting to packages.sury.org (packages.sury.org)|172.67.182.150|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1769 (1.7K) [application/octet-stream]
Saving to: ‘/etc/apt/trusted.gpg.d/php.gpg’

/etc/apt/trusted.gpg.d/php.gpg          100%[==============================================================================>]   1.73K  --.-KB/s    in 0.001s

2021-09-12 06:50:30 (2.80 MB/s) - ‘/etc/apt/trusted.gpg.d/php.gpg’ saved [1769/1769]

SURY PPAリポジトリ のPHPをaptリポジトリに追加します。

$ echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" | sudo tee /etc/apt/sources.list.d/php.list
deb https://packages.sury.org/php/ buster main

パッケージ一覧をアップデートをします。

$ sudo apt-get update
Hit:1 http://archive.raspberrypi.org/debian buster InRelease
Hit:2 https://packages.sury.org/apache2 buster InRelease
Get:3 https://packages.sury.org/php buster InRelease [6,837 B]
Get:4 https://packages.sury.org/php buster/main armhf Packages [328 kB]
Get:5 http://raspbian.raspberrypi.org/raspbian buster InRelease [15.0 kB]
Fetched 350 kB in 6s (55.9 kB/s)
Reading package lists... Done

インストールできるPHPのバージョンを確認します。

7.4.23の最新です。

$ apt show php7.4
Package: php7.4
Version: 7.4.23-1+0~20210826.50+debian10~1.gbpb41c6a
Priority: optional
Section: php
Maintainer: Debian PHP Maintainers <team+pkg-php@tracker.debian.org>
Installed-Size: 84.0 kB
Provides: php
Depends: libapache2-mod-php7.4 | php7.4-fpm | php7.4-cgi, php7.4-common
Homepage: http://www.php.net/
Download-Size: 48.2 kB
APT-Sources: https://packages.sury.org/php buster/main armhf Packages
・
・  以降省略
・

パッケージの更新を行います。

$ sudo apt-get upgrade
Reading package lists... Done
Building dependency tree
Reading state information... Done
Calculating upgrade... Done
The following packages have been kept back:
  libxml2
The following packages will be upgraded:
  libargon2-1 libidn2-0 libpcre2-8-0 libpcre2-posix0 libpcre3 libzstd1
6 upgraded, 0 newly installed, 0 to remove and 1 not upgraded.
Need to get 957 kB of archives.
After this operation, 166 kB disk space will be freed.
Do you want to continue? [Y/n] y    <=y入力
Get:1 https://packages.sury.org/php buster/main armhf libpcre3 armhf 2:8.44-2+0~20210301.9+debian10~1.gbpa278ad [323 kB]
・
・  以降省略
・

PHP7.4のインストール

下記のコマンドでPHP7.4をインストールします。

$ sudo apt-get install php7.4
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
  libapache2-mod-php7.4 libsodium23 php-common php7.4-cli php7.4-common php7.4-json php7.4-opcache php7.4-readline
Suggested packages:
  php-pear
The following NEW packages will be installed:
  libapache2-mod-php7.4 libsodium23 php-common php7.4 php7.4-cli php7.4-common php7.4-json php7.4-opcache php7.4-readline
0 upgraded, 9 newly installed, 0 to remove and 1 not upgraded.
Need to get 3,337 kB of archives.
After this operation, 13.0 MB of additional disk space will be used.
Do you want to continue? [Y/n] y    <=y入力
Get:1 https://packages.sury.org/php buster/main armhf php-common all 2:84+0~20210621.36+debian10~1.gbp28513e [16.5 kB]
・
・  以降省略
・

念のためインストールされたPHPを確認します。

$ php -v
PHP 7.4.23 (cli) (built: Aug 26 2021 16:07:37) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with Zend OPcache v7.4.23, Copyright (c), by Zend Technologies

最新です。

PHPモジュールのインストール

WordPressに必要なモジュールをインストールします。

$ sudo apt-get install php7.4-curl php7.4-json php7.4-mbstring php7.4-mysql php7.4-imagick php7.4-xml php7.4-zip php7.4-intl
Reading package lists... Done
Building dependency tree
Reading state information... Done
php7.4-json is already the newest version (7.4.23-1+0~20210826.50+debian10~1.gbpb41c6a).
php7.4-json set to manually installed.
The following additional packages will be installed:
  fontconfig-config fonts-dejavu-core fonts-droid-fallback fonts-noto-mono ghostscript gsfonts imagemagick-6-common libavahi-client3 libcups2 libcupsfilters1
  libcupsimage2 libde265-0 libfftw3-double3 libfontconfig1 libgs9 libgs9-common libheif1 libijs-0.35 libjbig0 libjbig2dec0 liblcms2-2 liblqr-1-0 libltdl7
  libmagickcore-6.q16-6 libmagickwand-6.q16-6 libonig5 libopenjp2-7 libpaper-utils libpaper1 libtiff5 libwebp6 libwebpmux3 libx265-165 libxslt1.1 libzip4
  poppler-data ttf-dejavu-core
Suggested packages:
  fonts-noto ghostscript-x cups-common libfftw3-bin libfftw3-dev liblcms2-utils libmagickcore-6.q16-6-extra poppler-utils fonts-japanese-mincho
  | fonts-ipafont-mincho fonts-japanese-gothic | fonts-ipafont-gothic fonts-arphic-ukai fonts-arphic-uming fonts-nanum
The following NEW packages will be installed:
  fontconfig-config fonts-dejavu-core fonts-droid-fallback fonts-noto-mono ghostscript gsfonts imagemagick-6-common libavahi-client3 libcups2 libcupsfilters1
  libcupsimage2 libde265-0 libfftw3-double3 libfontconfig1 libgs9 libgs9-common libheif1 libijs-0.35 libjbig0 libjbig2dec0 liblcms2-2 liblqr-1-0 libltdl7
  libmagickcore-6.q16-6 libmagickwand-6.q16-6 libonig5 libopenjp2-7 libpaper-utils libpaper1 libtiff5 libwebp6 libwebpmux3 libx265-165 libxslt1.1 libzip4
  php7.4-curl php7.4-imagick php7.4-mbstring php7.4-mysql php7.4-xml php7.4-zip poppler-data ttf-dejavu-core
0 upgraded, 43 newly installed, 0 to remove and 1 not upgraded.
Need to get 21.8 MB of archives.
After this operation, 70.4 MB of additional disk space will be used.
Do you want to continue? [Y/n] y    <=y入力
Get:1 http://archive.raspberrypi.org/debian buster/main armhf libcupsfilters1 armhf 1.21.6-5+rpt1 [160 kB]
Get:2 https://packages.sury.org/php buster/main armhf php7.4-imagick armhf 3.5.1-1+0~20210825.29+debian10~1.gbp4a47e2 [84.6 kB]
・
・  以降省略
・

※WordPress5.9.1にアップデートした時、php7.4-intlのモジュールが要求されたため追加。(2022/1/26)

Apache2向けにphp-fpmをインストール

FPM(FastCGI Process Manager)と言われるPHPのFastCGI実装をインストールします。

ほっぺ
ほっぺ

要するにPHPを速く動作させます。

インストール時にApache2の設定も変更するので、先にApache2をインストールしておいてください。

ももぶろ
ももぶろ

忘れないでね。

$ sudo apt-get install php7.4-fpm
Reading package lists... Done
Building dependency tree
Reading state information... Done
Suggested packages:
  php-pear
The following NEW packages will be installed:
  php7.4-fpm
0 upgraded, 1 newly installed, 0 to remove and 1 not upgraded.
Need to get 1,204 kB of archives.
After this operation, 2,787 kB of additional disk space will be used.
Get:1 https://packages.sury.org/php buster/main armhf php7.4-fpm armhf 7.4.23-1+0~20210826.50+debian10~1.gbpb41c6a [1,204 kB]
Fetched 1,204 kB in 3s (458 kB/s)
・
・  以降省略
・

PHPの設定

日本語処理と動画アップロードの設定をします。

$ sudo vi /etc/php/7.4/apache2/php.ini
ももぶろ
ももぶろ

viの超簡単な使い方は、ここを見てね

ファイルの中に既に定義されている行のコメントを外したり、値を変えたりします。

・
・  手前省略
・
[mbstring]
; language for internal character representation.
; This affects mb_send_mail() and mbstring.detect_order.
; http://php.net/mbstring.language
mbstring.language = Japanese      <=行頭の;を削除して有効化
・
・  以降省略
・
memory_limit = 128M
post_max_size = 40M
upload_max_filesize = 30M

動画は最大30MBまでアップロードできるようにします。

もっと大きなファイルをアップロードする場合は値を変更してください。

Apache2の再起動

PHP.iniを変更したので、Apache2を再起動します。

$ sudo systemctl restart apache2.service
ももぶろ
ももぶろ

PHPのインストールはこれで終わりです。

タイトルとURLをコピーしました