Install PHP on Ubuntu Linux
Step 1. Install developer packages
sudo apt install software-properties-common
Step 2. Add the PHP repository
sudo add-apt-repository ppa:ondrej/php
Step 3. Install PHP 8.3
This will install PHP and required modules.
sudo apt install php8.3 libapache2-mod-php8.3 php8.3-{mbstring,intl,apcu,opcache,gd,curl,sqlite3,mysql,pgsql}
Step 4. Check It
Check the PHP version.
$ php -v
You will see something like this:
PHP 8.3.9 (cli) (built: Jul 2 2024 14:10:14) (NTS) Copyright (c) The PHP Group Zend Engine v4.3.9, Copyright (c) Zend Technologies with Zend OPcache v8.3.9, Copyright (c), by Zend Technologies
Step 5. Update Apache
You might need to run the following command to enable the Apache module, especially if upgrading PHP from a previous version.
sudo a2enmod php8.3
Great!