2017-03-07

You have been asked to create a LAMP stack, whether you’re thinking “Lamp stack, as in lights and bulbs” or “Ok let’s build a web server” this guide will help get you working quickly.

First for those that do not know a LAMP stack, also known simply as LAMP, is an acronym for a Linux/UNIX server with Apache as the server engine, MySQL/MariaDB as the database engine and PHP as the primary server-side script language.

These steps are based on RHEL 7.2/7.3 but should work for all versions of RHEL with minimal changes.

Just a couple things that you will need to be ready:

A decent Internet connection.

A non-production server to use with this guide.

This guide assumes that the server was installed with minimal options and is properly registered with a Red Hat subscription.

Access to the server that allows you Sudo (admin) access.

Depending on your organizational needs your server may have a graphical user interface (GUI) or you may simply have terminal access. With either option, it is suggested that you go through this guide first on a non-production server in case you need to go through it a couple times.

If you have a GUI, go to the “Applications” menu, then within the “Utilities” sub-menu find the “Terminal” application and open it.

Within Terminal (whether in the GUI or through SSH) follow these steps, to make things easier you can copy and paste the commands into the Terminal window.

NOTE:

With the yum commands below, this guide does not automatically install any piece of the LAMP stack. After you understand what you are doing, you can use the “-y” command to automatically install.

LAMP Installation Steps

Check Red Hat registration, the script below will help with that.

If you are properly registered, you will receive a message “Properly Registered” otherwise you will receive prompts to type in the Red Hat username and password along with the hostname of the server.

Update System first.

Install useful applications

Install LAMP components.

Enable Services to have them load at startup.

Open Firewall for HTTP and HTTPS.

Create simple PHP Info page to verify PHP is working in Apache.

The main purpose of this file is to make sure that PHP is working in Apache but it is also a good file to review for each project to make sure you have all needed PHP modules/extensions installed.

Add PHP configuration into Apache.

This is a needed step in order to have PHP handled properly in Apache.

Secure MariaDB/MySQL.

This is a needed step to protect your MariaDB/MySQL server. This command will first start the service then ask a series of questions, based on the needs of the project the answers will vary.

This is what you will see

At this point, tap enter/return, as you shouldn’t have a root password at this point

At this point, type Y (case can be lower or upper) and tap enter/return

You will need to type in a password then confirm the password. NOTE: This is your “god” password over all of your MariaDB system so it should be a difficult to guess password

In most cases, you want to remove unauthenticated users so type Y (case can be lower or upper) and tap enter/return

In most cases you want to remove remote “god” root access so type Y (case can be lower or upper) and tap enter/return

If this is a development box to start learning how to do things with MariaDB/MySQL you could say no to this but in most cases type Y (case can be lower or upper) and tap enter/return

In most cases type Y (case can be lower or upper) and tap enter/return

You are now done and will see something like this

Start Apache.

Load your site, if you are in a GUI, depending you may or may not have an internet browser on your machine, if you have a browser you can open it and simply go to http://localhost/info.phpIf you are in SSH/Terminal, the code below should load HTML of the default site for you if everything is working

At this point, you should have a working HTTP LAMP stack but it will only run one website.

Multi-Site Installation Steps

Very few LAMP stacks are set up specifically to run only one website. The steps below will help you get your server serving multiple websites, again with little effort on your part.

For multi-site to work we need to change SELinux to run in permissive mode.
NOTE: Check with your company’s IT security, some companies may have a problem with this where others may have no problem with it.Running the below script will change the setting for you and then restart the server.

Create a file “websites.csv”, within this file we will define the additional sites for the server.

This websites.csv file has some logic tied to it in that if you do not define the HTTPS_Port, SSLCertificateFile, and SSLCertificateKeyFile your site will simply be HTTP and not a secure site (HTTPS)

This script below will create the header of the CSV for you and then load the file in the nano text editor.

Type in the values remembering to add a comma as the delimiter (make sure not to add spacing).

When you are done hold down the Control/Ctrl key and type the X key to close the file, the system will ask you if you want to save, type Y for yes or type N for no then tap the Enter/Return key.

Here is an example of what the final file could look like

SSL CertificatesWhere you put your SSL certificate files may differ than this guide. The guide will focus on the location of the files as /etc/httpd/sslMake sure you have the crt and key files both in the /etc/httpd/ssl directory (or the directory you choose).

Set some basic variables for the following steps

OPTIONAL – Remove GUI Desktop

Create Web Developer Group

In the situation that you have multiple web developers a web developer group is helpful.

Configure Apache to handle multiple sites

Let the CSV define the additional sites

Reassign permissions to the /var/www/ directory to allow the webdev group read and write access

Test Configuration

Restart Apache Service

Show more