Methods to Set up Linux, Apache, MySQL, PHP (LAMP) stack on Ubuntu 16.04

How to Install Linux, Apache, MySQL, PHP (LAMP) stack on Ubuntu 16.04

This tutorial teaches the best way to set up LAMP on Ubuntu 16.04 VPS. LAMP is an acronym for Linux, Apache, MySQL, PHP. It’s a well-liked stack for creating and deploying dynamic net functions.

On this stack, Linux serves because the working system for the net utility. MySQL is used because the database. Apache is used as the net server. PHP is used to course of dynamic content material. In another variants of this stack, Perl is used as an alternative of PHP or Python. Nevertheless, for this tutorial, we’re going to set up PHP, as it’s the most well-liked alternative for this stack.

What you’ll want

Earlier than you start with Ubuntu LAMP tutorial, you will want the next:

It’s endorsed to make use of a sudo person as an alternative of the root person to put in software program for safety functions. In case you have root entry to your VPS server you may create a sudo person with following instructions

adduser 

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

usermod -aG sudo 

Change to this new person.

sudo su - 

How LAMP works

Each time an online web page request arrives at a server it’s handed on to an utility referred to as net server, in our case Apache. Apache appears to be like for the file being requested within the URL of the request and passes this info to the PHP interpreter. It executes the logic written in that file, pulls information from the MySQL database if wanted and generates an online web page. Apache, our net server sends this generated net web page to the shopper. This entire course of is executed with some variations each single time while you request an online web page from a LAMP server.

Step 1 – Putting in Apache Internet Server

Earlier than starting the set up, replace your system and be sure you have newest packages.

sudo apt-get replace
sudo apt-get improve

Now set up Apache2 with the next command

sudo apt-get set up apache2

Checking your set up

To examine the set up, open your browser in your native machine and enter the next handle in handle bar.

http://

For instance, in case your VPS IP handle is 195.110.59.211 your handle must be:

http://195.110.59.211

You need to see a web page that appears like this:

Installing LAMP on Ubuntu - Apache 2 Default Page

 

Observe: For those who don’t know your VPS’s IP handle, the quickest solution to discover it’s by operating following the command. This command prints the general public IP handle of your VPS.

dig +quick myip.opendns.com @resolver1.opendns.com

Troubleshooting your set up

For those who didn’t see the above picture don’t fear, you may need enabled the firewall. You must allow Apache to serve net requests on port 80 and port 443 in your firewall. Set up UFW.

sudo apt-get set up ufw

Then permit HTTP and HTTPS visitors by way of the firewall.

sudo ufw permit http
sudo ufw permit https

This command allows HTTP and HTTPS visitors by way of the firewall. UFW is command line utility referred to as Uncomplicated Firewall. It’s used to handle and make guidelines for Linux firewall. Now enter your VPS Ip handle in your browser to examine the set up. You may examine the standing of Apache server with the next command.

sudo systemctl standing apache2

Step 2 – Putting in MySQL

MySQL is the database to your utility. To put in MySQL enter the next command.

sudo apt-get set up mysql-server

Throughout set up, it’ll immediate you for the password of the foundation person. Ensure that to make use of a robust password. Don’t depart it clean.

Installing LAMP on Ubuntu - MySQL Password

The root person is the best privileged person of MySQL. Utilizing root person you may create different customers for the databases. It’s a good observe to create a separate person/function for the database of a brand new net utility. You may examine the standing of MySQL service with the next command.

sudo systemctl standing mysql

Instance output:

● mysql.service - MySQL Group Server
   Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
   Lively: energetic (operating) since Tue 2017-07-11 09:39:40 EDT; 1min 39s in the past
 Primary PID: 9579 (mysqld)
   CGroup: /system.slice/mysql.service
           └─9579 /usr/sbin/mysqld

Jul 11 09:39:39 abandoned-plate systemd[1]: Beginning MySQL Group Server...
Jul 11 09:39:40 abandoned-plate systemd[1]: Began MySQL Group Server.

Step 3 – Putting in PHP

PHP executes your utility. Set up PHP and further modules with the next command

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

This command will set up the newest secure model of PHP and a few further modules which might be required for net utility to work.

Step 3.1 – Checking your PHP set up

Now that you’ve got put in PHP, we are going to examine whether it is working correctly by making a take a look at file and opening it within the browser. First, set up the nano textual content editor.

sudo apt-get set up nano

Nano is a command line textual content editor and is less complicated to get began with for freshmen. Click on right here to learn to use the nano textual content editor. Now, enter the next command.

 sudo nano /var/www/html/take a look at.php

This command will open nano editor with a clean take a look at.php file for modifying. The listing /var/www/html the place we’re creating our take a look at PHP file is named the webroot. That is the place Apache appears to be like for the file requested within the web site URL by default if it has not been configured to look elsewhere. Try Apache Ubuntu documentation web page for details about its configuration. Additionally, you want root privileges to have the ability to write to this listing. We’ve used sudo earlier than our command. Now enter the next textual content in opened editor:


After getting into this textual content press Ctrl + X (or CMD + X if you’re on Mac), after which Y, after which hit ENTER. This may save the file and exit the editor. Now open following net handle in your browser

http:///take a look at.php

You need to see a web page that appears like this:

 

LAMP on Ubuntu Installed

The phpinfo() operate we referred to as inside our take a look at.php script shows details about the PHP set up and its configuration. Now take away this take a look at file by getting into following command:

sudo rm /var/www/html/take a look at.php

Observe: It is vitally essential to take away this take a look at file after checking set up as a result of it could assist an attacker acquire vital details about the server configuration.

Conclusion

You may have discovered the best way to set up LAMP on Ubuntu. After set up, you may copy your PHP information to the server and deploy your net utility. You may also set up phpMyAdmin to handle your databases on an online interface. Remember to examine our different VPS tutorials and when you have any issues, feedback, concepts do tell us within the feedback sections. Blissful coding!

Author

Prithviraj is a cybersecurity knowledgeable that loves a problem. When he is not managing servers and fixing safety flaws, he writes about it on numerous blogs.

Leave a Reply

Your email address will not be published. Required fields are marked *