How to Install LAMP stack on Debian 8 (Jessie)

  1. Knowledge Base
  2. Apache
  3. How to Install LAMP stack on Debian 8 (Jessie)

LAMP stack is a group of open source software used to get web servers up and running. The acronym stands for Linux, Apache, MySQL, and PHP.

Here is how to install the Apache2 Web Server, MySQL 5 Database, PHP 5 and other important packages and extensions.

Install LAMP stack on Debian 8

In order to complete this tutorial, you will need to have a Debian 8 server which is the distribution of the Linux operating system. So, the Linux part is taken care of.

If you need to setup an instance running Debian 8 (Jessie) on Google Cloud, click here.


Step 1. Update the System

Before running through the steps of this tutorial, make sure that all of your repositories are up to date.

Update your package lists, Type the following command in Terminal:

sudo apt update
Update Debian Package
Your operating system will compare the software packages currently installed with any new versions that might have been updated recently in the Debian online repositories

 

Next, Update our system by typing this command:

sudo apt upgrade
Upgrade Debian Distribution
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 Server, it will take a few minutes.

 

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


Step 2. Installing Apache

The next step in  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 apt install apache2
This command installs the basic Apache web server package as well as the documentation that goes along with it.

 

Once done, type the IP address provided by Google for your server in the browser.

(Example IP Address)
http://111.111.111.111

You will see the default Apache 2 web page, similar to this:

Apache2 Configuration Page
If you see this page, then congratulations - you have successfully installed Apache2 webserver on Debian 8.

 

When you are done looking at this test page, please remove it by typing the following command:

sudo rm /var/www/html/info.html

Step 3. Installing MySQL 5+

The next component of the LAMP server is MySQL.

To install MySQL, type the following:

sudo apt install mysql-server
On Debian 8, this command will install MySQL 5+ and other required packages.

 

Note that the installation routine will ask you to set up a new password for the root MySQL user:

MySQL Username and Password
This is a separate account used specifically for MySQL for administrative functions.

 

After this, the MySQL installation is finished.

To keep your new database server safe and secure MySQL Installation, type the following:

sudo mysql_secure_installation

At this point, the system will prompt you to enter the password for the root MySQL account. Go ahead and enter the password for the root MySQL account and then 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 ask you to remove any anonymous user's. Go ahead and answer yes to remove the anonymous user's option for safety:

Remove anonymous users? [Y/n] y

Next, the script will ask you to either allow or disallow remote logins for the root account. Go ahead and answer yes to remove the disallow remote logins for root for safety:

Disallow remote login? [Y/n] y

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.

Remove test databases? [Y/n] y

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

All done! If you have completed all of the above steps, your MySQL installation should be completed. Let us 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. Once in, 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.

Install MySQL Extension for PHP.

To Install MySQL Extension for PHP Support, type the following:

sudo apt install php5-mysql

Restart Apache Server

sudo service apache2 restart

Create User and Database

To create a MySQL user and database follow these steps:

  • At the command line, type the following:
mysql -u root -p
  • Type the MySQL root password, and then press Enter.
  • To create a database user, type the following command. Replace exampleuser with the user you want to create, and replace examplepasswd with the user's password:
GRANT ALL PRIVILEGES ON *.* TO 'exampleuser'@'localhost' IDENTIFIED BY 'examplepasswd';

This command will create and grant the user all permissions. However, you can grant specific permissions to maintain precise control over database access.

To learn more about setting up database permissions, click here.

  • To explicitly grant the SELECT permission, type the following command:
GRANT SELECT ON *.* TO 'exampleuser'@'localhost';
  • To create a database, Replace dbexample with the name of the database that you want to create, type the following command:
CREATE DATABASE dbexample;
  • When you are finished create Database, exit the application by typing either of the following commands:
 \q

or

exit

Step 4. Installing PHP

For our last component in LAMP Stack, we will set up and install PHP. The widely-used server-side scripting language used far and wide for dynamic web content, making it essential to many web and application developers. Installing this on your Server is quite easy.

To install PHP, simply type the following command :

sudo apt install php5

Agree to the installation and PHP 5 will be installed on your Server.

Restart Apache Server

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 the text editor to create a file named info.php by typing the following command:

sudo vim 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:

Note: You can also type : set paste in vim before you paste to disable automated indenting.

:

Type Set Paste

set paste

Insert paste by typing the following:

i

Inside this file, copy paste the following:

<?php phpinfo(); ?>

Save your changes by entering:

:wq!

Once done, open your web browser and type the IP address provided by Google for your server in the browser.

(Example IP Address)
http://111.111.111.111/info.php

You will see the default PHP information page, similar to this:

When you are done looking at this test PHP page, please remove it for security by typing the following command:

sudo rm /var/www/html/info.php

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

Install PHP 5 Curl

cURL is a library that lets you make HTTP requests in PHP. You can install Curl for PHP 5 by typing the following command in terminal:

sudo apt install php5-curl

Restart Apache Server

sudo service apache2 restart

Once done, you have completed the PHP installation.


That's it!

You've Installed Linux, Apache, MySQL, PHP (LAMP) stack on Debian 8 (Jessie) 

If you encounter problems during or after the installation. Lets us know in the Comments below!