How To Install LAMP Stack on Ubuntu 14.04
Database,  PHP,  Unix

How To Install LAMP Stack on Ubuntu 14.04

If you are going to host your website on Unmanaged Dedicated Server or VPS then in that case you are the one, who is going to install all the required services. You can host any PHP based dynamic website or blog like WordPress on Linux, using Apache Server, MySQL or any other Relational Database and PHP. LAMP is a acronym which is a collection of open source software which represent Linux Operating System, Apache Web Server, MySQL database and PHP. By installing these you will be able to run any PHP based dynamic website.

How To Install LAMP Stack on Ubuntu 14.04

In this post i am going to explain How to install and configure Linux, Apache, MySQL, PHP(LAMP) stack. First thing you need is a VPS with Ubuntu 14.0 installed, you can get it from DigitalOcean they have monthly plan as low as $5. After purchasing you will get you VPS configured with Ubuntu 14.04 OS and your root user detail. Now follow my instruction for next step

How To Install Apache Web Server?

To install Apache Web Server, log in to your VPS server with root user access using any SSH client, You can use Putty for this purpose. Now we are going to install apache using apt package manager, which will download the apache setup from ubuntu repository. Enter below command in putty client

sudo apt-get update
sudo apt-get install apache2

We are using sudo linux command to run the installation as root user. Few minutes after your setup will complete and control will return to prompt. To check if your Apache Server is configured correctly or not, you can visit your server ip


if everything is right, you will see the test page with message It works! . Now your Apache is running, if you ever need to start, stop or restart Apache Web server you can do by following command

Start Apache Server :        sudo /etc/init.d/apache2 start
Stop Apache Server :         sudo /etc/init.d/apache2 stop
Restart Apache Server :   sudo /etc/init.d/apache2 restart

How To Install MySQL?

After configuring Apache next step is setting up MySQL. MySQL is a open source database management system and it will store all the website data in form of relational table. MySQL requires some helper packages through which it communicates with other components. We can install these with MySQL with below command

sudo apt-get install mysql-server php5-mysql

During installation MySQL will ask you to set root password for administrative access. Set this password different from your Linux root password for security purpose.

After few minutes MySQL will be installed, now we need to setup the environment where MySQL will store its information. You can do so by running below command

sudo mysql_install_db

To increase the security of MySQL, one extra step is recommended and that is MySQL Secure Installation and we can do that by running below interactive script.

sudo mysql_secure_installation

It will ask your MySQL root password and give you option to change it or keep the existing one, you can do so by entering ‘y’ or ‘n’ in the prompt. For other question just press the ‘ENTER’ key and it will set the default values. By doing so setup will remove MySQL sample users and databases, disable remote root logins, and load the currently changed setting. With this step your MySQL is configure and ready to use.

Whenever you want to start and stop MySQL database you can do so by entering below command
Start MySQL Database :  sudo service mysql start
Stop MySQL Database :   sudo service mysql stop

How To Install PHP?

As of now we have configured a VPS system with Ubuntu 14.04, Apache Web Server and MySQL Database. Our next and last step will be to install PHP which will process all your dynamic content. To install PHP type below command on terminal

sudo apt-get install php5 libapache2-mod-php5 php5-mcrypt

Above command will install PHP with all the dependency.

Now we need to do some changes in Apache configuration to manage dynamic website. By default Apache looks for index.html in your website directory and if  found then it looks for another one according hierarchy. We are going to set the default setting for .php so that web server will first search for index.php file.  To modify the setting enter below command

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

Output will be like this

<IfModule mod_dir.c>
    DirectoryIndex index.html index.cgi index.php index.xhtml index.htm

Now change the order of files with this

<IfModule mod_dir.c>
    DirectoryIndex index.php index.html index.cgi index.xhtml index.htm

Now web server will processs php file first.

How To Check If PHP is Working on Web Server or Not?

We can check whether PHP is installed or not and is working properly by creating a simple info.php file. You need to create this file in your public_html directory, you can do so by entering

sudo nano /var/www/public_html/info.php

It will open nano editor, you can use vi editor instead of nano. Enter below sample php code and save the file


After saving the file you need to enter your server ip with info.php page, it will be like


Your screen should look like this
How To Install LAMP Stack on Ubuntu 14.04

With this step we have now successfully configured LAMP stack on Ubuntu 14.04.  Now you can install any CMS or host your dynamic website on this server. Below image represent LAMP Architecture and how this server will process dynamic content. How To Install LAMP Stack on Ubuntu 14.04

Below are the tutorials which will help you managing your Linux VPS and Setting Up WordPress based blog.

I hope you liked the post, Please give your valuable feedback and suggestion in the comments. Also please like our Facebook page and follow us on Twitter for updates.

Leave a Reply

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