How one can 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 easy methods 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 internet purposes.

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 a substitute of PHP or Python. Nevertheless, for this tutorial, we’re going to set up PHP, as it’s the preferred alternative for this stack.

What you’ll want

Earlier than you start with Ubuntu LAMP tutorial, you’ll need the next:

It’s endorsed to make use of a sudo consumer as a substitute of the root consumer to put in software program for safety functions. You probably have root entry to your VPS server you may create a sudo consumer with following instructions

adduser 

The above command creates a consumer along with your offered username. Now make the newly created consumer a sudoer.

usermod -aG sudo 

Swap to this new consumer.

sudo su - 

How LAMP works

At any time when an online web page request arrives at a server it’s handed on to an utility known as internet server, in our case Apache. Apache seems to be for the file being requested within the URL of the request and passes this data 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 internet server sends this generated internet web page to the consumer. This complete 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 to 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 tackle in tackle bar.

http://

For instance, in case your VPS IP tackle is 195.110.59.211 your tackle needs to be:

http://195.110.59.211

You must see a web page that appears like this:

Installing LAMP on Ubuntu - Apache 2 Default Page

Word: Should you don’t know your VPS’s IP tackle, the quickest approach to discover it’s by working following the command. This command prints the general public IP tackle of your VPS.

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

Troubleshooting your set up

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

sudo apt-get set up ufw

Then enable HTTP and HTTPS site visitors by way of the firewall.

sudo ufw enable http
sudo ufw enable https

This command permits HTTP and HTTPS site visitors by way of the firewall. UFW is command line utility known as Uncomplicated Firewall. It’s used to handle and make guidelines for Linux firewall. Now enter your VPS Ip tackle 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 in your utility. To put in MySQL enter the next command.

sudo apt-get set up mysql-server

Throughout set up, it can immediate you for the password of the foundation consumer. Make sure that to make use of a powerful password. Don’t go away it clean.

Installing LAMP on Ubuntu - MySQL Password

The root consumer is the best privileged consumer of MySQL. Utilizing root consumer you may create different customers for the databases. It’s a good observe to create a separate consumer/position for the database of a brand new internet 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: lively (working) since Tue 2017-07-11 09:39:40 EDT; 1min 39s in the past
 Foremost 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 additional modules which can be required for internet utility to work.

Step 3.1 – Checking your PHP set up

Now that you’ve put in PHP, we’ll 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 simpler to get began with for newbies. Click on right here to discover ways 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 enhancing. 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 seems to be for the file requested within the web site URL by default if it has not been configured to look someplace else. Take a look at 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 have now used sudo earlier than our command. Now enter the next textual content in opened editor:


After coming 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 internet tackle in your browser

http:///take a look at.php

You must see a web page that appears like this:

 

LAMP on Ubuntu Installed

The phpinfo() operate we known 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 coming into following command:

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

Word: It is extremely essential to take away this take a look at file after checking set up as a result of it might assist an attacker achieve essential details about the server configuration.

Conclusion

You’ve gotten realized easy methods to set up LAMP on Ubuntu. After set up, you may copy your PHP information to the server and deploy your internet utility. You may also set up phpMyAdmin to handle your databases on an online interface. Be sure you examine our different VPS tutorials and you probably have any issues, feedback, concepts do tell us within the feedback sections. Pleased coding!

Author

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

Leave a Reply

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