[Tutorial #4] Setting up LAMP in Technology Stack

[Tutorial #4] Setting up LAMP in Technology Stack

Commands Summary:

//update linux

#> sudo apt-get update      //update package repositories information

#> sudo apt-get upgrade     //install package upgrades

//install apache2

#> sudo apt-get install apache2

//install php

#> sudo apt-get install php5 libapache2-mod-php5 php5-mcrypt

//install mysql

#> sudo apt-get install mysql-server php5-mysql

//install phpmyadmin

#> sudo apt-get install phpmyadmin

//in case thing went wrong, remove installed package and its configuration file(s)

#> sudo apt-get purge package_name

Introduction

In last tutorial (#3) we setup our network and server hardware. Now is the time to go into the server and build the software components of our technology stack. For WordPress we need the following four basic software:

  1. Linux operating system: here we assume we use Ubuntu Linux. It should already be installed on your server. What you need to do is to configure it.
  2. The Apache2 web server: we need this so our server can listen to web requests and responds them with WordPress application.
  3. The PHP language: this is because WordPress is written in PHP. We need to install this so the server can understand it.
  4. The MySQL database: as WordPress uses MySQL to store/retrieve data.

Together these four are called the LAMP stack, and is widely used for web applications beyond WordPress.

Screenshot_2016-08-29-23-03-47-1

LAMP icons

Prerequisites:

This tutorial assumes you have the following basic programming skills:

  • Familiar with linux command line operation. You can learn the basics via course like this.
  • Knows how to remotely login to a server.

Make Linux Update-to-Date

Whenever we want to install new software package in linux, the first thing to do is to make sure:

  1. Package repositories are up to date.
  2. Current installed packages are up to date.

No. 1 is to ensure the package installer (apt-get) can find and download the packages we want. No. 2 is to make sure we have the latest patches on our server.

Run the following two commands in order:

#> sudo apt-get update      //update package repositories information

#> sudo apt-get upgrade     //install package upgrades

The symbol #>  represents the command prompt and is not part of the command. If succeeded each command should exit without any errors.

Install Apache2

To install Apache2, simply run the command:

#> sudo apt-get install apache2

Command Explanation

It is worth to explain the above command as you will use it extensively. Here sudo means to execute the commands on its right as the super user or administrator. Linux requires to add sudo whenever you are running commands that change important system files. Doing so makes sure you won’t accidentally execute wrong commands and damage the system.

apt-get is the main package manager for Ubuntu. Adding install tag tells the manager to install a new package. apache2 is the package name for apache2.

You can install multiple packages at once with apt-get by:

#> sudo apt-get install package_1 package_2 ... package_n

Test Apache2

After the installation finishes we want to see if Apache2 works. To do so, first check your Internet connection is correctly set up:

  • Make sure your server’s firewall allows connection with port 80 (used by http connection, which is used by webpage requests). This is especially important for Amazon AWS, as the default setting for port 80 is not allowed.
  • If you cannot connect via your url, try to connect by your server’s IP address.

Type in your url or your IP address in any browser, and you should see the default Apache webpage:

Screenshot_2016-08-29-15-13-52-1

 Default Apache2 webpage.

Install PHP5

We want to install PHP next. To do so execute the following command:

#> sudo apt-get install php5 libapache2-mod-php5 php5-mcrypt

Here php5 is the main package.  libapache2-mod-php5  is the add-on module so apache2 can understand PHP5. php5-mcrypt is an encryption library for PHP5, and is useful for encrypting sensitive data in web applications.

Testing PHP5

You can test php5 by the following procedure:

  1. Go to the default webpage directory as shown on the apache2 default page (should be /www/var/html/ ). You should see the file index.html
  2. Move index.html to something like index.html.bup . Create a new file called index.php.
  3. In index.php type: phpinfo(); ?>
  4. Reload the browser. You should see the webpage becomes the PHP information page:

Screenshot_2016-08-29-15-51-19-1

Install MySQL

Finally we will install MySQL by the following command:

#> sudo apt-get install mysql-server php5-mysql

Upon installation you will be prompted to enter the password for the default administrator root user:

Screenshot_2016-08-29-16-03-24-1

Type in a secured password. Then you will be prompted to type it again. After that the program continues execution in the shell and finish.

Install PHPMyAdmin

Finally, unless you are familiar with SQL language, it is better to use a graphical interface for creating/changing databases. One such tool is PHPMyAdmin. It is a webpage-based tool for you to modify your MySQL databases.

WARNING:
Please do not rush through this step. The following prompt you will see “apache2” IS HIGHLIGHTED BUT NOT SELECTED!  You must hit “SPACE”, “TAB”, and “ENTER” to correctly install PHPMyAdmin with Apache2.

Execute the following command:

sudo apt-get install phpmyadmin

After this you will see this prompt. NOTICE THAT “apache2” IS HIGHLIGHTED BUT NOT SELECTED! You must hit “SPACE”, “TAB”, and “ENTER” to correctly install PHPMyAdmin with Apache2.

Screenshot_2016-08-29-16-23-16-1

Apache2 is NOT selected!

Screenshot_2016-08-29-16-28-08-1

Pressing [SPACE], Apache2 is selected.

After this you will need to enter root’s password you specified when installing MySQL. It will also ask a password for logging into PHPMyAdmin. If it asks whether to use “dbconfig-common” to configure database, select yes.

Test MySQL and PHPMyAdmin

To test PHPMyAdmin, type this into your browser:

your_domain_or_ip/phpmyadmin

You should see the login page.

Screenshot_2016-08-29-16-34-41-1

As of version 4.4.0.10-1, the default user is “root”. Enter the password you specified, and you should see the admin panel:

Screenshot_2016-08-29-16-37-36-1

Conclusion

Congratulation! Now you have completed installation of the basic LAMP (Linux, Apache, MySQL, PHP) stack. Next we will learn how to configure Apache2 /MySQL and install WordPress in 5 minutes.