How to Install PHP 8.x on Ubuntu 22.04

PHP is a general-purpose scripting language geared toward web development. It was originally created by Danish-Canadian programmer Rasmus Lerdorf in 1994. The PHP reference implementation is now produced by The PHP Group

In this tutorial, i am going to show you how to install and configure PHP 8.x on ubuntu 22.04 machine.

How to Install PHP 8.x on Ubuntu 22.04

Follow the below given steps to install and configure PHP 8.x on ubuntu 22.04 machine:

Step 1 – Update System Dependencies
Step 2 – Add PHP PPA
Step 3 – Install PHP 8.x for Apache
Step 4 – Install PHP 8.x Extensions
Step 5 – Verify PHP Version
Step 6 – Configure PHP 8.x

Step 1 – Update System Dependencies

Open command line and run the following command on command line to update latest packages or dependencies on ubuntu 22.04 machine:

sudo apt update
sudo apt upgrade

Step 2 – Add PHP PPA

This is an optional setup if you wish to install PHP 8.1. But you are about to install any lower versions of PHP versions like 7.4 you need to add this PPA.

sudo apt install software-properties-common
sudo add-apt-repository ppa:ondrej/php
sudo apt update

Only add this if you are about to install a PHP version other than version 8.1.

Step 3 – Install PHP 8.x for Apache

Run the following command on command prompt to install PHP 8.1:

sudo apt install php8.1

Once the installation has been done, you can confirm the installation using the following command:

php -v

Step 4 – Install PHP 8.x Extensions

Run the following command, you can install PHP extensions:

sudo apt install php8.1-extension_name

Now, install some commonly used php-extensions with the following command.

sudo apt install php8.1-common php8.1-mysql php8.1-xml php8.1-xmlrpc php8.1-curl php8.1-gd php8.1-imagick php8.1-cli php8.1-dev php8.1-imap php8.1-mbstring php8.1-opcache php8.1-soap php8.1-zip php8.1-redis php8.1-intl -y

Step 5 – Verify PHP Version

Run the following command, you can easily verify PHP version:

php -v
Output
PHP 8.1.5 (cli) (built: Apr 21 2022 10:32:13) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.1.5, Copyright (c) Zend Technologies
    with Zend OPcache v8.1.5, Copyright (c), by Zend Technologies

Step 6 – Configure PHP 8.x

Once the php installation has been done , Now you configure PHP for Web Applications by modifying some values in php.ini file.

So, run the following command on command prompt to edit php.ini:

sudo nano /etc/php/8.1/apache2/php.ini

Hit F6 for search inside the editor and update the following values for better performance.

upload_max_filesize = 32M 
post_max_size = 48M
memory_limit = 256M
max_execution_time = 600
max_input_vars = 3000
max_input_time = 1000

Then run the following command on command prompt to restart apache web server:

sudo service apache2 restart

Conclusion

Through this tutorial, i have shown to you how to install PHP 8.1 on your Ubuntu 22.04 server for Apache.

Be First to Comment

Leave a Reply

Your email address will not be published.