Debian(Ubuntu)にPHP8をインストールする

動作環境

  • OS : Debian11

前提条件

  • 既にApache2がインストールされていること

さぁ、インストールしよう

aptを最新にします。

$ sudo apt update

Hit:1 http://ftp.jaist.ac.jp/debian bullseye InRelease
Get:2 http://ftp.jaist.ac.jp/debian bullseye-updates InRelease [39.4 kB]
Get:3 http://security.debian.org/debian-security bullseye-security InRelease [44.1 kB]
Get:4 http://security.debian.org/debian-security bullseye-security/main Sources [102 kB]
Get:5 http://security.debian.org/debian-security bullseye-security/main amd64 Packages [120 kB]
Get:6 http://security.debian.org/debian-security bullseye-security/main Translation-en [77.0 kB]
Fetched 382 kB in 1s (731 kB/s)                                  
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
All packages are up to date.

PHP8をインストールするまでの事前準備

$ sudo apt install -y lsb-release ca-certificates apt-transport-https software-properties-common gnupg2
$ echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" | sudo tee /etc/apt/sources.list.d/sury-php.list
$ wget -qO - https://packages.sury.org/php/apt.gpg | sudo apt-key add -
  • ここに関しての操作は、このサイトを参考にしました。
  • ホントにうまくいくの?と内心ドキドキしました。

phpをインストールしていきます。

$ sudo apt install -y php8.1
$ sudo apt install -y php8.1-mbstring
$ sudo apt install -y php8.1-gd
$ sudo apt install -y php8.1-mcrypt
$ sudo apt install -y php8.1-pgsql
  • php8.1をインストールした後は、OSをリブートした方が良さそうです。

apache2を再起動しておきます。

$ sudo systemctl restart apache2

最後に

私の環境では、どうやら上述手順でうまくいったようです。 よかった^^