Tony Bandy
We hope you find this tutorial helpful. In addition to guides like this one, we provide simple cloud infrastructure for developers. Learn more →

How To Install Linux, Apache, MySQL, PHP (LAMP) Stack on Debian 8

Posted Jun 16, 2015 88.1k views LAMP Stack Debian


The LAMP stack of software, consisting of the Linux operating system, Apache web server, MySQL database, and PHP scripting language, is a great foundation for web or application development. Installed together, this software stack enables your server to host dynamic websites and web applications.

In this tutorial, we'll walk you through the installation of this software on a Debian 8 (Jessie) DigitalOcean Droplet.

Debian 8, as our operating system, is the Linux part of the stack.


Before we get started, please complete the following:

  • Create your Debian 8 DigitalOcean Droplet via the web interface
  • Complete the Initial Server Setup for Debian 8
  • As part of this setup, you'll create a sudo user and install sudo
  • You'll also install basic security packages such as IPTables, Fail2Ban, and others

If you have not yet finished your basic Droplet setup, go ahead and finish that up and then come back to this tutorial. We'll be using a sudo user to complete this tutorial.

Step 1 — Update the System

Before we install any software, it’s important to make sure your system is up to date.

Log in to your system via SSH, which you have set up previously (if not, see the Initial Server Setup tutorial).

To update your package lists, type:

  • sudo aptitude update

What this does is tell your operating system to compare the software packages currently installed with any new versions that might have been updated recently in the Debian online repositories, where base software packages are stored.

One note of caution is in order. If you are running a development or mission-critical high-use server, be cautious about installing updates without carefully going through each package to determine if it is actually needed for your system. In our example here, all packages have been installed for the purposes of this tutorial only.

For now, let’s go ahead and update our system. You can do this by typing this command:

  • sudo aptitude safe-upgrade

Once you’ve determined that these updated software components are relevant for your needs, go ahead and update your Droplet. This may take a while, depending on the current version of the operating system you have installed, software packages, and network conditions. On a fresh Droplet, it will take a couple of seconds.

Once done however, the Droplet is fully patched, updated, and ready for our LAMP installation.

Step 2 — Install Apache

The next step in our LAMP installation is installing the Apache web server. This is a popular web server that allows your server to display web content. To install Apache, type the following:

  • sudo aptitude install apache2 apache2-doc

This installs the basic Apache web server package as well as the documentation that goes along with it. This may take a few seconds as Apache and its required packages are installed. Once done, Aptitude will exit; Apache is now installed.

Let's test that the web server will respond with a sample web page. First up, you will need the IP address of your Droplet. You can view your IP address in your DigitalOcean account dashboard or simply use your current SSH session:

  • sudo ifconfig eth0

On your screen, you will see a few lines of output, including your server's IP address. You'll want the four-part number shown after inet addr::

inet addr:

Note the IP address listed and type it into your favorite web browser like this:


Once done, you will see the default Apache 2 web page, similar to this:

Apache2 Debian Default Page

If you see this page, then congratulations — you have successfully installed Apache on your Droplet!

You can upload your website content to the /var/www/html directory. If you want to set up multiple websites, please see this article on setting up Apache virtual hosts.

For additional instructions and security information, please take a look at Debian's Apache information.

Step 3 — Install and Secure MySQL

The next component of the LAMP server is MySQL. This relational database software is an essential backend component for other software packages such as WordPress, Joomla, Drupal, and many others.

To install MySQL and PHP support for it, type the following:

  • sudo aptitude install mysql-server php5-mysql

This will install MySQL and other required packages. Note that the installation routine will ask you to enter a new password for the root MySQL user:

New password for the MySQL "root" user

This is a separate account used specifically for MySQL for administrative functions. The username is root and the password is whatever you set here. Be sure to set a good password with various combinations of letters and numbers.

After this, the MySQL installation is finished.

To keep your new database server safe, there is an additional script you need to run. Type the following to get started:

  • sudo mysql_secure_installation

At this point, the script will now ask you a few questions. When prompted, go ahead and enter the password for the root MySQL account. The system will then ask you:

Change the root password? [Y/n] n

Since we already set the root MySQL password at our installation, you can say no at this point. The script will then ask:

Remove anonymous users? [Y/n] y

Go ahead and answer yes to remove the anonymous users option for safety. You can answer yes to the rest of the questions as well by entering y.

Next, the script will ask you to either allow or disallow remote logins for the root account. For safety, disallow remote logins for root unless your environment requires this.

Finally, the script will ask you to remove the test database and then reload the privilege tables. Answer yes to both of these. This will remove the test database and process the security changes.

If everything is correct, once done, the script will return with:

All done! If you have completed all of the above steps, your MySQL installation should now be secure.

Let's double-check that our new MySQL server is running. Type this command:

  • mysql -u root -p

Enter the root password you set up for MySQL when you installed the software package. Remember, this is not the root account used for your Droplet administration. Once in, now type the following to get the server status, version information and more:

  • status

This is a good way to ensure that you’ve installed MySQL and are ready for further configuration. When you are finished examining the output, exit the application by typing this:

  • exit

Step 4 — Install PHP

For our last component, we will set up and install PHP, known as PHP: Hypertext Preprocessor. This widely-used server-side scripting language is used far and wide for dynamic web content, making it essential to many web and application developers. Fortunately, installing this on your Droplet is quite easy.

To install PHP, simply type the following:

  • sudo aptitude install php5-common libapache2-mod-php5 php5-cli

Agree to the installation and PHP will be installed on your Droplet. You will see many packages being installed beyond just PHP; don’t worry, as this is integrating the software with your existing Apache2 installation and other programs.

Restart Apache on your Droplet to make sure all of the changes with the PHP installation take effect. To do this, type the following:

  • sudo service apache2 restart

Now, let’s take a moment to test the PHP software that you just installed. Move into your public web directory:

  • cd /var/www/html

Once there, use your favorite console text editor to create a file named info.php. Here’s one method of doing this:

  • sudo vi info.php

This command will use the command line editor vi to open a new blank file with this name. Inside this file, type the following:

<?php phpinfo(); ?>

Save your changes. Open your web browser and type the following URL:


If you’ve done everything correctly, you will see the default PHP information page, like the one shown below:

PHP Information Page

When you are done looking at this test PHP page, please remove it for security. To do that, run this command:

  • sudo rm -i /var/www/html/info.php

The system will then ask you if you wish to remove the test file that you've created. Answer yes and you're finished; you have completed the basic PHP installation.


You have now installed the basic LAMP stack on your DigitalOcean Droplet.

Now it's time to customize your server. This includes any custom programs that you may need to install on your Droplet, and basic security measures to keep unwanted visitors away! Take a look at these articles and others in the DigitalOcean community:


Creative Commons License