Home » Operating System » Linux »  Install PHP in Ubuntu 18.04

Address

Jl. Meranti Wing 22 Level 4
Kampus IPB Darmaga
Bogor 16680, Jawa Barat, Indonesia
Tlp./Fax +62 (251) 8624535

Hours
Monday—Friday: 08:00–16:00

 Install PHP in Ubuntu 18.04

To install PHP, run:

$ sudo apt install php libapache2-mod-php php-mysql

After installing PHP, create info.php file in the Apache root document folder. Usually, the apache root document folder will be /var/www/html/ or /var/www/ in most Debian based Linux distributions. In Ubuntu 18.04 LTS, it is /var/www/html/.

Create test.php in the apache root folder as shown below.

$ sudo vi /var/www/html/info.php

Add the following lines:

<?php
phpinfo();
?>

Save and quit the file. Restart apache service to take effect the changes.

$ sudo systemctl restart apache2

Now, open up your web browser and type: http://IP-address/info.php in the address bar.

You will be pleased with a screen like below.

Install PHP modules

To improve the functionality of PHP, you can install some additional PHP modules.

To list the available PHP modules, run:

$ sudo apt-cache search php- | less

Sample output:

Use and arrows to move up and down between the result. To exit from the result, type q.

To find the details of any particular php module, for example php-gd, run:

$ sudo apt-cache show php-gd

To install a php module run:

$ sudo apt install php-gd

To install all modules (not necessary though), run:

$ sudo apt-get install php*

Do not forget to restart Apache service after installing any php module.


Leave a comment

November 2018
M T W T F S S
 1234
567891011
12131415161718
19202122232425
2627282930  

Categories