sajad torkamani

Add PPA repository

Ubuntu’s default PPA repositories will probably not include the latest PHP version so you’ll want to add ppa:ondrej/php.

sudo add-apt-repository ppa:ondrej/php
sudo apt-get update

Install PHP packages

Head over to the PHP website to check the current stable version. At the time of writing, this is 8.3.7.

Assuming we’ll use PHP with MySQL, we’ll want to install the following packages.

php_version=8.3 && sudo apt install php$php_version-fpm php$php_version-mysql php$php_version-xml php$php_version-curl

You may need to install more packages with time.

Verify installation

php -v

This should output something like:

PHP 8.3.7 (cli) (built: May 23 2024 12:36:32) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.3.7, Copyright (c) Zend Technologies
with Zend OPcache v8.3.7, Copyright (c), by Zend Technologies

Sources

Tagged: PHP