2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Ubuntu 22.04 に PHP 7.4 をインストール

Last updated at Posted at 2023-09-16

参考ページ

How to install PHP 7.4 on Ubuntu 22.04 LTS Jammy Linux

Conoha の VPS で確認しました。

更新

sudo apt update
sudo apt upgrade
sudo apt autoremove

再起動

sudo shutdown -r now

カーネルのバージョン

$ uname -a
Linux **** 5.15.0-83-generic #92-Ubuntu SMP Mon Aug 14 09:30:42 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux

PHP 7.4 のインストール

sudo add-apt-repository ppa:ondrej/php -y
sudo apt install php7.4

次のパッケージも同時にインストールされます。

Apache2 もインストールされます。

The following NEW packages will be installed:
  apache2 apache2-bin apache2-data apache2-utils bzip2 libapache2-mod-php7.4
  libapr1 libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap liblua5.3-0
  mailcap mime-support php-common php7.4 php7.4-cli php7.4-common php7.4-json
  php7.4-opcache php7.4-readline ssl-cert

よく使うライブラリーのインストール

sudo apt install php7.4-mbstring
sudo apt install php7.4-mysql
sudo apt install php7.4-curl
sudo apt install php7.4-xml
sudo apt install php7.4-fpm
sudo apt install php7.4-gd
sudo apt install php7.4-bz2
sudo apt install php7.4-zip

確認

$ php  -v
PHP 7.4.33 (cli) (built: Sep  2 2023 08:03:46) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with Zend OPcache v7.4.33, Copyright (c), by Zend Technologies

ファイアウォールの状態を調べる

sudo systemctl status ufw

実行結果

$ sudo systemctl status ufw
● ufw.service - Uncomplicated firewall
     Loaded: loaded (/lib/systemd/system/ufw.service; enabled; vendor preset: e>
     Active: active (exited) since Sat 2023-09-16 08:47:45 JST; 39min ago
       Docs: man:ufw(8)
   Main PID: 416 (code=exited, status=0/SUCCESS)
        CPU: 72ms

ufw の設定の確認

$ sudo ufw status
Status: active

To                         Action      From
--                         ------      ----
OpenSSH                    ALLOW       Anywhere                  
OpenSSH (v6)               ALLOW       Anywhere (v6)

80番ポートを開ける

$ sudo ufw allow 80
Rule added
Rule added (v6)

確認

$ sudo ufw status
Status: active

To                         Action      From
--                         ------      ----
OpenSSH                    ALLOW       Anywhere                  
80                         ALLOW       Anywhere                  
OpenSSH (v6)               ALLOW       Anywhere (v6)             
80 (v6)                    ALLOW       Anywhere (v6)

ブラウザーでアクセス

image.png

Web で PHP7.4 が使われているかの確認

次のプログラムを、/var/www/html に置く

/var/www/html/test_a002.php
<?php phpinfo();
?>

http://****/test_app2.php にアクセス
image.png

composer のインストール

こちらのページを参考にしました。
composer gives error locally on php v7.4 and ubuntu 22.04

もし、パッケージの composer をインストールしていたら削除します。

sudo apt remove composer

PHP7.4 用の composer のインストール

php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php composer-setup.php
php -r "unlink('composer-setup.php');"
sudo mv composer.phar /usr/bin/composer

確認

$ which composer
/usr/bin/composer

$ composer --version
Composer version 2.6.3 2023-09-15 09:38:21

参考: PHP の複数バージョンを切り替える方法

sudo update-alternatives --config php
$ sudo update-alternatives --config php
There are 3 choices for the alternative php (providing /usr/bin/php).

  Selection    Path                  Priority   Status
------------------------------------------------------------
  0            /usr/bin/php.default   100       auto mode
  1            /usr/bin/php.default   100       manual mode
* 2            /usr/bin/php7.4        74        manual mode
  3            /usr/bin/php8.1        81        manual mode

Press <enter> to keep the current choice[*], or type selection number:

Ubuntu 23.10 に PHP7.4 をインストール

こちらに情報があります。
How to Install PHP 7.4 on Ubuntu 23.10

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?