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:
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:
Four packages are available to get an upgrade, so first we will upgrade them:
Now we will install the PHP 8.1 using the apt package manager:
To confirm the installation of the PHP, we will check the version of installed PHP:
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:
To check the status of the apache2 service, will run the command:
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:
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:
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:
In the opened file, make sure the following changes which are mentioned below:
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:
If you want to install the development tools for the PHP, use the command:
Similar to the development tools, we can install the debugging tools as well by running the command:
To remove the php from the Ubuntu, we will use the purge command to remove the PHP along with its all packages:
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.