Installing PHP on Ubuntu 22.04
Thank to: https://tecadmin.net/
HP is a programming language used for developing web applications. You must install PHP packages on a Ubuntu system to run the application written on it. Generally, it is used to create e-commerce websites, blogs, and API applications. If you’re looking for an easy way to install PHP on Ubuntu 22.04, look no further. In this blog post, we’ll show you how to do it quickly and easily.
We will use the Ondrej PPA for installing PHP on Ubuntu 22.04 LTS system. Which contains PHP 8.1, 8.0, 7.4, 7.3, 7.2. 7.1, 7.0 & PHP 5.6 packages. You can install any of the versions as required for your application. The new application developers are suggested to use the latest PHP version ie PHP 8.1.
In this tutorial, you will learn how to install PHP on Ubuntu 22.04 LTS system. This tutorial is also compatible with Ubuntu 20.04, and 18.04 systems.
Before We Begin
First, login to the Ubuntu 22.04 via console. Then update the Apt cache and upgrade the current packages of system using the following command:
When prompted, press ‘y’ to confirm the installation.
Installing PHP on Ubuntu 22.04
PHP installation on Ubuntu systems is pretty straightforward. You just need to add the required PPA and you can install any PHP version on the Ubuntu system.
Follow these steps to complete PHP installation on Ubuntu:
- Install few dependencies required by this tutorial with the below-mentioned command:
- Add the Ondrej PPA to your system, which contains all versions of PHP packages for the Ubuntu systems.
- Now, update the Apt package manager cache.
- The SURY repository contains PHP 8.1, 8.0, 7.4, 7.3, 7.2. 7.1, 7.0 & PHP 5.6. As the latest stable version of PHP is 8.0, but a large number of websites still required PHP 7. You can install any of the required PHP versions on your system.
- Install PHP 8.1:
- Install PHP 7.4:
- Install PHP 5.6 (EOL):
Replace version 8.1, 7.4, or 5.6 with the required PHP version to install on Ubuntu. Even you can install multiple PHP versions on a single Ubuntu system.
- Some applications required other PHP extensions, that can also be added using below-mentioned syntax:
Replace [extension] with the extension you want to install, if you want to add multiple extensions then include them in braces, I am going to install “php-mbstring, php-mysql, php-xml, and php-curl” by running the below-mentioned command:
Users have installed different PHP version, need to replace
8.1
with required PHP versions.
Check Active PHP Version
Now after installation verify that the correct version of PHP is installed by checking the version number by the below-mentioned command:
About PHP Configuration Files
Configuration files are stored under a directory with version number under /etc/php directory. For example PHP 8.1 configuration files located as below:
- Main PHP configuration file location:
- PHP CLI: /etc/php/8.1/cli/php.ini
- Apache: /etc/php/8.1/apache2/php.ini
- PHP FPM: /etc/php/8.1/fpm/php.ini
- All the installed PHP modules are stored under /etc/php/8.1/mods-available directory.
- PHP Active modules configuration directory location:
- PHP CLI: /etc/php/8.1/cli/conf.d/
- Apache: /etc/php/8.1/apache2/conf.d/
- PHP FPM: /etc/php/8.1/fpm/conf.d/
To check files for the other PHP versions, just change the PHP version number (8.1 in the above example) in the files and directory path.
Switch Default PHP Version for CLI
You can use update-alternatives command to set the default PHP version. Use this tutorial to read more details about switching PHP version for CLI and Apache.
The above output shows all the installed PHP versions on your system. Selection number 2 set PHP 7.4 as the default PHP version for the command line.
Uninstalling PHP
If any PHP version is no more required, can be removed from the system. That will free the disk space as well as system security.
To uninstall any PHP version just type:
Also uninstall all the modules for that version with the following command:
Conclusion
This tutorial provides you with the instructions to install PHP on Ubuntu 22.04. The Ondrej PPA allows us to quickly install PHP on Ubuntu systems. It also allows us to install multiple PHP versions on a single system. You can switch to any PHP version as default anytime with the update-alternative utility.
Comentarios
Publicar un comentario
Dime si la información de este blog te sirvio.