Ubuntu 22.04 LTSにPHP 8.1 をインストールする方法
環境
OSバージョンを確認します
# cat /etc/lsb-release DISTRIB_ID=Ubuntu DISTRIB_RELEASE=22.04 DISTRIB_CODENAME=jammy DISTRIB_DESCRIPTION="Ubuntu 22.04 LTS"
PHP 8.1のインストール手順
1.PHP 8.1 をインストールします
# apt -y install php8.1 php8.1-mbstring php-pear
2.phpバージョンを確認します
# php -v PHP 8.1.2 (cli) (built: Apr 7 2022 17:46:26) (NTS) Copyright (c) The PHP Group Zend Engine v4.1.2, Copyright (c) Zend Technologies with Zend OPcache v8.1.2, Copyright (c), by Zend Technologies
3.テストスクリプトを作成します
# echo '<?php echo `php -i`."\n"; ?>’ > test.php
# php test.php | head
実行結果
phpinfo() PHP Version => 8.1.2 System => Linux arte-virtual-machine 5.15.0-33-generic #34-Ubuntu SMP Wed May 18 13:34:26 UTC 2022 x86_64 Build Date => Apr 7 2022 17:46:26 Build System => Linux Server API => Command Line Interface Virtual Directory Support => disabled Configuration File (php.ini) Path => /etc/php/8.1/cli Loaded Configuration File => /etc/php/8.1/cli/php.ini