PHP 8.3 on Ubuntu

How to Install PHP 8.3 on Ubuntu 22.04

PHP, which stands for “Hypertext Preprocessor,” is a server-side scripting language widely used for web development. PHP is often used to create dynamic web pages, handle forms, interact with databases, and perform various server-side tasks.

It has been a popular choice for web development for many years, and despite the emergence of other languages and frameworks, it continues to be widely used in the industry.

In this tutorial, we will show you how to install PHP 8.3 on a Ubuntu 22.04 OS.

Update Operating System

Update your Ubuntu 22.04 operating system to make sure all existing packages are up to date:

# apt update && apt upgrade

Add PHP Repository

By default, PHP 8.3 is not included in the Ubuntu 22.04 default repository.  So you will need to add Ondrej Sury PPA into your system.

First, install the required packages using the following command:

# apt-get install ca-certificates apt-transport-https software-properties-common

Once all the packages are installed, add this PPA using the following command:

# add-apt-repository ppa:ondrej/php

Once you are done, update the repository with the following command:

# apt-get update

Install PHP 8.3

Now, you can install the PHP 8.3 using the following command:

# apt-get install php8.3

Once the PHP is installed, you can check the PHP version on your system with the following command:

# php8.3 --version

Output:

# PHP 8.3.0 (cli) (built: Nov 24 2023 08:50:08) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.3.0, Copyright (c) Zend Technologies
    with Zend OPcache v8.3.0, Copyright (c), by Zend Technologies

Install PHP 8.3 for Apache

To install PHP as an Apache module, execute:

# apt install libapache2-mod-php8.3

Then, restart Apache to integrate the new PHP module:

# systemctl restart apache2

Install PHP 8.3 FPM for Nginx

For the Nginx web server, you need to install the FPM service, you can install it using the following command:

# apt install php8.3-fpm

Once the installation has been completed, you can confirm that the PHP-FPM service has been installed correctly with the following command:

# systemctl status php8.3-fpm

Output:

● php8.3-fpm.service - The PHP 8.3 FastCGI Process Manager
     Loaded: loaded (/lib/systemd/system/php8.3-fpm.service; enabled; vendor preset: enabled)
     Active: active (running)
       Docs: man:php-fpm8.3(8)
    Process: 58796 ExecStartPost=/usr/lib/php/php-fpm-socket-helper install /run/php/php-fpm.sock /etc/php/8.3/fpm/pool.d/www.conf 83 (code=exited, status=0>
   Main PID: 58793 (php-fpm8.3)
     Status: "Processes active: 0, idle: 2, Requests: 0, slow: 0, Traffic: 0req/sec"
      Tasks: 3 (limit: 2178)
     Memory: 7.5M
        CPU: 34ms
     CGroup: /system.slice/php8.3-fpm.service
             ├─58793 "php-fpm: master process (/etc/php/8.3/fpm/php-fpm.conf)
├─58794 php-fpm: pool www
└─58795 php-fpm: pool www

Install PHP Extension

Installing PHP extensions are simple with the below-mentioned syntax:

# sudo apt install php8.3-[extension]

Replace [extension] with the extension you want to install, if you want to add multiple extensions then include them in braces:

# apt install php8.3-mysql php8.3-imap php8.3-ldap php8.3-xml php8.3-curl php8.3-mbstring php8.3-zip

To check loaded PHP modules use the command:

# php8.3 -m

Example Output:

[PHP Modules]
..............
fileinfo
filter
ftp
gettext
hash
iconv
imap
json
ldap
libxml
mbstring
mysqli
mysqlnd
..............

[Zend Modules]
Zend OPcache

Running PHP 8.3 with Other Versions

Instead of removing old PHP versions, it is also possible to run multiple PHP versions side-by-side.

The update-alternatives command provides an easy way to switch between PHP versions for PHP CLI.

# update-alternatives --config php

This brings up a prompt to interactively select the alternative PHP binary path that php points to.

There are 2 choices for the alternative php (providing /usr/bin/php).

  Selection    Path             Priority   Status
------------------------------------------------------------
* 0            /usr/bin/php8.3   81        auto mode
  1            /usr/bin/php8.1   81        manual mode
  2            /usr/bin/php8.3   83        manual mode

To set the path without the interactive prompt:

# update-alternatives --set php /usr/bin/php8.1

Comments and Conclusion

In the tutorial, you have learned how to install PHP 8.3 on Ubuntu 22.04.

For additional help or useful information, we recommend you to check the official PHP 8.3 documentation.

If you have any questions please leave a comment below.

2 thoughts on “How to Install PHP 8.3 on Ubuntu 22.04

Leave a Reply

Your email address will not be published. Required fields are marked *