「Nextcloud等のLAMP環境が動くか」を考慮しながらUbuntu 24.04サーバを構築しています。

そこで、php8.3のインストール及びモジュールの追加を行います。

さっくりとした手順

  1. レポジトリを追加します。
  2. php並びに必要なパッケージを段階的にインストールします。
  3. Nextcloud等で必要になるように設定をしていきます。

レポジトリ追加とアップデート

  • phpレポジトリの追加
sudo add-apt-repository ppa:ondrej/php
  • パッケージ全体のアップデート
sudo aptitude update

段階的なインストール

  • php本体
sudo aptitude install php8.3
  • 周辺モジュール(APCuとMemcached)
sudo aptitude memcached php8.3-apcu
  • Webアプリに必要な周辺モジュール(MySQLを使う場合)
sudo aptitude install php8.3-{opcache,pdo,bcmath,calendar,ctype,fileinfo,ftp,gd,intl,json,ldap,mbstring,mysql,posix,readline,sockets,bz2,tokenizer,zip,curl,iconv,phar,xml,dev,imagick,gmp}
  • Webアプリに必要な周辺モジュール(Postgresを使う場合)
sudo aptitude install php8.3-{opcache,pdo,bcmath,calendar,ctype,fileinfo,ftp,gd,intl,json,ldap,mbstring,pgsql,pdo_pgsql,posix,readline,sockets,bz2,tokenizer,zip,curl,iconv,phar,xml,dev,imagick,gmp}
  • インストール確認
php -v
PHP 8.3.11 (cli) (built: Aug 30 2024 09:28:18) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.3.11, Copyright (c) Zend Technologies
    with Zend OPcache v8.3.11, Copyright (c), by Zend Technologies

2024/09/06現在のバージョンです。

OPcacheとAPCuの有効化

Nextcloudはこの設定が無いと警告の対象となります。(或いはエラーが発生します)

  • 設定ファイル待避
sudo mv /etc/php/8.3/mods-available/opcache.ini /path/to/backup/directory/opcache.ini.$(date +%Y%m%d)
sudo mv /etc/php/8.3/mods-available/apcu.ini /path/to/backup/directory/apcu.ini.$(date +%Y%m%d)

任意のバックアップディレクトリを指定します。

  • 設定ファイル差し替え
cat <<- __EOF__ | sudo tee -a /etc/php/8.3/mods-available/opcache.ini
; configuration for php opcache module
; priority=10
zend_extension=opcache.so
opcache.enable=1
opcache.enable_cli=1
opcache.interned_strings_buffer=16
opcache.max_accelerated_files=10000
opcache.memory_consumption=256
opcache.save_comments=1
opcache.revalidate_freq=1
__EOF__
cat <<- __EOF__ | sudo tee -a /etc/php/8.3/mods-available/apcu.ini
extension=apcu.so
[apcu]
apc.enabled=1
apc.shm_size=32M
apc.ttl=7200
apc.enable_cli=1
apc.serializer=php
__EOF__

※ メモリ量などは環境に合わせます。

  • 設定反映
sudo systemctl restart apache2.service
  • Apache稼働確認
systemctl status apache2.service

active (running)を確認します。