PHP is a simple, secure, flexible, and efficient open-source language.
Standing for PHP Hypertext Preprocessor, it is the most used programming language worldwide.
Able to integrate into HTML, PHP handles the connection between your web pages and databases.
The scripting language, PHP, will process the code to display dynamic content to users.
By the end of this PHP tutorial
- You’ll be able to install PHP on Ubuntu 20.04 and in less than 7 minutes!
PHP tutorial requirements
Step 1: Update package repository
First, always update Ubuntu’s package repository.
Because doing so will:
- Protect your software, while shortening your future updates time
- Always get you the latest versions of what you want to install.
You’re probably wondering how to update your package repository by now.
Simply, type the following command into your terminal and press ENTER.
- sudo apt update
Then, put in your password and let Ubuntu do the magic work.
Don’t forget to check our tutorial on what is Ubuntu Linux and how to install it.
Step 2: Install PHP on Ubuntu
Installing PHP is a straightforward task.
Just, copy the below command and paste it into your terminal.
- sudo apt install PHP
Press Y to confirm the latest PHP download and install.
Step 3: Verify PHP installation on Ubuntu
Coming up, time to verify the PHP version after the installation.
Put in the command:
- php -v
Well, you can see that, by the time of writing this article, the latest PHP version is 7.4.3How to Install PHP on Ubuntu 20.04? Master the basics with this step-by-step "pictures included" guide, in less than 7 minutes! Click To Tweet
Step 4: Install PHP with Apache
Did you know that it is possible to install PHP using Apache as well?
All you have to do is put in the following command:
- sudo apt install libapache2-mod-php
For the changes to take effect immediately, you need to restart Apache using the given command:
- sudo systemctl restart apache2
Next, check and verify the Apache PHP module status by using the command:
- sudo systemctl status apache2
Now that it’s up and running, you are on the right track!
Step 5: Install PHP extensions on Ubuntu 20.04
To get a list of PHP extensions, you can enter the following command
- sudo apt install php-
Afterward, press the tab button on your keyboard twice, followed by Y, for a complete extensions list
For example, to install the cas extension, the command you need to enter would be:
- sudo apt install php-cas
The system will ask for the needed additional space to install the extension.
Press “y” to accept the process.
Momentarily, it will begin to download and install the extension you picked up.
This is the way you can download and run any of the available PHP extensions.
Step 6: Test your PHP process
To test the configuration of your web server for PHP processing.
Create a new file named info.php inside var/www/html with the following command:
- sudo nano /var/www/html/info.php
With the code:
- Save the file
- Head over to your browser
- Browse the server’s IP address
You will get the following webpage.
ServerHub to the rescue
You can do it yourself, but you don’t have to!
Wave us hello at [email protected] and let us guide you freely to your upcoming website.
Additionally, with 100% Uptime, 24/7 support, and 40GB interface connectivities.
ServerHub spans 9 locations and offers custom quotes
Check out our amazing deals starting from $5 a month!
That was the simplest-full guide to master the PHP basics on Ubuntu 20.04.
I’m sure that by now, you are a PHP professional yourself.
With learning how to install PHP, PHP extensions, and integrating them with Apache.
Let us discuss your thoughts and questions in the comments below so we can brainstorm, together!
This tutorial is a part of the LAMP stack guide series.
Check out the rest of the series: