How to Install Linux, Apache, MySQL, PHP

Linux, Apache, MySQL, PHP,stack on Ubuntu 16.04

This educational teaches the way to install LAMP on Ubuntu sixteen.04 VPS. LAMP is an acronym for Linux, Apache, MySQL, PHP. It is a popular stack for creating and deploying dynamic web applications.

In this stack, Linux serves because the running machine for the web utility. MySQL is used as the database. Apache is used as the internet server. PHP is used to procedure dynamic content. In a few other variations of this stack, Perl is used in preference to PHP or Python. However, for this tutorial, we are going to installation PHP, as it’s miles the maximum famous desire for this stack.

Linux, Apache, MySQL, PHP,What you’ll need

Before you begin with Ubuntu LAMP tutorial, you’ll want the following:

  • A neighborhood system with SSH customer mounted (see academic on the way to use putty ssh customer if you are Windows person)
  • VPS Running Ubuntu sixteen.04
  • A non-root consumer with the sudo privileges

It is usually recommended to use a sudo person instead of the foundation person to put in software program for safety purposes. If you have root get right of entry to to your VPS server you may create a sudo user with following instructions

adduser <username>

The above command creates a person together with your provided username. Now make the newly created person a sudoer.

usermod -aG sudo <username>

Switch to this new user.

sudo su - <username>

How LAMP works

Whenever a web web page request arrives at a server it’s far passed on to an application referred to as internet server, in our case Apache. Apache looks for the file being asked within the URL of the request and passes this records to the PHP interpreter. It executes the common sense written in that report, pulls data from the MySQL database if wanted and generates an internet web page. Apache, our web server sends this generated web page to the consumer.

Step 1 – Installing Apache Web Server

Before starting the installation, update your gadget and make certain you have contemporary packages.

sudo apt-get update
sudo apt-get upgrade

Now install Apache2 with the following command

sudo apt-get install apache2

Checking your installation

To test the installation, open your browser to your nearby system and enter the subsequent address in deal with bar.


For instance, in case your VPS IP address is your address should be:

You should see a page that looks like this:

Note: If you don’t realise your VPS’s IP address, the fastest manner to discover it’s far by manner of walking following the command. This command prints the general public IP address of your VPS.

dig +short

Troubleshooting your installation

If you probably did no longer see the above picture don’t worry, you may have enabled the firewall. You ought to enable Apache to serve net requests on port 80 and port 443 to your firewall. Install UFW.

sudo apt-get install ufw

Then allow HTTP and HTTPS traffic through the firewall.

sudo ufw allow http
sudo ufw allow https

This command permits HTTP and HTTPS site visitors through the firewall. UFW is command line software referred to as Uncomplicated Firewall. It is used to manipulate and make guidelines for Linux firewall. Now input your VPS Ip cope with to your browser to test the installation. You can take a look at the repute of Apache server with the subsequent command.

sudo systemctl status apache2

Step 2 – Installing MySQL

MySQL is the database on your software. To set up MySQL enter the subsequent command.

sudo apt-get install mysql-server

During installation, it’ll spark off you for the password of the basis consumer. Make positive to use a robust password. Don’t depart it blank.

Using root consumer you can create different customers for the databases. It is a superb practice to create a separate user/position for the database of a new internet software. You can test the repute of MySQL service with the subsequent command.

sudo systemctl status mysql

Example output:

● mysql.service - MySQL Community Server
   Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
   Active: active (running) since Tue 2017-07-11 09:39:40 EDT; 1min 39s ago
 Main PID: 9579 (mysqld)
   CGroup: /system.slice/mysql.service
           └─9579 /usr/sbin/mysqld

Jul 11 09:39:39 abandoned-plate systemd[1]: Starting MySQL Community Server...
Jul 11 09:39:40 abandoned-plate systemd[1]: Started MySQL Community Server.

Step 3 – Installing PHP

PHP executes your application. Install PHP and further modules with the subsequent command

sudo apt-get install php libapache2-mod-php php-mcrypt php-mysql php-cgi php-curl php-json

This command will deploy the modern stable model of PHP and a few extra modules that are required for net application to paintings.

Step 3.1 – Checking your PHP installation

Now which you have set up PHP, we will check if it’s miles running nicely via creating a check file and establishing it within the browser. First, installation the nano textual content editor.

sudo apt-get install nano

Nano is a command line textual content editor and is less difficult to get began with for novices. Click here to learn how to use the nano text editor. Now, input the following command.

sudo nano /var/www/html/test.php

This command will open nano editor with a blank test.Hypertext Preprocessor file for enhancing. The listing /var/www/html wherein we are growing our check PHP document is known as the webroot. This is in which Apache seems for the report asked inside the internet site URL with the aid of default if it has no longer been configured to appearance somewhere else. Check out Apache Ubuntu documentation web page for facts about its configuration. Also, you want root privileges with a purpose to write to this directory. We have used sudo before our command. Now enter the subsequent textual content in opened editor:


After entering this article press Ctrl + X (or CMD + X if you are on Mac), after which Y, after which hit ENTER. This will save the record and go out the editor. Now open following internet address on your browser


You should see a page that looks like this:

The phpinfo() feature we called internal our check.Php script presentations statistics approximately the PHP installation and its configuration. Now remove this check record by way of entering following command:

sudo rm /var/www/html/test.php
It may be very critical to get rid of this take a look at file after checking installation due to the fact it could help an attacker advantage essential statistics about the server configuration.

Install Linux, Apache, MySQL, PHP,Conclusion

You have learned the way to deploy LAMP on Ubuntu. After installation, you can replica your PHP documents to the server and install your net application. You can also installation phpMyAdmin to manage your databases on an internet interface. Be positive to test our other VPS tutorials and if you have any problems, remarks, ideas do allow us to understand inside the remarks sections. Happy coding!