Linux LAMP Installation Guide

Introduction

LAMP stands for Linux, Apache, MySQL and PHP.

However, over the years LAMP refers to any deployment stack involving similar components such as the replacement of PHP with Python.

Additionally, the component does not necessarily have to start with the same letter such as MySQL can be easily replaced by PostgreSQL.

The following is a quick start guide to setup the LAMP environment using Linux Debian, such as Ubuntu.

WARNING: You must have root access in order to continue as Linux will prompt for a password.

Update

To make sure that the latest package list is used run the following.

~$ sudo apt-get update

Apache

Apache will be used as the web server so that the PHP web pages can be published through a web browser.

It is also one of the most popular open-source web servers to date and supported by a large community.

1. Open a terminal window and enter the following command:

~$ sudo apt-get install apache2

Enter the root password and the following is displayed.

LAMP Apache - Installation

2. Enter Y to accept installing the dependencies and continue the installation.

The progress of the installation is displayed and the prompt should return.

LAMP Apache - Installation Complete

3. Verify the Apache server is running by opening a web browser and navigating to http://localhost

LAMP Apache - Verify

NOTE: At anytime the following can be entered from the terminal to restart the Apache server. The command is useful to troubleshoot a web application.
~$ sudo /etc/init.d/apache2 restart

MySQL

The database will be used to store the application data.

1. Open a terminal window and enter the following command:

~$ sudo apt-get install mysql-server

Enter the root password and the following is displayed.

LAMP MySQL - Installation

2. Enter Y to accept installing the dependencies and continue the installation.

The progress of the installation is displayed and the MySQL root password prompt should be displayed.

LAMP MySQL - Password prompt

3. Enter the MySQL root user password and enter it again on the next screen to continue the installation.

4. Verify the installation by checking the version number of MySQL from the terminal.

~$ mysql --version

LAMP MySQL - Version

5. The following is optional, but highly recommended to provide added security to the MySQL database server.

~$ sudo mysql_secure_installation

6. Enter the following at the specified prompts:

  • Enter current password for root (enter for none): root password
  • Change the root password? N
  • Remove anonymous users? Y
  • Disallow root login remotely? Y
  • Remove test database and access to it? Y
  • Reload privilege tables now? Y

PHP

This enables PHP development and operation to be possible.

The PHP components and Apache libraries are required in order to render PHP correctly in a web browser.

1. Open a terminal window and enter the following command:

~$ sudo apt-get install php5 libapache2-mod-php5

Enter the root password and the following is displayed.

LAMP PHP - Installation

2. Enter Y to accept installing the dependencies and continue the installation.

The progress of the installation is displayed and the prompt should return.

LAMP PHP - Complete

3. Verify the installation by checking the PHP version.

~$ php -v

LAMP PHP - Version

  1. Verify that PHP is working correctly.
~$ php -r 'echo "\n\nPHP is working fine.\n\n\n";'

The following output should be displayed.

PHP is working fine.  

References


comments powered by Disqus