PHP

スクリプト言語 PHP について

 

PHP言語一般

 

CentOSでのPHP言語

 

Debian/UbuntuでのPHP言語

 

Debian 9 / 10 にPHP7.4をインストール(アップデイト)

参照: Upgrade/Installation guide for PHP 7.4 on Ubuntu and Debian

現在のインストール済みのPHP環境を確認します。

  • sudo apt list --installed php*

上記の説明を参考に新しいPHP7.4とその追加機能をインストールします。レポジトリは、packages.sury.orgを使用る設定です。

  • sudo apt install php7.4 php7.4-common php7.4-cli
  • sudo apt install php7.4-curl php7.4-mbstring php7.4-bz2 php7.4-readline php7.4-intl
  • sudo apt install php7.4-bcmath php7.4-bz2 php7.4-curl php7.4-intl php7.4-mbstring php7.4-mysql php7.4-readline php7.4-xml php7.4-zip

最後に古いPHP7.3をアンインストールします。

  • apt purge php7.3 php7.3-common

 # Change 7.3 with all versions you want to purge.

 

参照: How to Update to PHP 7.4 for WordPress Site on Debian 9/10

 

Debian 9・10に複数のPHPバージョンをインストール

 レポジトリ SURY をインストールして、PHP7.3、7.4、8.0 などの複数のPHPバージョンをインストールして管理する説明が以下のURLです。

https://www.itzgeek.com/how-tos/linux/debian/how-to-install-php-7-3-7-2-...

PHP拡張モジュールのインストール、WordPressやDrupalの場合の説明

  • WordPress
sudo apt install -y php7.3-mysql php7.3-dom php7.3-simplexml php7.3-ssh2 
php7.3-xml php7.3-xmlreader php7.3-curl  php7.3-exif  php7.3-ftp 
php7.3-gd  php7.3-iconv php7.3-imagick php7.3-json  php7.3-mbstring 
php7.3-posix php7.3-sockets php7.3-tokenizer
  • Drupal
sudo apt install -y php7.3-mysql php7.3-dom php7.3-gd php7.3-json 
php7.3-pdo php7.3-simplexml php7.3-tokenizer php7.3-xml

 

Debian 11 Bulleyes にPHP8.2 FPMをインストール

参考にしたページ : 

Apache2の場合

sudo apt install apache2 php8.2-fpm libapache2-mod-php8.2 libapache2-mod-fcgid

sudo a2enmod php8.2

sudo a2enmod proxy_fcgi setenvif && sudo a2enconf php{version}-fpm

sudo systemctl restart apache2

sudo a2enconf php8.2-fpm 

もし、古いPHP8.1などのPHP-FPMがインストールされている場合は、削除します。

sudo a2disconf php8.1-fpm
sudo apt purge php8.1*

sudo systemctl restart php8.2-fpm

Nginxの場合

sudo apt install nginx php8.2-fpm

編集 /etc/nginx/nginx.conf

server {
    listen 80;
    server_name mysite.example.com;
    root /var/www/mysite;
    index index.php index.html;
    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/var/run/php/php8.2-fpm.sock;
    }
}

Nginx文法のテスト sudo nginx -t

 

Debian12にPHP8.1/8.3をインストール

Debianでは apt-key コマンドが非推奨になっているので、インストール手順が異なります。SURY PHP PPA レポジトリを使います。

参考にしたサイト: PHP 8.1  https://computingforgeeks.com/how-to-install-php-on-debian-linux-2/

参考にしたサイト: PHP8.3  https://tecadmin.net/how-to-install-php-on-debian-12/

 

もし、DEB.SURY.ORG Automatic Signing Key が古いので更新できない場合は、新しいKeyをダウンロードします。

 

もし、以下のapt update エラーが起きた場合

The script will try to autodetect whether any APT repository is not
configured with signed-by= directive and will print warning about the
installation of this package.

You need to manually add:

[signed-by=/usr/share/keyrings/debsuryorg-archive-keyring.gpg]

to your APT sources lists. See the Debian Wiki for more information:

https://wiki.debian.org/DebianRepository/UseThirdParty#Sources.list_entry

gpgを再インストールして、入れ替える作業で対応できました。以下のサイトで suryレポジトリの再設定しました。

参考にしたサイト: PHP 8.1  https://computingforgeeks.com/how-to-install-php-on-debian-linux-2

 

2026年2月 apt-keyの代わりにsigned-byを使ってインストール(参考:https://zenn.dev/ykbone/articles/a6c85350eef102

現状のPHP環境の確認

php -m > current_extensions.txt

dpkg -l | grep php | awk '{print $2}' > current_packages.txt

suryレポジトリの設定

パッケージのインストール

sudo apt update
sudo apt install -y lsb-release ca-certificates apt-transport-https software-properties-common gnupg2 curl

GPGキーのダウンロードと設定

curl -fsSL https://packages.sury.org/php/apt.gpg | sudo gpg --dearmor -o /etc/apt/keyrings/sury-php.gpg

パッケージの更新

sudo apt update

PHP8.3をインストールする場合

sudo apt install -y php8.3 php8.3-cli php8.3-fpm php8.3-mysql php8.3-mbstring php8.3-xml php8.3-curl php8.3-zip php8.3-gd php8.3-intl

PHPバージョン切り替え

php -v 
sudo update-alternatives --set php /usr/bin/php8.3 
もしくは 
sudo update-alternatives --config php

Apache(mod_php)を使っている場合

古いPHPバージョンを無効にして新しいバージョンを有効化

sudo a2dismod php8.2
sudo a2enmod php8.3
sudo systemctl restart apache2

 

 

WindowsでのPHP言語

 

タグ: 

オープンソースソフトウェア: