PHP is a versatile server-side scripting language widely used for creating dynamic and interactive web applications. If you're planning to set up a content management system (CMS) like WordPress, Drupal, or Joomla, or if you want to develop your own PHP-based web applications, installing PHP on your Ubuntu 20.04 LTS system is essential. This guide will walk you through the process of installing PHP and verifying the installation on Ubuntu 20.04 LTS.
Installation
Step 1: Update your package list to ensure you have the latest information on available packages and their dependencies.
sudo apt update
Step 2: Install PHP by running the following command. This will install the PHP interpreter, command-line interface, and the necessary libraries.
sudo apt install php
If you require a specific version of PHP, such as PHP 7.3 or PHP 7.4, you can install it by specifying the version number in the package name. These versions are available in the Ubuntu repositories as php7.3
, php7.4
, etc. The PHP interpreter binaries will then be named accordingly, like php7.3
or php7.4
.
sudo apt install php7.3
Note that the php
package always points to the latest stable version of PHP available in the Ubuntu repositories.
Verifying the installation
Step 3: Verify that PHP has been installed successfully by checking its version. Use the following command to display the installed PHP version.
php -v
If you've installed a specific version of PHP, use the corresponding command to check its version. The command format is php<version_number> -v
. For example, to check the version of PHP 7.3, run:
php7.3 -v
That's it! You have successfully installed PHP on your Ubuntu 20.04 LTS system. You can now begin developing PHP applications or set up software that requires PHP, such as WordPress or Drupal.
Keep in mind that the php
package installs only the most commonly used PHP extensions. For development purposes, you may need to install additional libraries manually. These packages typically follow the naming convention php-<extension_name>
, such as php-curl
. To search for available PHP packages and extensions, use the following command:
apt search php
Member discussion