PHP (Hypertext Preprocessor) is a widely used open-source scripting language that is particularly well-suited for web development and can be embedded into HTML. With the release of PHP 8.3, developers gain access to new features, performance enhancements, and bug fixes that can significantly improve their web applications. However, upgrading PHP on your Ubuntu 22.04 server requires careful attention to ensure a smooth transition.

In this guide, we’ll walk you through the process of installing PHP 8.3 on Ubuntu 22.04.

Step 1 – Add PHP Repository

To install PHP 8.3 on Ubuntu 22.04, you’ll need to add a repository containing PHP 8.3 packages and install PHP along with any necessary extensions.

First, install all the necessary dependencies:

apt install curl gpg gnupg2 software-properties-common ca-certificates apt-transport-https lsb-release -y

Ondřej Surý maintains a repository with updated PHP versions for Ubuntu. Add this repository to your system:

add-apt-repository ppa:ondrej/php

Update the package index.

apt update -uy

Step 2 – Install PHP8.3

Now, you can install the PHP8.3 using the following command:

apt -y install php8.3

After successful installation, you can verify the PHP version using the following command:

php --version

Output:

PHP 8.3.4 (cli) (built: Mar 16 2024 08:40:08) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.3.4, Copyright (c) Zend Technologies
    with Zend OPcache v8.3.4, Copyright (c), by Zend Technologies

Step 3 – Install Additional PHP Extensions

Depending on your requirements, you may need to install additional PHP extensions. You can install some common PHP extensions using the following command:

apt install php8.3-{cli,pdo,mysql,zip,gd,mbstring,curl,xml,bcmath,common}

You can also install PHP Composer using the following command:

php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php composer-setup.php --install-dir=/usr/local/bin --filename=composer

Output:

All settings correct for using Composer
Downloading...

Composer (version 2.7.2) successfully installed to: /root/composer.phar
Use it: php composer.phar

Next, verify the Composer version using the following command:

composer --version

Output:

Composer version 2.7.2 2024-03-11 17:12:18
PHP version 8.3.4 (/usr/bin/php8.3)
Run the "diagnose" command to get more detailed diagnostics output.

Step 4 – Verify PHP8.3 Installation

To verify that PHP is installed and configured correctly on your Ubuntu 22.04 system, you can create a simple PHP script and then execute it through your web server or the command line.

Create a test.php file.

nano test.php

Add the following code:

<?php
echo 'Hello World!';
?>

Save and close the file.

Now, you have a test.php file containing a PHP script that will display information about your PHP installation.

You can execute the test.php script directly from the command line. Open a terminal and navigate to the directory where test.php is located. Then, run the following command:

php test.php;echo

You will see the following output:

Hello World!

Conclusion

By following the instructions provided in this tutorial, you’ve gained the knowledge and confidence to upgrade your PHP version safely and efficiently. With PHP 8.3, you’ll benefit from enhanced performance, new features, and bug fixes that can help optimize your web applications and improve overall server security. You can now upgrade your PHP version on dedicated server hosting from Atlantic.Net!