PHP stands for Hypertext Preprocessor, free and open source, server-side scripting language that can also integrate into HTML. PHP language is suitable for dynamic and interactive web development. This is the most common and widely used web programming language in the world. PHP is an interpreted language so, you don't require a compiler to run the PHP program. PHP processing acts as a bridge between the PHP interpreter and the webserver.
Here at LinuxAPT, as part of our Server Management Services, we regularly help our Customer to perform related PHP queries.
In this context, we shall look into PHP installation on Ubuntu 20.04 system.
How to perform PHP installation on Ubuntu 20.04 ?
Before proceeding with this Installation Procedure, ensure that you use a user with sudo privileges to run the administrative commands.
1. Install PHP modules
Update the apt packages of your system and then type the following command on the terminal to install PHP components:
$ sudo apt install php libapache2-mod-php php-mysql
Enter the administrative password and in a while, a prompt interrupt the installation. Press 'y' and then hit the 'Enter' key to continue this process.
After that, all PHP modules to be installed on your system. You can also install the required PHP extension depending on the project requirements.
2. Check installed PHP version
Verify the installation of PHP by running the following command:
$ php --version
The installed PHP version should display on the terminal.
3. Install required PHP extensions
To search for the relevant PHP extension type the following command on the terminal:
$ sudo apt-cache search php | grep php-
The all PHP extensions list displays on the terminal. You can find the relevant PHP extension and install it on your system by using the following syntax:
$ sudo apt install php-[extension-name]
4. Configure PHP
To configure the PHP for your web applications, you need to change certain values in the php.ini configuration file. Type the following command to open the 'php.ini' configuration file:
$ sudo nano /etc/php/7.4/apache2/php.ini
Now, find and change the following values in the configuration file:
# Upload max write = 32 M
# After max size = 48 M
# Speicher limit = 256 M
# Max perform time = 600
# Input vars = 3000
# Input time max = 1000
Once you have changed the PHP configuration settings.
Now, restart the service of the apache server by typing the following command:
$ sudo systemctl restart apache2
5. Test the PHP installation
Now, create a new PHP file in the web directory. Here, we have created a new file with the name 'info.php' by using the following command:
$ sudo nano /var/www/html/info.php
Paste the following PHP code in the above file:
echo "Welcome to PHP installation Tutorial!";
Save this file and open the following URL in your browser:
For example, 127.0.0.1/info.php
This should display the output as shown below:
Welcome to PHP installation Tutorial!
[Need urgent assistance in fixing PHP version errors? We can help you. ]
This article covers the PHP installation on Ubuntu 20.04 system. Basically, popular Content Management platforms such as WordPress, Drupal, and Magento are based on PHP.
To Install PHP on Ubuntu 20.04:
1. Update your server.
$ apt-get update && apt-get upgrade
2. Install PHP on Ubuntu 20.04, just run the following command.
$ apt-get install php
3. To verify if PHP is installed, run the following command.
To Install PHP 7.4 modules (extensions):
Run the command below.
apt-get install php-pear php-fpm php-dev php-zip php-curl php-xmlrpc php-gd php-mysql php-mbstring php-xml libapache2-mod-php
To check all the PHP modules available in Ubuntu, run:
$ apt-cache search --names-only ^php
How to install PHP 8.0 on Ubuntu 20.04 or 18.04 ?
1. First, update your Ubuntu server:
$ apt-get update && apt-get upgrade
2. Add the PHP repository (by Ondřej Surý):
$ apt-get install software-properties-common
$ add-apt-repository ppa:ondrej/php
3. And finally, update your package list:
$ apt-get update
4. Install PHP 8.0 with the following command:
$ apt-get install php8.0
5. To check if PHP 8.0 is installed on your server, run the following command:
$ php -v
6. Install PHP 8.0 modules (extensions)
You may need additional packages and modules depending on your applications. The most commonly used modules can be installed with the following command:
$ apt-get install libapache2-mod-php8.0 php8.0-fpm libapache2-mod-fcgid php8.0-curl php8.0-dev php8.0-gd php8.0-mbstring php8.0-zip php8.0-mysql php8.0-xml
How to change the PHP version you're using ?
If you have multiple PHP versions installed on your Ubuntu server, you can change what version is the default one.
1. To set PHP 7.4 as the default, run:
$ update-alternatives --set php /usr/bin/php7.4
2. To set PHP 8.0 as the default, run:
$ update-alternatives --set php /usr/bin/php8.0
3. You can verify what version of PHP you’re using with the following command:
$ php -v