2.PHP8.2のインストールと設定

PHP7.4のインストールと設定
PHP7.4のインストールと設定

bookwormの標準リポジトリから、PHP8.2をインストールします。

PHP8.2のインストール

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

ほっぺ
ほっぺ

busterの時代は、PHP7.4だったのですが、bookwormにはPHP8.2が入っています。

$ sudo apt-get -y install php8.2
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
  libapache2-mod-php8.2 php-common php8.2-cli php8.2-common php8.2-opcache php8.2-readline
Suggested packages:
  php-pear
The following NEW packages will be installed:
  libapache2-mod-php8.2 php-common php8.2 php8.2-cli php8.2-common php8.2-opcache php8.2-readline
0 upgraded, 7 newly installed, 0 to remove and 0 not upgraded.
Need to get 4,250 kB of archives.
After this operation, 22.5 MB of additional disk space will be used.
Get:1 http://deb.debian.org/debian bookworm/main arm64 php-common all 2:93 [13.1 kB]
Get:2 http://deb.debian.org/debian bookworm/main arm64 php8.2-common arm64 8.2.7-1~deb12u1 [642 kB]
Get:3 http://deb.debian.org/debian bookworm/main arm64 php8.2-opcache arm64 8.2.7-1~deb12u1 [492 kB]
Get:4 http://deb.debian.org/debian bookworm/main arm64 php8.2-readline arm64 8.2.7-1~deb12u1 [11.9 kB]
Get:5 http://deb.debian.org/debian bookworm/main arm64 php8.2-cli arm64 8.2.7-1~deb12u1 [1,562 kB]
Get:6 http://deb.debian.org/debian bookworm/main arm64 libapache2-mod-php8.2 arm64 8.2.7-1~deb12u1 [1,501 kB]
Get:7 http://deb.debian.org/debian bookworm/main arm64 php8.2 all 8.2.7-1~deb12u1 [28.2 kB]
Fetched 4,250 kB in 1s (3,193 kB/s)
Selecting previously unselected package php-common.
(Reading database ... 77286 files and directories currently installed.)
Preparing to unpack .../0-php-common_2%3a93_all.deb ...
Unpacking php-common (2:93) ...
・
・
・

インストールされたPHPは

$ php -v
PHP 8.2.7 (cli) (built: Jun  9 2023 19:37:27) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.2.7, Copyright (c) Zend Technologies
    with Zend OPcache v8.2.7, Copyright (c), by Zend Technologies

とか

$ sudo apt install apt-show-versions php
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
apt-show-versions is already the newest version (0.22.13+nmu1).
php is already the newest version (2:8.2+93).
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

で確認できます。

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

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

$  sudo apt-get -y install php8.2-curl php8.2-mbstring php8.2-mysql php8.2-imagick php8.2-xml php8.2-zip php8.2-intl
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
  fonts-droid-fallback fonts-noto-mono fonts-urw-base35 ghostscript gsfonts imagemagick-6-common libavahi-client3 libcups2 libfftw3-double3 libfontenc1 libgs-common libgs10 libgs10-common libice6 libidn12 libijs-0.35
  libjbig2dec0 liblcms2-2 liblqr-1-0 libltdl7 libmagickcore-6.q16-6 libmagickwand-6.q16-6 libonig5 libopenjp2-7 libpaper-utils libpaper1 libsm6 libwebpdemux2 libwebpmux3 libxslt1.1 libxt6 libzip4 poppler-data x11-common
  xfonts-encodings xfonts-utils
Suggested packages:
  fonts-noto fonts-freefont-otf | fonts-freefont-ttf fonts-texgyre 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:
  fonts-droid-fallback fonts-noto-mono fonts-urw-base35 ghostscript gsfonts imagemagick-6-common libavahi-client3 libcups2 libfftw3-double3 libfontenc1 libgs-common libgs10 libgs10-common libice6 libidn12 libijs-0.35
  libjbig2dec0 liblcms2-2 liblqr-1-0 libltdl7 libmagickcore-6.q16-6 libmagickwand-6.q16-6 libonig5 libopenjp2-7 libpaper-utils libpaper1 libsm6 libwebpdemux2 libwebpmux3 libxslt1.1 libxt6 libzip4 php8.2-curl php8.2-imagick
  php8.2-intl php8.2-mbstring php8.2-mysql php8.2-xml php8.2-zip poppler-data x11-common xfonts-encodings xfonts-utils
