Linux serverlinux web serverNETWORK ADMINISTRATIONS

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

Introduction

A “LAMP” stack is a group of open source software that is typically installed together to enable a server to host dynamic websites and web apps. This term is actually an acronym which represents the Linux operating system, with the Apache web server. The site data is stored in a MySQL database, and dynamic content is processed by PHP.

In this guide, we’ll get a LAMP stack installed on an Ubuntu 16.04 Droplet. Ubuntu will fulfill our first requirement: a Linux operating system.

Step 1: Install Apache and Allow in Firewall

#sudo apt-get update
#sudo apt-get install apache2

Set Global ServerName to Suppress Syntax Warnings

Next, we will add a single line to the /etc/apache2/apache2.conf file to suppress a warning message. While harmless, if you do not set ServerName globally, you will receive the following warning when checking your Apache configuration for syntax errors:

Open up the main configuration file with your text edit:

#sudo nano /etc/apache2/apache2.conf

Adjust the Firewall to Allow Web Traffic

Next, assuming that you have followed the initial server setup instructions to enable the UFW firewall, make sure that your firewall allows HTTP and HTTPS traffic. You can make sure that UFW has an application profile for Apache like so:

#sudo ufw app list

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

#sudo ufw app info “Apache Full”

Step 2: Install MySQL

Now that we have our web server up and running, it is time to install MySQL. MySQL is a database management system. Basically, it will organize and provide access to databases where our site can store information.

#sudo apt-get install mysql-server

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:

Warning: Enabling this feature is something of a judgment call. If enabled, passwords which don’t match the specified criteria will be rejected by MySQL with an error. This will cause issues if you use a weak password in conjunction with software which automatically configures MySQL user credentials, such as the Ubuntu packages for phpMyAdmin. It is safe to leave validation disabled, but you should always use strong, unique passwords for database credentials.

#sudo mysql_secure_installation

Step 3: Install PHP

PHP is the component of our setup that will process code to display dynamic content. It can run scripts, connect to our MySQL databases to get information, and hand the processed content over to our web server to display.

#sudo apt-get install php libapache2-mod-php php-mcrypt php-mysql

This should install PHP without any problems. We’ll test this in a moment.

In most cases, we’ll want to modify the way that Apache serves files when a directory is requested. Currently, if a user requests a directory from the server, Apache will first look for a file called index.html. We want to tell our web server to prefer PHP files, so we’ll make Apache look for an index.php file first.

To do this, type this command to open the dir.conf file in a text editor with root privileges:

#sudo nano /etc/apache2/mods-enabled/dir.conf

After this, we need to restart the Apache web server in order for our changes to be recognized. You can do this by typing this:

#systemctl restart apache2

Install PHP Modules

To enhance the functionality of PHP, we can optionally install some additional modules.

To see the available options for PHP modules and libraries, you can pipe the results of apt-cache search into less, a pager which lets you scroll through the output of other commands:

#apt-cache search php- | less

Use the arrow keys to scroll up and down, and q to quit.

For example, to find out what the php-cli module does, we could type this:

apt-cache show php-cli

If, after researching, you decide you would like to install a package, you can do so by using the apt-get install command like we have been doing for our other software.

If we decided that php-cli is something that we need, we could type:

# sudo apt-get install php-cli

Step 4: Test PHP Processing on your Web Server
n order to test that our system is configured properly for PHP, we can create a very basic PHP script.

We will call this script info.php. In order for Apache to find the file and serve it correctly, it must be saved to a very specific directory, which is called the “web root”.

In Ubuntu 14.04, this directory is located at /var/www/html/. We can create the file at that location by typing:

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

This will open a blank file. We want to put the following text, which is valid PHP code, inside the file:

source

by IT Training and Tutorials

linux web server

38 thoughts on “How To Install Linux, Apache, MySQL, PHP (LAMP) stack on Ubuntu 16.04 And Ubuntu 16.10

  • For casinos and gambling, VPS and DEDIC from WELL-WEB NET are excellent. Prices from 490 rub(~8$). Normal percents with normal rates, traffic is not limited, management is convenient. When registering, you can use any data – they are not checked. It is enough to specify the rules of the mail – that would get access. Now the action goes – you pay for 6 months. – double the payment deadline! It remains quite a bit until the end! It turns out cheap and much better!

  • sudo nano /etc/apache2/mods-enabled/dir.conf when i put after php install it show command not found

  • its not working for the case that mysql connection string return no connection

  • Hi sir I have a problem ! When i am doing "apt-get install php libapache2-mod-php php-mcrypt php-mysql" then it is throwing an error i.e. "E: Could not get lock /var/lib/dpkg/lock – open (11: Resource temporarily unavailable)
    E: Unable to lock the administration directory (/var/lib/dpkg/), is another process using it?
    " Please help me out of this

  • the music in this video is so AIDS, thx tho.

  • does normal saving of the php file in /var/www/html gives us permisssion ???????

  • During mysql installation,for me it didnt open package configuration tab…does it make problem?

  • intersting – i did everythink like in tutorial. Everything works so geat but in the end when i try to show php page so just text (<?php phpinfo(); ?> appear. Where is a problem? i think something is wrong with my php client:(

  • Thank you for the video, it helped me a lot.
    could you please tell me which music did you use in this video?

  • Thanks for the video.This video helped me a lot to maintain my ubuntu mail server.I have ubuntu server from http://www.datasoft.ws.They are providing servers at cheap rate with low price and good technical support

  • Which way do you prefer; install Web Server directly as Local Environment or using Vagrant?

  • could you please help???
    apache2ctl configtest
    /usr/sbin/apache2ctl: 165: /usr/sbin/apache2ctl: /usr/sbin/apache2: not found
    Action 'configtest' failed.
    The Apache error log may have more information.

  • 5:29 there is no ip address in my case

    and you have ens33 and lo and my pc shows enp3s0 , lo and wlo1

    its confusing…

  • Thanks for the video! Can you make one where you show how to
    1- set up several sites on the server
    2- install https

  • When I want to save my ServerName in the apache2config, it tells me that I can do it. it says "permission denied" What should I do?

  • Hey !
    How could you build proprely a database initially created by using "mysql -u root -p" and now without the root permission (removed by the apache_secure_installation) ?
    Regards.

  • hey thanks for the tutorial , though i cant see apache whenever i ran sudo ufw app list ..would appreciate if i could get a way out

  • Thank you so much this video clarified so many things after so many tries from various websites this one is very useful and easy to follow.

  • How did he save the server name? I can't get it to work

  • Good Perfect, I did followed each steps and installed LAMP on my server. I'm ready to create my First WEB aplication. Thanks a LOT

Comments are closed.