Installing and Configuring LAMP Stack on Ubuntu 16.04 LTS

LAMP stack is a popular open source web platform which is used to run dynamic web sites and servers. It includes Linux, Apache, MySQL, and PHP. 

Update the repository

    sudo apt-get update

    sudo apt-get upgrade

To install apache HTTP server, Open up terminal and type

    sudo apt-get install apache2

now open up web browser and test the apache server installation on your local machine

    http://localhost/

in my system http://192.168.56.101/ 


 perfect!, now our apacheHTTP server is up and running. Now the next step is to install mysql-database server. To install mysql-server type the following command

    sudo apt-get install mysql-server php5-mysql

during the installation process it will ask you to enter 'root' password for mysql database.


you need to enter the password again to confirm it. To test mysql-server installation, type the following command

    mysql -u root -p

then hit enter and it will ask you for mysql password


for enable the extra security measures in your mysql server type the following command

    sudo /usr/bin/mysql_secure_installation

enter the mysql-server root password and it will ask you to change database root password, type 'n'and hit enter.It will ask you some options for simplicity type 'y' to all of them. You can also skip that if you install mysql just for learning/testing purpose, bacause it will disable remote login, anonymous users etc.
 By default, a MySQL installation has an anonymous user, allowing anyone  
 to log into MySQL without having to have a user account created for  
 them. This is intended only for testing, and to make the installation  
 go a bit smoother. You should remove them before moving into a  
 production environment.  
 Remove anonymous users? [Y/n] y                        
  ... Success!  
 Normally, root should only be allowed to connect from 'localhost'. This  
 ensures that someone cannot guess at the root password from the network.  
 Disallow root login remotely? [Y/n] y  
 ... Success!  
 By default, MySQL comes with a database named 'test' that anyone can  
 access. This is also intended only for testing, and should be removed  
 before moving into a production environment.  
 Remove test database and access to it? [Y/n] y  
  - Dropping test database...  
  ... Success!  
  - Removing privileges on test database...  
  ... Success!  
 Reloading the privilege tables will ensure that all changes made so far  
 will take effect immediately.  
 Reload privilege tables now? [Y/n] y  
  ... Success!  
 Cleaning up...   

the next step is to install PHP, open up terminal and type

    sudo apt-get install php5 libapache2-mod-php5

now add php to the directory index

    sudo nano /etc/apache2/mods-enabled/dir.conf

the dir.conf file look like this


now simply move the 'index.php' in first place, like this


then press Ctrl+O and enter to save and Ctrl+X to exit. After that restart apache server by

    sudo service apache2 restart

PHP contains alot of useful libraries and modules which we can add into our server. We can see all the libraries which are available is by

    apt-cache search php5-

and to install any listed module type

    sudo apt-get install

to install multiple modules at once, put the module names with space

    sudo apt-get install ...

Now to test the php installation, create a php file 'index.php' in root web directory

    sudo nano /var/www/html/index.php

and put the below code
 <?php  
   phpinfo();  
 ?>  

restart the apache server and open your url into web browser just we did previously.


We have successfully installed LAMP stack.