0 upgraded, 43 newly installed, 0 to remove and 0 not upgraded.
Need to get 24.1 MB of archives.
After this operation, 89.1 MB of additional disk space will be used.
Get:1 http://deb.debian.org/debian bookworm/main arm64 fonts-droid-fallback all 1:6.0.1r16-1.1 [1,807 kB]
Get:2 http://deb.debian.org/debian bookworm/main arm64 libfftw3-double3 arm64 3.3.10-1 [326 kB]
Get:3 http://deb.debian.org/debian bookworm/main arm64 liblcms2-2 arm64 2.14-2 [143 kB]
Get:4 http://deb.debian.org/debian bookworm/main arm64 liblqr-1-0 arm64 0.4.2-2.1 [23.9 kB]
Get:5 http://deb.debian.org/debian bookworm/main arm64 libltdl7 arm64 2.4.7-5 [392 kB]
Get:6 http://deb.debian.org/debian bookworm/main arm64 libopenjp2-7 arm64 2.5.0-2 [175 kB]
Get:7 http://deb.debian.org/debian bookworm/main arm64 libwebpdemux2 arm64 1.2.4-0.2+deb12u1 [99.3 kB]
Get:8 http://deb.debian.org/debian bookworm/main arm64 libwebpmux3 arm64 1.2.4-0.2+deb12u1 [109 kB]
Get:9 http://deb.debian.org/debian bookworm/main arm64 imagemagick-6-common all 8:6.9.11.60+dfsg-1.6 [165 kB]
Get:10 http://deb.debian.org/debian bookworm/main arm64 libmagickcore-6.q16-6 arm64 8:6.9.11.60+dfsg-1.6 [1,585 kB]
Get:11 http://deb.debian.org/debian bookworm/main arm64 libmagickwand-6.q16-6 arm64 8:6.9.11.60+dfsg-1.6 [348 kB]
Get:12 http://deb.debian.org/debian bookworm/main arm64 php8.2-imagick arm64 3.7.0-4 [89.0 kB]
Get:13 http://deb.debian.org/debian bookworm/main arm64 poppler-data all 0.4.12-1 [1,601 kB]
Get:14 http://deb.debian.org/debian bookworm/main arm64 fonts-noto-mono all 20201225-1 [402 kB]
Get:15 http://deb.debian.org/debian bookworm/main arm64 libfontenc1 arm64 1:1.1.4-1 [23.6 kB]
Get:16 http://deb.debian.org/debian bookworm/main arm64 x11-common all 1:7.7+23 [252 kB]
Get:17 http://deb.debian.org/debian bookworm/main arm64 xfonts-encodings all 1:1.0.4-2.2 [577 kB]
Get:18 http://deb.debian.org/debian bookworm/main arm64 xfonts-utils arm64 1:7.7+6 [85.6 kB]
Get:19 http://deb.debian.org/debian bookworm/main arm64 fonts-urw-base35 all 20200910-7 [10.8 MB]
Get:20 http://deb.debian.org/debian bookworm/main arm64 libgs-common all 10.0.0~dfsg-11+deb12u2 [148 kB]
Get:21 http://deb.debian.org/debian bookworm/main arm64 libgs10-common all 10.0.0~dfsg-11+deb12u2 [586 kB]
Get:22 http://deb.debian.org/debian bookworm/main arm64 libavahi-client3 arm64 0.8-10 [43.8 kB]
Get:23 http://deb.debian.org/debian bookworm/main arm64 libcups2 arm64 2.4.2-3+deb12u4 [228 kB]
Get:24 http://deb.debian.org/debian bookworm/main arm64 libidn12 arm64 1.41-1 [82.8 kB]
Get:25 http://deb.debian.org/debian bookworm/main arm64 libijs-0.35 arm64 0.35-15 [15.8 kB]
Get:26 http://deb.debian.org/debian bookworm/main arm64 libjbig2dec0 arm64 0.19-3 [62.8 kB]
Get:27 http://deb.debian.org/debian bookworm/main arm64 libpaper1 arm64 1.1.29 [12.6 kB]
Get:28 http://deb.debian.org/debian bookworm/main arm64 libice6 arm64 2:1.0.10-1 [55.6 kB]
Get:29 http://deb.debian.org/debian bookworm/main arm64 libsm6 arm64 2:1.2.3-1 [34.0 kB]
Get:30 http://deb.debian.org/debian bookworm/main arm64 libxt6 arm64 1:1.2.1-1.1 [172 kB]
Get:31 http://deb.debian.org/debian bookworm/main arm64 libgs10 arm64 10.0.0~dfsg-11+deb12u2 [2,253 kB]
Get:32 http://deb.debian.org/debian bookworm/main arm64 ghostscript arm64 10.0.0~dfsg-11+deb12u2 [57.0 kB]
Get:33 http://deb.debian.org/debian bookworm/main arm64 gsfonts all 2:20200910-7 [18.5 kB]
Get:34 http://deb.debian.org/debian bookworm/main arm64 libonig5 arm64 6.9.8-1 [179 kB]
Get:35 http://deb.debian.org/debian bookworm/main arm64 libpaper-utils arm64 1.1.29 [8,776 B]
Get:36 http://deb.debian.org/debian bookworm/main arm64 libxslt1.1 arm64 1.1.35-1 [231 kB]
Get:37 http://deb.debian.org/debian bookworm/main arm64 libzip4 arm64 1.7.3-1+b1 [53.2 kB]
Get:38 http://deb.debian.org/debian bookworm/main arm64 php8.2-curl arm64 8.2.7-1~deb12u1 [33.7 kB]
Get:39 http://deb.debian.org/debian bookworm/main arm64 php8.2-intl arm64 8.2.7-1~deb12u1 [130 kB]
Get:40 http://deb.debian.org/debian bookworm/main arm64 php8.2-mbstring arm64 8.2.7-1~deb12u1 [430 kB]
Get:41 http://deb.debian.org/debian bookworm/main arm64 php8.2-mysql arm64 8.2.7-1~deb12u1 [108 kB]
Get:42 http://deb.debian.org/debian bookworm/main arm64 php8.2-xml arm64 8.2.7-1~deb12u1 [97.6 kB]
Get:43 http://deb.debian.org/debian bookworm/main arm64 php8.2-zip arm64 8.2.7-1~deb12u1 [24.6 kB]
Fetched 24.1 MB in 2s (10.6 MB/s)
Extracting templates from packages: 100%
Preconfiguring packages ...
・
・
・

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

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

