How To Install Linux, Apache, MySQL, PHP (LAMP) stack on Ubuntu 16.10


LAMP stack is a stack of few softwares installed together to enable a server to host dynamic websites and web apps. This stack is “Linux” as operating system, “Apache” as webserver ” MySQL” for storing data in database and “PHP” for processing websites.

Step 1: Install the Apache Webserver, the ‘A’ in LAMP stack.

The Apache web server is the most popular web server in the world, which is a great choice for hosting a website.
The latest version of Apache (while writing this article) is 2.4.25.

We can install Apache by using apt package manager in Ubuntu. Before you begin installing any software, it is a good practice to update all all the packages to the latest version. So type the following command to update

 sudo apt-get update 


You may be asked for user password as you are using “sudo” command.
Now type the following to get Apache2 Web server installed on your machine.

 sudo apt-get install apache2 


Once done, your web server will get installed. You can immediately verify if your web server is installed as expected by visiting your server’s IP address in your web browser.

 http://server_IP_address  or can simply type “localhost”, which will present you the default page as shown below.


If you are seeing that page as in the image above, that means you have installed your Web server correctly.

Step 2: Installing MySQL for database

MySQL is an open-source relational database management system. This is used popularly for LAMP stack for managing all the database related activities.’

Coming to installation, as we have already update the packages while installing Apache using “update” command, we can now install the mysql-server package using the “apt-get” tool.Also, along with MySQL server, let us install PHP helper package by adding “php5-mysql” to the command.

Please run the following command to install MySQL server:

 sudo apt-get install mysql-server php5-mysql 


When installing this, it might ask you to setup a root password. Choose a secure password and memorize it. MySQL will automatically bind to localhost ( by default.

When the installation is complete we need to run the following command to secure our MySQL server environment.

 sudo mysql_secure_installation 


During this installation, the MySQL installer will prompt for the root password(Which I asked to memorize above).
Also, it will ask you if you want to change the password. You can type ‘no’ at the prompt.

The installer will ask you for more questions, which you can just select the default one’s by hitting “ENTER” button. Once done your database is setup. Now we need to set up PHP.

If you want to have PHPMyAdmin to manage your database, you can find the installation steps for that here.

Step 3: Installing PHP for WebApps

PHP is the programming language or script used for processing and displaying dynamic web content. It can talk to the database and can display details to the end users with the help of the web server.

To install PHP and its helper packages we will use the same apt-get tool, here is the command to run:

 sudo apt-get install php5 libapache2-mod-php5 


This will install the PHP on our machine.

There are many PHP modules that enhance the default PHP functionalites. To see the available options for PHP modules and libraries, you can type this command:

 apt-cache search php5- 


If we want any of the modules to be installed, we could use the apt tool again. Here is an example of how you can install CURL module:

  sudo apt-get install php5-curl 

Step 4: Testing it out!!

To test that we have configured our LAMP stack properly, we can create a small PHP file which will display the PHP configuration information.

Apache’s default root directory is  /var/www/html/ . Please navigate to that folder and create a file calling it “phpinfo.php”.

Open the file using a text editor and paste the following code into it:


Now save the file “phpinfo.php”.
To test this out, please navigate to  http://server_IP_address/phpinfo.php  in your browser. You can also access the file using  http://localhost/phpinfo.php  and you should see something like this below :



Have you seen this page ??  This page contains all your server info and PHP related configuration information. Once you successfully seen this page, please remove it to prevent other to access this sensitive information.

Hurray !! You have set up LAMP stack on your machine, now you can create and host your website here. Please leave any issue you came across when installing LAMP and we can help you out.


Share it with your friends now!

You may also like

Leave a Reply

Your email address will not be published. Required fields are marked *