Installing LAMP (Linux, Apache, MySQL, PHP) Stack on Ubuntu 14.04

This article explains the steps to install the LAMP software bundle on Ubuntu 14.04.

Blue Light Tech

LAMP

LAMP is a web service solution stack suitable for building highly dynamic web applications and web sites. It is open source software and the term LAMP is an acronym for the components of the bundle, which are as follows:

  • Linux operating system
  • Apache Web Server
  • MySQL database
  • PHP (sometimes substituted by Python or Perl)

Ubuntu

Ubuntu is a Linux-based operating system and uses the Unity desktop. After installing LAMP on Ubuntu, you can start using it for required purposes.

Ubuntu has a Package Manager, apt. The package manager maintains most of the software required for Ubuntu. You can download the latest LAMP packages using apt.

Prerequisites

The prerequisites to successfully install LAMP on Ubuntu 14.04 are as follows:

Setting up Non-Root User Account

Root user has higher privileges and permissions which this installation does not require. To reduce the chances of risk which may come with unwanted permissions, a non-root user with some root privileges is used for the installation.

To create a non-root user for the installation, perform the following:

  1. Open the terminal and log in as root user on Ubuntu server.
  2. Type the command
    adduser <username>

    Replace <username> with a name for the user. For example – tester.
  3. Type a password for the user.
  4. Retype the password.

    Following figure shows the password being updated for the new user.

  5. Type answers for the questions that appear on the terminal.
    These questions are optional and if you do not wish to provide answers, press the Enter key. The system asks for confirmation on the information provided.
  6. Press y to confirm the information.
  7. To add the user to the sudo group, run the command
    gpasswd –a <username> sudo

    Replace <username> with a name for the user.

    User is successfully added to the sudo group.

Installing LAMP

LAMP installation comprises the following tasks:

  1. Installing Apache
  2. Installing MySQL
    1. Creating Directory and securing the database
  3. Installing PHP
    1. Updating dir.conf file
    2. Installing PHP Modules
  4. Verifying the Installation

Installing Apache

To install Apache Web Server on Ubuntu 14.04, perform the following:

  1. Log in to the terminal as the user performing the installation.
  2. To get an update of the packages, run the command -
    sudo apt-get update

    System gets the updates and displays the message as shown the following figure.

  3. To install the Apache package, run the command
    sudo apt-get install apache2
    The system asks for confirmation on the installation.
  4. Press y to confirm the installation. When the installation is successful, the terminal displays a message as Starting web server apache2.

Installing MySQL

    To install MySQL database on Ubuntu 14.04, perform the following:

  1. Log in to the terminal as user performing the installation.
  2. Run the command
    sudo apt-get install mysql-server php5-mysql
    The system asks for confirmation on the installation.
  3. Press y to confirm the installation.
    System prompts you to provide a root password for the database.
  4. Type a strong password for MySQL root user.
  5. Retype the password to confirm.
    MySQL database is created.

Creating Directory and Securing the Database

After installing the database, you must create a directory structure for the database to store information. And the database must be made secure so that you can start using it for storing required data.

Perform the following:

  • To create the database directory, run the command
    sudo mysql_install_db
  • To secure the database, perform the following:
    • Run the command
      sudo mysql_secure_installation
    • Type the MySQL root password provided during the database installation.
      System asks if you want to change the root password.
    • Press n if you do not want to change the MySQL root password.
      System prompts some more questions.
    • Press Enter for next four questions –
      • Remove anonymous users?
      • Disallow root login remotely?
      • Remove test database and access to it?
      • Reload privilege tables now? System shows the Installation Secure message. The database is now secure for storing data.

Installing PHP

    To install PHP on Ubuntu 14.04, perform the following:

  1. Log in to the terminal as the user performing the installation.
  2. Run the command
    sudo apt-get install php5 libapache2-mod-php5 php5-mcrypt
    The system asks for confirmation on the installation.
  3. Press y to confirm the installation.
  4. PHP is successfully installed on the system.

Updating dir.conf file

The dir.conf file structure defines the sequence in which Apache serves directories when a user makes a request. Based on the default configuration, Apache looks for index.html when a request is made. If you want to make Apache first refer PHP files, then you must edit the configuration to move index.php to the first in the structure.

To update the dir.conf file, perform the following:

  1. Run the command
    sudo nano /etc/apache2/mods-enabled/dir.conf
    The dir.conf file opens. The index.php file must be moved to the first position after DirectoryIndex specification.
  2. Move index.php file to the position as shown in the following figure. Use the help provided on the screen to move the file.
  3. Press Ctrl+X to save and exit the dir.conf file.
  4. Press y to confirm saving the file.
  5. Restart Apache web server for the update to be registered. Run the command
    sudo service apache2 restart

Installing PHP Modules

PHP has some modules and libraries available which enhance the functionality of PHP. You can choose the required packages, based on your requirement, and install these modules.

To install PHP modules, perform the following:

  1. To view the list of available PHP modules, run the command
    apt-cache search php5-
    System displays the list of available PHP modules and a short description of each module, as shown in the following figure.
  2. To get further details of a module, run the command
    apt-cache show <package name>

    Replace <package name> with the name of the required package for the PHP module. For example, to get information about the package php5-mongo, run the command

    apt-cache show php5-mongo
    The system displays information as shown in the following figure.
  3. To install the required PHP module, run the command
    sudo apt-get install <package name>
    Replace <package name> with the name of the required package.

    Note: You can install multiple packages at once by providing the package names with a space. For example,

    sudo apt-get install <package1> <package2> <package3>

    After completing these steps, LAMP installation is complete on the system. You can start using it for required purposes.

Verifying the Installation

To verify if the installation is successful, you can create a basic PHP script and check if the web server can display the correct content generated by the PHP script.

Perform the following:

  1. Log in to the terminal.
  2. Run the command
    sudo nano /var/www/html/info.php
    to create the info.php file.
  3. Type the following into the file.
    <?php
    phpinfo();
    ?>
  4. Save and close the file.
  5. Type http://<server_domain_name_or_IP>/info.php in your browser’s address bar.
    Replace <server_domain_name_or_IP> with the domain name or public IP address of your server.
    You will see a PHP web page showing information about your server. This shows that your installation is successful.

    Note: Remove the info.php file by using the command

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


25 Comments


Ulysses - 26/05/2018 13:59:18

A staff restaurant https://www.drugonsale.com kamagra Forced to make a roster move by Gattis' return, the Braves sent center fielder B.J. Upton to the 15-day disabled list retroactive to Saturday to preserve their already shorthanded bench. The team determined that the strained right adductor muscle Upton sustained on Friday night would need the longest recovery time of the three injuries to Braves starting outfielders from this weekend's series.


Judi - 12/05/2018 12:47:32

rLyp8u https://www.genericpharmacydrug.com


Judi - 12/05/2018 12:28:42

hoUcXF https://www.genericpharmacydrug.com


mike11 - 18/04/2018 01:41:39

IjieHz https://www.genericpharmacydrug.com


mike11 - 17/04/2018 23:42:58

uFJwU4 https://www.genericpharmacydrug.com


mike11 - 16/04/2018 16:31:05

B2Mygn https://www.genericpharmacydrug.com


HolaBromz - 19/03/2018 12:22:26

http://google0123.com/


Wyatt - 08/02/2018 09:38:22

Youth,mens,womens cheap sport apparel online,find authentic quality https://goo.gl/wGoQry


GoldenTabs - 08/01/2018 23:22:43

PKMXKd https://goldentabs.com/


GoldenTabs - 08/01/2018 13:48:26

DW9725 https://goldentabs.com/


JimmiNu - 10/09/2017 11:28:41

XKQXpp http://www.FyLitCl7Pf7ojQdDUOLQOuaxTXbj5iNG.com


JimmiXzSq - 20/05/2017 19:39:45

WCsud0 http://www.LnAJ7K8QSpkiStk3sLL0hQP6MO2wQ8gO.com


JimmiXzSq - 20/05/2017 06:52:18

DFKX9z http://www.LnAJ7K8QSpkiStk3sLL0hQP6MO2wQ8gO.com


JimmiXzSq - 20/05/2017 05:59:50

ST4xr0 http://www.LnAJ7K8QSpkiStk3sLL0hQP6MO2wQ8gO.com


JimmiXzSq - 18/05/2017 23:06:12

T6dUgi http://www.LnAJ7K8QSpkiStk3sLL0hQP6MO2wQ8gO.com


JimmiXzSq - 18/05/2017 00:14:56

Pj1jCB http://www.LnAJ7K8QSpkiStk3sLL0hQP6MO2wQ8gO.com


Barnypok - 01/04/2017 09:50:36

QOAtoI http://www.LnAJ7K8QSpkiStk3sLL0hQP6MO2wQ8gO.com


Barnypok - 01/04/2017 05:44:34

XIN6qx http://www.LnAJ7K8QSpkiStk3sLL0hQP6MO2wQ8gO.com


Barnypok - 31/03/2017 23:27:16

uSFjpS http://www.LnAJ7K8QSpkiStk3sLL0hQP6MO2wQ8gO.com


Barnypok - 31/03/2017 18:41:25

j9TYPZ http://www.LnAJ7K8QSpkiStk3sLL0hQP6MO2wQ8gO.com


Julie - 25/02/2017 21:45:13

Great article. Another approach would be to use professional Linux management services. I contacted https://linuxhostsupport.com and they did all of this for me.


Margareta - 24/02/2017 02:38:05

Finally! The long days of look for some respectable info regarding %BT% complete!

Here I located things I need to have. May possibly I use this particular blog post in the form of origin within my following assessment

http://en.gravatar.com/jessicawestrick?


JimmiXzSw - 19/02/2017 07:49:38

st4fzb http://www.FyLitCl7Pf7ojQdDUOLQOuaxTXbj5iNG.com


Toi - 20/12/2015 22:21:16

Perceft answer! That really gets to the heart of it!


Patrick Dawson - 30/10/2015 16:29:50

Incredibly useful article guys! LAMP server is now up and running :)