Ubuntu

How to Install PHP 8.0 in Ubuntu 22.04

There are many programming languages that are used for web development, PHP is one of them which is being used on the server-side, moreover, PHP is a scripting language that is used for dynamic websites and database management. PHP is fast and can be easily interfaced with databases like MySQL, Postgresql, and Informix.

In this article, we are going to discover the method of installing the PHP scripting language on Ubuntu.

How to install PHP on Ubuntu 22.04

For the installation of the PHP on Ubuntu, we will add the PPA repository of the PHP on Ubuntu by using the add-apt-repository command:

$ sudo add-apt-repository ppa:ondrej/php

When the PPA repository of the PHP is being added, we will refresh the packages of the Ubuntu to add the PPA repository in the list:

$ sudo apt update

Four packages are available to get an upgrade, so first we will upgrade them:

$ sudo apt upgrade -y

Now we will install the PHP 8.1 using the apt package manager:

$ sudo apt install php8.1 -y

To confirm the installation of the PHP, we will check the version of installed PHP:

$ php --version

Now to run the PHP, we have to install web server like Apache or Nginx, in this article, we will install and use the Apache2 server:

$ sudo apt install apache2 -y

To check the status of the apache2 service, will run the command:

$ sudo systemctl status apache2

The service of the Apache2 is in running condition, now we will install the extensions of the PHP 8.1 using the apt package manager:

$ 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

In the above command, common and necessary extensions have been installed, you can install it according to your wish, for the purpose, we can display all the extensions:

$ php -m

After the installation of the extensions, we will configure the PHP, for this purpose, we will make some changes in the php.ini file using the nano text editor, you can choose any other text editor as well for example, vim:

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

In the opened file, make sure the following changes which are mentioned below:

upload_max_filesize = 32M

post_max_size = 48M

memory_limit = 256M

max_execution_time = 600

max_input_vars = 3000

max_input_time = 1000

After making the configuration changes, restart the Apache server:

$ sudo systemctl restart apache2

If you want to install the development tools for the PHP, use the command:

$ sudo apt install php8.1-dev

Similar to the development tools, we can install the debugging tools as well by running the command:

$ sudo apt install php8.1-xdebug php8.1-pcov

To remove the php from the Ubuntu, we will use the purge command to remove the PHP along with its all packages:

$ sudo apt purge php8.1 -y

Conclusion

PHP is one the most popular scripting languages used to create dynamic websites, moreover, most of the e-commerce websites are using PHP which can easily be embedded with the HTML. In this write-up, the PHP installation method has been discussed by installing the PHP 8.1 release on Ubuntu 22.04.

About the author

Hammad Zahid

I'm an Engineering graduate and my passion for IT has brought me to Linux. Now here I'm learning and sharing my knowledge with the world.