Ubuntu 22.10にPHP 8.1 をインストールする
環境
OSのバージョンを確認します
# cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=22.10
DISTRIB_CODENAME=kinetic
DISTRIB_DESCRIPTION="Ubuntu 22.10"
# cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=22.10
DISTRIB_CODENAME=kinetic
DISTRIB_DESCRIPTION="Ubuntu 22.10"
# cat /etc/lsb-release DISTRIB_ID=Ubuntu DISTRIB_RELEASE=22.10 DISTRIB_CODENAME=kinetic DISTRIB_DESCRIPTION="Ubuntu 22.10"
操作方法
1.PHP 8.1 をインストールします
# apt -y install php8.1 php8.1-mbstring php-pear
# apt -y install php8.1 php8.1-mbstring php-pear
# apt -y install php8.1 php8.1-mbstring php-pear
2.phpのバージョンを確認します
# php -v
PHP 8.1.7-1ubuntu3 (cli) (built: Sep 13 2022 14:02:34) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.1.7, Copyright (c) Zend Technologies
with Zend OPcache v8.1.7-1ubuntu3, Copyright (c), by Zend Technologies
# php -v
PHP 8.1.7-1ubuntu3 (cli) (built: Sep 13 2022 14:02:34) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.1.7, Copyright (c) Zend Technologies
with Zend OPcache v8.1.7-1ubuntu3, Copyright (c), by Zend Technologies
# php -v PHP 8.1.7-1ubuntu3 (cli) (built: Sep 13 2022 14:02:34) (NTS) Copyright (c) The PHP Group Zend Engine v4.1.7, Copyright (c) Zend Technologies with Zend OPcache v8.1.7-1ubuntu3, Copyright (c), by Zend Technologies
3.テストスクリプトを作成して動作確認します
# echo '<?php echo `php -i`."\n"; ?>' > php_test.php
# php php_test.php | head
# echo '<?php echo `php -i`."\n"; ?>' > php_test.php
# php php_test.php | head
# echo '<?php echo `php -i`."\n"; ?>' > php_test.php # php php_test.php | head
実行結果
phpinfo()
PHP Version => 8.1.7-1ubuntu3
System => Linux arkgame 5.19.0-23-generic #24-Ubuntu SMP PREEMPT_DYNAMIC Fri Oct 14 15:39:57 UTC 2022 x86_64
Build Date => Sep 13 2022 14:02:34
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
phpinfo()
PHP Version => 8.1.7-1ubuntu3
System => Linux arkgame 5.19.0-23-generic #24-Ubuntu SMP PREEMPT_DYNAMIC Fri Oct 14 15:39:57 UTC 2022 x86_64
Build Date => Sep 13 2022 14:02:34
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
phpinfo() PHP Version => 8.1.7-1ubuntu3 System => Linux arkgame 5.19.0-23-generic #24-Ubuntu SMP PREEMPT_DYNAMIC Fri Oct 14 15:39:57 UTC 2022 x86_64 Build Date => Sep 13 2022 14:02:34 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