ほっぺ
ほっぺ

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

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

ももぶろ
ももぶろ

忘れないでね。

$  sudo apt-get install php8.2-fpm
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Suggested packages:
  php-pear
The following NEW packages will be installed:
  php8.2-fpm
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 1,573 kB of archives.
After this operation, 5,692 kB of additional disk space will be used.
Get:1 http://deb.debian.org/debian bookworm/main arm64 php8.2-fpm arm64 8.2.7-1~deb12u1 [1,573 kB]
Fetched 1,573 kB in 2s (953 kB/s)
Selecting previously unselected package php8.2-fpm.
(Reading database ... 79198 files and directories currently installed.)
Preparing to unpack .../php8.2-fpm_8.2.7-1~deb12u1_arm64.deb ...
Unpacking php8.2-fpm (8.2.7-1~deb12u1) ...
Setting up php8.2-fpm (8.2.7-1~deb12u1) ...

Creating config file /etc/php/8.2/fpm/php.ini with new version
NOTICE: Not enabling PHP 8.2 FPM by default.
NOTICE: To enable PHP 8.2 FPM in Apache2 do:
NOTICE: a2enmod proxy_fcgi setenvif
NOTICE: a2enconf php8.2-fpm
NOTICE: You are seeing this message because you have apache2 package installed.
Created symlink /etc/systemd/system/multi-user.target.wants/php8.2-fpm.service → /lib/systemd/system/php8.2-fpm.service.
Processing triggers for man-db (2.11.2-2) ...
Processing triggers for php8.2-fpm (8.2.7-1~deb12u1) ...
NOTICE: Not enabling PHP 8.2 FPM by default.
NOTICE: To enable PHP 8.2 FPM in Apache2 do:
NOTICE: a2enmod proxy_fcgi setenvif
NOTICE: a2enconf php8.2-fpm
NOTICE: You are seeing this message because you have apache2 package installed. package installed.

PHPの設定

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

$ sudo vi /etc/php/8.2/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 = 40M

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

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

Apache2の再起動

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

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

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

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