How to Install PHP on Ubuntu 18.04

How to Install PHP on Ubuntu 18.04

In this tutorial we will discuss how to install PHP 7.4 on Ubuntu 18.04, and also how to integrate it with Apache.

Preparation

Make sure the linux distro that you use is the same, that Ubuntu can be checked with the command

$ lsb_release

The command will display the following results like

No LSB modules are available.                                                                                                                                           
Distributor ID: Ubuntu                                                                                                                                                  
Description:    Ubuntu 18.04.4 LTS                                                                                                                                      
Release:        18.04                                                                                                                                                   
Codename:       bionic

Make sure the computer is connected to the internet

Installastion PHP 7.4

Type the following command in the terminal

$ sudo apt install php7.4 libapache2-mod-php7.4

The  command by default will install the apache and php packages. After the installation process is complete, restart Apache with the following command

$ sudo systemctl restart apache2

 Installing PHP extensions

To expand PHP's core functionality you can install a number of additional extensions. PHP extensions are available as packages and can be easily installed by:

$ sudo apt install php7.4-[extname]

For example, if you want to install extensions like curl, the commands that are used are:

$ sudo apt install php7.4-curl

After the php extension installation process don't forget to restart your apache service to see the changes.

Testing

To test whether your web server is configured correctly for PHP processing, create a new file called info.php in the directory  /var/www/html  with the following code:

/var/www/html/info.php

phpinfo();

Save the file, open the browser of your choice and visit http://localhost/info.php

The phpinfo function will print information about your PHP configuration as shown in the image below :

Php Info

 

 

 

Dipost Oleh Administrator

Hello there

Post Terkait