PHP is one of the most adopted open source programming language commonly used in the creation of interactive and dynamic web pages. Setting up a PHP development environment is key to testing your applications locally before you can deploy them in the cloud, virtualized environment or using containerization technology. This topic outlines PHP 8.3 environment setup on an Ubuntu Linux system.

In this tutorial we guide you through the installation of PHP 8.3 on Ubuntu and how you can use the command line interface to setup a local programming environment. By the end you will be able to perform PHP dependency management using Composer.

🏆 BESTSELLER

The Ultimate Ubuntu Desktop Handbook

Master Ubuntu like a pro - from beautiful desktop customization to powerful terminal automation. Perfect for developers, system admins, and power users who want total control of their workspace.

Only $15 $30
Get Instant Access →

Prerequisites

For you to follow this tutorial, a local or virtual machine with Ubuntu installed is required. Additionally, you’ll need an administrative access to the machine with decent internet connectivity. You can refer to various Ubuntu OS installation guides available in our website.

Step 1 – Add APT PPA repository

All the installation steps used in this article are performed on the command line. This cane be done from a root user account or another standard user account with permissions to use sudo.

Launch terminal on your Ubuntu system. For Desktop you can use Desktop Environment search function to locate the “Terminal” application. For remote applications an SSH session will drop your right at the terminal (using your client).

Ensure you have the latest versions of deb applications and utilities installed on the system.

sudo apt update && sudo apt upgrade -y
[ -f /var/run/reboot-required ] && sudo reboot -f

Install tools required to configure APT repositories on the system.

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

Next, we install PPA repository with PHP 8.3 packages in it – ppa:ondrej/php

sudo add-apt-repository ppa:ondrej/php

Step 2 – Install PHP 8.3 and extensions

Once the repository is configured, proceed to install PHP 8.3 on Ubuntu system.

sudo apt -y install php8.3

Confirm the installation by checking PHP version.

$ php8.3 -v
PHP 8.3.9 (cli) (built: Jul  5 2024 12:04:09) (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

Other additional PHP extensions can be installed is required. The command syntax is php8.3-<extension_name>

$ sudo apt install php8.3-{cli,pdo,mysql,zip,gd,mbstring,curl,xml,bcmath,common}
Reading package lists... Done
Building dependency tree
Reading state information... Done
Note, selecting 'php8.3-common' instead of 'php8.3-pdo'
php8.3-cli is already the newest version (8.3.9-1+ubuntu20.04.1+deb.sury.org+1).
php8.3-cli set to manually installed.
php8.3-common is already the newest version (8.3.9-1+ubuntu20.04.1+deb.sury.org+1).
php8.3-common set to manually installed.
The following additional packages will be installed:
  fontconfig-config fonts-dejavu-core libfontconfig1 libgd3 libjbig0 libjpeg-turbo8 libjpeg8 libonig5 libtiff5 libwebp6 libx11-6 libx11-data libxau6 libxcb1 libxdmcp6 libxpm4 libzip4
Suggested packages:
  libgd-tools php-pear
The following NEW packages will be installed:
  fontconfig-config fonts-dejavu-core libfontconfig1 libgd3 libjbig0 libjpeg-turbo8 libjpeg8 libonig5 libtiff5 libwebp6 libx11-6 libx11-data libxau6 libxcb1 libxdmcp6 libxpm4 libzip4 php8.3-bcmath
  php8.3-curl php8.3-fpm php8.3-gd php8.3-mbstring php8.3-mysql php8.3-xml php8.3-zip
0 upgraded, 25 newly installed, 0 to remove and 5 not upgraded.
Need to get 5,330 kB of archives.
After this operation, 18.4 MB of additional disk space will be used.
Do you want to continue? [Y/n] y

Some of the plugins that we installed are:

  • cli – command line interpreter. It is used for testing PHP scripts from shell or interactive PHP scripting.
  • mysql – For interacting with MySQL databases
  • zip – Useful when working with compressed files
  • gd – You need it to work with images
  • mbstring – Management of non-ASCII strings
  • curl – For making HTTP requests in PHP
  • xml – Working with XML data
  • bcmath – Working with precision floats
  • common – Documentation, examples, and common modules for PHP

In this section we’ve been able to install PHP and commonly required PHP extensions. In the next section, we look at how to setup PHP dependency management using Composer.

Step 3 – Set up PHP Composer

Composer is a PHP utility for handling dependency management when building applications using PHP and many third party modules. With Composer you declare libraries that the project has dependency on and it will manage its installation and updating.

Download Compose setup script.

php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"

Next run the script to setup composer.phar

$ php composer-setup.php
All settings correct for using Composer
Downloading...

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

Make the script available to all users in the system.

sudo mv composer.phar /usr/local/bin/composer

For use by single logged in user you can copy the script to ~/.local/bin

mv composer.phar ~/.local/bin/composer

Check your Composer version by running:

$ composer --version
Composer version 2.7.7 2024-06-10 22:11:12

When using Compose in your project, you have to initialize for composer.json file creation. This file is used to manage app dependencies and defining project details such as Author and License. See the basic Composer’s autoload functionality.

The command to initialize a project is.

composer init

Generated data will be saved insider the composer.json file.

Step 4 – Test PHP 8.3 installation

We can now create a test PHP script.

tee hello.php<<EOF
<?php
echo 'Hello World from my PHP code';
?>
EOF

Test the script to confirm PHP is able to process it correctly.

php hello.php;echo

If successful you will see the characters within the quotes in your code printed out.

Hello World from my PHP code

Conclusion.

At this point, you should have PHP 8.3 programming environment configured in your local or remote Ubuntu Linux machine and ready to get started. We hope you benefited from our article. Until next time, Cheers!.

LEAVE A REPLY

Please enter your comment!
Please enter your name here