In this post we will learn how you can install Apache2 server and PHP5 on Ubuntu. Undoubtedly, Apache2 is the most famous webserver and along with PHP, these both become the best recipes to cook pretty neat websites.

Oh ! Was that too much cooking, eh ? Sigh ! let’s not get more into and coming straight to the point, on how to install these two in your Ubuntu box.

Open the terminal window in Ubuntu and type the following commands :

sudo apt-get install apache2

sudo apt-get install php5

sudo apt-get install libapache2-mod-php5

sudo apache2ctl restart

First command install apache2, while second install PHP5. Third command installs the PHP module for Apache2 server and finally the fourth command restarts the apache server which gets initialized while installing.

Place your PHP files inside /var/www to run your PHP scripts. Read this post to learn, how to set permission on the /var/www folder

To run a test if PHP is successfully installed on your box, do as following.

cd /var/www

sudo vi test.php

This will open a new file called test.php. Now type the following lines of code to see if PHP is up & running (press ESC then i to enter insert mode in vi editor).


Save the file by hitting ESC following by :wq

Now you should be back in the terminal window, type :

php –f test.php

And if that executes without an error, you are successful. Another way to check this, is via browser, hit http://localhost/test.php

It will show you complete configuration of your installed PHP with the loaded modules.

Hope that helps

Stay Digified !!

Sachin Khosla

Share this post: