Our website is made possible by displaying online advertisements to our visitors. Please consider supporting us by disabling your ad blocker.

Install The LAMP Stack On A Debian Linux VPS

TwitterFacebookRedditLinkedInHacker News

So you’re at a time in your life where you want to manage your own web server. Maybe you are currently on a shared hosting plan and it isn’t giving you the performance you need because your web application is getting crazy amounts of traffic or maybe you just want to play the role of DevOps. My blog (the one you’re on now) is on a virtual private server (VPS). The LAMP (Linux, Apache, MySQL, PHP) stack sits on top of this server which allows me to serve web applications or support software like WordPress.

My VPS is hosted on a Digital Ocean Droplet with the Debian Linux distribution. Reading further will show you how to set up the LAMP stack on your own Debian Linux instance.

If you’re familiar with Digital Ocean you’ll know that they offer pre-built VPS images that already contain the LAMP stack. The problem with this is that the images are only made with older versions of Ubuntu. What if you want to use a recent version? Or a different distribution like Debian?

I personally prefer Debian because it has a smaller footprint than Ubuntu. It allows me to keep my server with lower specs.

Let’s talk about getting the LAMP stack set up. You technically don’t need Digital Ocean to make this happen, but it is a worthy service for it.

We’re going to assume you already have your Debian Linux machine operational. Using your Terminal (Mac or Linux) or PuTTY (Windows), SSH into your machine similar to the following:

ssh root@

The IP will probably not be, but you will need a privileged user to continue, whether that be root or a user that can use sudo.

At this point you’re ready to start installing stuff.

Installing MySQL

Assuming you’re root and not using sudo, run the following to install the MySQL Server and the MySQL Client for accessing the server via the command line:

apt-get install mysql-server mysql-client

During the installation it will ask you to set a password for the root MySQL user. Although we won’t do it in this tutorial, you should create a heavily privileged account and use it instead of the root account for safety reasons.

Installing Apache

Now that the database is installed and ready to go, we need to install Apache which will serve web requests. From the Terminal or PuTTY, run the following:

apt-get install apache2

That wasn’t so hard. You can see that Apache is serving requests by visiting, from your web browser, your server IP or domain name if you’ve set one up. If you’re looking for a quality and affordable domain name, you might check out the provider I use which is Namecheap.

Installing PHP

Although not too much different, getting PHP up and running might require the most from you. Start by installing PHP and the various modules from the Terminal or PuTTY:

apt-get install php5 php5-mysql libapache2-mod-php5

To get PHP working with MySQL you will need to enable the extension in your PHP configuration file typically found at /etc/php5/apache2/php.ini. Find in the file the following line:


If it exists, uncomment it. If it doesn’t exist, add it.

Restart Apache now that you’ve added PHP to the mix and you should be in good shape. To restart Apache, do the following:

/etc/init.d/apache2 restart

All your HTML and PHP files should go in the /var/www/html directory since that is what Apache is serving.

Installing phpMyAdmin For UI Database Access

You could go a step further and set up phpMyAdmin which is a very useful dashboard for accessing your MySQL databases and data. To do this, run the following from the Terminal or PuTTY:

apt-get install phpmyadmin

When it asks you which server to use, make sure you select apache2 by pressing the space bar to select and then enter to confirm.

The next thing it will ask is if you want to use dbconfig-common as your starting database. Since we don’t yet have a database configured, we can go ahead and accept this option.

Finally it will ask you for two passwords. The first password it asks for is the root user to the MySQL database. This is the same password you chose when installing MySQL. The second password it asks for is a new one for interfacing phpMyAdmin with MySQL. Leaving it blank will create a random password which is fine.

Go ahead and restart Apache again using the following command:

/etc/init.d/apache2 restart

phpMyAdmin is now good to go! Verify the installation in your browser by visiting http://yoursitehere/phpmyadmin, replacing yoursitehere with your domain name or server IP address. When it asks you to sign in, go ahead and use the root MySQL account because you may not have created another one yet.


You now have the LAMP stack installed on your Debian machine. The LAMP stack is good if you intend to make PHP web applications or use software like WordPress. If you chose to use Digital Ocean to host your web server please consider using one of the affiliate links. Doing so will give us both credit towards our hosting plan. In case you don’t click the link and would prefer to enter the referral code manually, please use ee4903914bb4. If you’re planning on getting a domain name and decide to use Namecheap, please use this affiliate link.

A video version of this article can be seen below.

Nic Raboy

Nic Raboy

Nic Raboy is an advocate of modern web and mobile development technologies. He has experience in C#, JavaScript, Golang and a variety of frameworks such as Angular, NativeScript, and Unity. Nic writes about his development experiences related to making web and mobile development easier to understand.