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

7971-wqucxjmrzrwjmpxj

Introduction

A “LAMP” Linux Apache Mysql Php is group of software when you need to host static or dynamic web pages in your server. Linux as operating system, apache as web server to process user request, mysql databse to store data, and php to process dynamic content. Almost most CMS running on this LAMP stack. In this tutorial, we’ll guide to install a LAMP on an Ubuntu 16.04.

Prerequisites

Before you begin with this guide, you should at least have basic knowledge of linux, know basic shell command for linux, non-root user account with sudo privileges set up on your server.

Step 1 – Install Apache and Allow in Firewall

We can install apache using apt-get from official ubuntu repositories.
typing these commands below, since we used sudo , these operations below will get executed with root privileges

Test and Check apache config

If you got warning like these , it’s because we still not set ServerName, but if you got no warning, you can skip these step

Open main configuration file with nano:

Inside, at the bottom of the file, add a ServerName directive, pointing to your primary domain name.
If you do not have a domain name associated with your server, you can use your server’s public IP address

Save and test config again

We should get warning disappeared

Restart apache to implement config changes

Firewall configuration

Make sure that your firewall allows HTTP and HTTPS traffic that will be used for apache.

Output

If you look at the Apache Full profile, it should show that it enables traffic to ports 80 and 443:

Output

Allow incoming traffic for this profile

Check using your browser to see it’s can be accessed.

You should see the default Ubuntu 16.04 Apache web page. It should look something like this:

small_apache_default

Congratulations you have successfully install webserver and configuring firewall in ubuntu 16.04

Step 2 – Install MySQL Database server

We will install mysql database server using apt-get like apache before.

During the installation, your server will ask you to select and confirm a password for the MySQL “root” user. This is an administrative account in MySQL that has increased privileges. Think of it as being similar to the root account for the server itself (the one you are configuring now is a MySQL-specific account, however). Make sure this is a strong, unique password, and do not leave it blank.

When the installation is complete, we want to run a simple security script that will remove some dangerous defaults and lock down access to our database system a little bit. Start the interactive script by running these command below

You will be asked to enter the password you set for the MySQL root account. Next, you will be asked if you want to configure the VALIDATE PASSWORD PLUGIN.

Warning !! Answer No for no, we will not activated these plugins

At this point, your database system is now set up and we can move to next step.

Step 3 – Install PHP

PHP is the component to process dynamic content.We will install php run under the Apache server.
Like previous step before , we will install using apt-get

Configure apache config to read script php first using nano

Default configuration  will look like these

Change configuration like these

Save and restart apache webserver to apply configuration

Check apache status is running or not

Install PHP Modules
To get working with php script we will need some additional modules.
To see the available options for PHP modules and libraries, you can pipe the results of apt-cache search into less

Example result

In this example we will install php-cli and php-gd , execute command like these

Restart apache to take effect

 

Step 4 – Test PHP Processing on your Web Server

We will create basic php script for test purpose.
For apache’s default installation root directory should located at /var/www/html/
Create php  file using nano

Put these lines below to that file

Save and close nano

Open your browser and opwn your server address to check it’s working.

You should get page like these

small_php_info

Congratulations , you have successfully install LAMP in ubuntu 16.04

 

 

You may also like...

Leave a Reply

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