Chat with us, powered by LiveChat

This website uses cookies

Our website, platform and/or any sub domains use cookies to understand how you use our services, and to improve both your experience and our marketing relevance.

How to Install LAMP on Debian Server

August 9, 2016

6 Min Read
Reading Time: 6 minutes

A LAMP stack is a group of open source softwares: Linux, Apache, MySQL and PHP. Through this stack, the developers run their websites. Most VPS or Cloud PHP web servers come pre-installed with Linux.. They need to install LAMP stack themselves in order to run their website.

Install LAMP on Debian Server

Most developers who are not SysAdmins don’t know how to create a LAMP stack on their servers. If you are one of those developers, this blog is for you. In this blog, we will learn how to install LAMP on Debian server along with PHPMyAdmin to manage your database.

You might also like: Host PHP On Debian Based DigitalOcean Server in One Click

Before getting started, make sure that all the packages on your server are updated. To do that, open your terminal and run the following command:

apt-get update

Now your packages are updated. Now type the following command to know your server IP which will also be useful in the coming tutorial. Type the following command to know print your server IP.

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

Let’s start creating a Stack now:

Step 1: Installing Apache on Debian

PHP Web Servers are the main components that run your site. Apache is an open source software which runs 50% of the Web Servers around the world. To install apache on your server, run the following command:

apt-get install apache2

When it prompts, that extra space would be filled; type “y” and press enter

Installing Apache on Debian

Once the download is finished, head to your IP address and you will see this page:

Installing Apache 2 on Debian

By default, you can access your server scripts by adding it inside /var/www/html and creating your script there. In order to configure it to run your scripts inside public_html, we need to configure 000-default.conf file which is inside apache2/sites-enabled. To reach that folder type the following command:

cd /etc/apache2/sites-enabled

Now use the following command to view and edit that file.

vim 000-default.conf

Now head to DocumentRoot, press “i” to edit the file and then remove html from it and add public_html. Now save the file by pressing Esc and type “:wq”.

editing apache root folder

Now head to the terminal and type the following command to reach public_html folder and change the html folder name to public_html

cd /var/www
mv html public_html

Now restart your web server by typing the following command:

service apache2 restart

Now your settings are changed, and you can check them by going to your IP address and you will find the html directory root of your server. Now that we have configured Apache, let’s install MySQL.

Step 2: Installing MySQL on Debian

On your terminal, type the following command:

apt-get install mysql-server

Once installation is finished, it will ask you to set your root password.

installing mysql on debian

Set your password and press enter. Now complete your MySQL installation by running the following command:


Once you hit enter, the prompt will ask you to enter the root password, then hit enter.

  • Type n in order to not change root password and hit enter,
  • then type y to remove anonymous users and hit enter.
  • Type n if you want to disallow root login remotely and hit enter.
  • Now type y to remove test tables and databases and hit enter, then type y again and hit enter.

installing mysql on debian 2

MySql is now successfully installed on your server.

Step 3: Installing PHP on Debian

We have successfully setup Apache and MySql on our web server till now. One thing that’s remaining is server side language. We will be installing PHP on our server, so type the following command to install it:

apt-get install php5 php-pear php5-mysql

Once it’s complete, run the following command to restart your Apache:

service apache2 restart

Now head to your public_html folder of Apache by typing the following command

cd /var/www/public_html

Let’s create a simple PHPinfo file in it now. Type the following command to create a file:

vim index.php

Press i to start writing and type the following code in it:

<?php echo phpinfo();?>

Save it by pressing Esc and then typing :wq. Now head to browser and open [server ip]/index.php. Type the following command to find out your IP address again:

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

php info

If you find your PHPinfo file rendered then you have successfully configured your LAMP stack.

You might also like: PHP 5.6 Vs PHP 7 – Performance Benchmarks With Symfony 3

Step 4: Installing PHPMyAdmin on Debian

Every developer wants a UI to manage their MySQL server and they mostly prefer PHPMyAdmin which is an open source GUI which helps in Managing MySQL databases. Let’s first setup a SSL with Apache so that our password isn’t sent in plain text form. Type the following to install a SSL with Apache:

apt-get install mcrypt

Now restart your Apache with the following command:

service apache2 restart

Now install PHPMyAdmin by typing the following command:

apt-get install phpmyadmin

During the installation a prompt will open which will ask you about the Web Server you are using select Apache and press enter, after that it will ask about the root user password. Enter the password and press enter.

PHPMyAdmin will be installed in /usr/share/phpmyadmin. We will create it’s symlink inside the public_html folder. Type the following commands to route to public_html folder and create a symlink:

cd /var/www/public_html

ln -s /usr/share/phpmyadmin

Now type ls to verify whether the symlink has been created or not. Now open this in browser through [server ip address]/phpmyadmin. You will see that it is installed. Now let’s secure it create by creating a .htaccess file using vim inside PHPMyAdmin folder and allowing only your server ip to access it.

order allow,deny

allow from <your server ip>

You might also like: Installing PHPMyAdmin On Cloudways

Step 5: Installing Git and Composer

Every developer nowadays uses Git to manage their version controller and Composer to manage and install packages. These 2 softwares have become essential for every server, so let’s install them by typing the following command to install git:

sudo apt-get install git-all

Now type the following commands, as discussed on the official website, to install composer and move it to the bin so we can use it when we call composer on command line.

php -r "copy('', 'composer-setup.php');"

php -r "if (hash_file('SHA384', 'composer-setup.php') === 'e115a8dc7871f15d853148a7fbac7da27d6c0030b848d9b3dc09e2a0388afed865e6a3d6b3c0fad45c48e2b5fc1196ae') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"

php composer-setup.php

php -r "unlink('composer-setup.php');"

mv composer.phar /usr/local/bin/composer


In this tutorial you have learned how to install LAMP on Debian server. As you can see, creating a LAMP stack on an empty server is simple but it takes a lot of time and effort. When a client gives you a project, you will need to complete it and test it on a web server. But if you are going to build your own server, it will take a lot of time and the client might  get upset. That’s where Cloudways comes handy.

On Cloudways, you just need to create your account, run your server and everything will be installed and the UI environment will be set up for you within minutes. You just need to upload your work on your server and start testing your project on an online server. Sign Up now on Cloudways to enjoy 3 days of free trial on DigitalOcean server.

Share your opinion in the comment section. COMMENT NOW

Share This Article

Launch PHP websites without the worry of Server Management.

Pre-Installed Optimized Stack with Git, Composer & SSH

Ahmed Khan

Ahmed was a PHP community expert at Cloudways - A Managed PHP Hosting Cloud Platform. He is a software engineer with extensive knowledge in PHP and SEO. He loves watching Game of Thrones is his free time. Follow Ahmed on Twitter to stay updated with his works. You can email him at

Get Our Newsletter
Be the first to get the latest updates and tutorials.

Do you like what you read?

Get the Latest Updates

Share Your Feedback

Please insert Content

Thank you for your feedback!

BFCM 2019