Ubuntu 22.10にPHP 8.1 をインストールする

環境
OSのバージョンを確認します

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
# 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 をインストールします

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
# 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のバージョンを確認します

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
# 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.テストスクリプトを作成して動作確認します

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
# 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

実行結果

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
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

 

Ubuntu 22.10

Posted by arkgame