How to Install Linux, Apache, MySQL, PHP (LAMP) stack on Debian



LAMP is the most common configuration used in web server and it stands for Linux, Apache, MySQL, and PHP. This tutorial describes how to install LAMP stack on Debian. The Linux part of the stack is already done as the virtual private server is up and running Debian. Here you will see the installation of Apache, PHP and MySQL.

Initial Set Up


Before getting to installation of any LAMP software, just make sure that all of the repositories are up to date:

apt-get update


Installing Apache


Apache is free software that is distributed by Apache Software Foundation and is supposed to be the most popular open source software that runs over 50% of web servers in the world.

Run the following command on your terminal to install apache:

apt-get install apache2

To verify, you can point your browser to the server IP address and check. If it displays a page which says “It works”, then it is correct.

You can get your IP address using the following command:

ifconfig eth0 | grep inet | awk '{ print $2 }'


Installing MySQL


Let’s start with MySQL installation process. MySQL database management system is used for organizing and retrieving data.

Open your terminal and enter the following command.

apt-get install mysql-server

In case if the system displays any messages, press enter. You will be asked to set a root password while the program is installing. In case if you missed the chance, you can set it later from within the MySQL shell.

Next step is to run the secure install script to clean up.


While the secure install scrip is running, the system will ask for your MySQL root password. In that case, just hit enter as MySQL root password has not been set.

Enter current password for root (enter for none): 
OK, successfully used password, moving on...

When system prompts for setting the root password, type ‘Y’ and enter your new MySQL root password. Below you can see a snapshot of the output screen, while the script is running.

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...

MySQL is installed.

Installing PHP


PHP is a programming language for building dynamic web pages.

For the installation of PHP, open the terminal and type in the following command:

apt-get install php5 php-pear php5-suhosin php5-mysql

Note: If you are using Debian 7, then you will have to exclude php5-suhosin as it was removed.

The system will ask for your confirmation and PHP will be installed.

Now, restart apache to finalize the installation:

service apache2 restart


Verification by Access


Now that the LAMP stack is completely installed on your system, you may have to verify it by creating a simple php info page.

For that, you need to create a new blank file and paste the following code.

nano /var/www/info.php

Save and exit the file.

Visit your php info page by going to your IP address on browser. It should look similar to this:


Now you are done with the installation of LAMP stack on Debian.


support2 has written 111 articles

Leave a Reply