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.

✨ Vultr and Linode are back on Cloudways! VIEW PLANS→

How to Install LAMP on Debian Server

Updated on December 16, 2021

6 Min Read
install lamp debian

A LAMP stack is a group of open-source software: 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 to run their website.

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. Here, we will learn how to install LAMP on the Debian server along with PHPMyAdmin to manage your database server.

Setting up LAMP on Debian Server

Note: Cloudways users do not need to follow these steps, as LAMP is pre-configured on our Platform. These steps are meant to guide non-Cloudways users.

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

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.

if config eth0 | grep inet | awk '{ print $2 }'

Let’s start creating a Stack now:

Verify PHP Installation on Apache Next, and you will need to create a sample PHP file to serve over the Apache webserver.

Step 1: Installing Apache on Debian

PHP Web Servers are the main components that run your site. Apache is open-source software that 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 public IP address and you will see this page:

By default, you can access your server scripts by adding them inside /var/www/HTML and creating your script there. 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

Use the following command to view and edit that file.

vim 000-default.conf

Next, 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

Then, 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

Restart your web server by typing the following command:

service apache2 restart

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

In practical terms, you won’t use the administrative database root user to connect from your PHP application.

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 password for root.

Set your password and press enter. 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 to not change the 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

You have successfully set up Apache and MySql on your web server till now. One thing that remains is server side language. You will be installing PHP on your 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:

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

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

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

php info

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

Improve Your PHP App Speed by 300%

Cloudways offers you dedicated servers with SSD storage, custom performance, an optimized stack, and more for 300% faster load times.

Step 4: Installing PHPMyAdmin on Debian

Every developer wants a UI to manage their MySQL server, and they mostly prefer PHPMyAdmin, an open-source GUI that helps in database management. First, set up an SSL with Apache so that your password isn’t sent in plain text form. Type the following to install an SSL with Apache:

apt-get install mcrypt

Now restart your Apache with the following command:

service apache2 restart

Then, install PHPMyAdmin by typing the following command:

apt-get install PHPMyAdmin

During the installation, a prompt will ask you about the Web Server you are using. Select Apache and press enter. After that, it will ask you for 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 by creating a .htaccess file using vim inside the PHPMyAdmin folder and allowing only your server IP to access it.

order allow,deny
allow from

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 software 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 server, it will take a lot of time, and the client might get upset. That’s where Cloudways plays its part.

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

Shahzeb Ahmed

Shahzeb is a Digital Marketer with a Software Engineering background, works as a Community Manager — PHP Community at Cloudways. He is growth ambitious and aims to learn & share information about PHP & Laravel Development through practice and experimentation. He loves to travel and explore new ideas whenever he finds time. Get in touch with him at [email protected]


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

Thankyou for Subscribing Us!


Webinar: How to Get 100% Scores on Core Web Vitals

Join Joe Williams & Aleksandar Savkovic on 29th of March, 2021.

Do you like what you read?

Get the Latest Updates

Share Your Feedback

Please insert Content

Thank you for your feedback!

Do you like what you read?

Get the Latest Updates

Share Your Feedback

Please insert Content

Thank you for your feedback!

Want to Experience the Cloudways Platform in Its Full Glory?

Take a FREE guided tour of Cloudways and see for yourself how easily you can manage your server & apps on the leading cloud-hosting platform.

Start my tour


  • 0


  • 0


  • 0


  • 0



For 4 Months &
40 Free Migrations

For 4 Months &
40 Free Migrations

Upgrade Now