Installation of LAMP stack Ubuntu

Install LAMP Stack

L-A-M-P refers to Linux, Apache, MySQL and PHP. Simply put this is a group of software suites that work in tandem to enable server hosting of websites or applications.

We will go through the installation of Ubuntu 18.04 server. I will assume you’ve acquired your favorite virtual machine for use in this tutorial.

First:

It’s best practice to have a non-root sudo account associated with your server. To quickly address this you simply need to type:

# adduser superuser

Enter a password associated with the new user you’ve created named superuser. The rest of the information you’re being asked to fill in is optional.

Grant user administrative privileges this will allow our superuser to enter the sudo command without having to switch to root to do so.

As root enter the following command:

# usermod -aG sudo superuser

The modifier:

  • -a type, –auth-type = type
  • G group, –group = group

Now you’ll be able to execute superuser priviledges from the new account you just created.

Second:

Set up your firewall.

Let’s see what is currently configured in your UFW (uncomplicated firewall)

# ufw app list

This will produce a list of available applications.

Make sure SSH is allowed so we are able to log back in using Putty or WinSCP.

# ufw allow OpenSSH

Now let’s enable the firewall again using:

# ufw enable

Press “y” to proceed. Now type:

# ufw status

You should now see OpenSSH is allowed from anywhere. Make sure you have a strong password.

Third:

Ok, so we have a virtual machine configured with a superuser named “superuser” and our firewall is on and allowing SSH connections. Perfect.

Let’s install Apache2 and update our distribution of Ubuntu 18.04.

$ sudo apt update

$ sudo apt install apache2

Make sure our firewall (ufw) is configured to allow traffic for our shiny new apache installation.

$ sudo ufw allow in “Apache Full”

Forth:

Install MySQL. This is a database that sits on the third layer of our LAMP stack.

$ sudo apt install mysql-server

Enter “Y” to continue.

Now that is complete we are going to run a secure installation of MySQL:

$ sudo mysql_secure_installation

mysql_secure_installation is a shell script available on Unix systems, and enables you to improve the security of your installation in the following ways:

  • You can set a password for root accounts.
  • You can remove root accounts that are accessible from outside the local host.
  • You can remove anonymous-user accounts.
  • You can remove the test database, which by default can be accessed by anonymous users.

VALIDATE PASSWORD PLUGIN

The above is a configuration you’re going to be prompted about. You should research the best option for your uses and continue based on your own judgement. I continue without enabling.

I prefer to use a password when connecting to MySQL. We need to change the authentication method from auth_socket to mysql_native_password.

Open your MySQL:

$ sudo mysql

Type the following command:

mysql> SELECT user,authentication_string,plugin,host FROM mysql.user;

You’ll see that the user root is authenticated via auth_socket plugin. Let’s change this so we use a password instead:

mysql> ALTER USER ‘root‘@’localhost‘ IDENTIFIED WITH mysql_native_password BY ‘password‘;

Change password to your liking and hit enter.

Reload the server using:

mysql> FLUSH PRIVILEGES;

Let’s exit and move on to step 5.

mysql> exit

Fifth:

Install PHP. This is the step where we get the real satisfaction of minting our own digital footprint with dynamic content. We’ll connect it to our MySQL database to get CX information it will also server the processed content to our web server Apache2.

$ sudo apt install php libapache2-mod-php php-mysql

We need to change the priority by which our server looks for files, by default it searches out HTML files first. We will open up a text editor to change the order:

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

This will diplay:

<IfModule mod_dir.c>
    DirectoryIndex index.html index.cgi index.pl index.php index.xhtml index.htm
</IfModule>

Move index.php to BEFORE index.html.

It will look like this:

<IfModule mod_dir.c>
    DirectoryIndex index.php index.html index.cgi index.pl index.xhtml index.htm
</IfModule>

Ctrl+X to save. Confirm your choice by pressing “Y”, hit enter.

Restart Apache2.

$ sudo systemctl restart apache2

Check the status of Apache2 to make sure it’s running:

$ sudo systemctl status apache2

Press “Q” to exit the output of systemclt status apache2.

Sixth

Setup virtual hosts. This allows for hosting more than a single domain on your server.

IN THIS STAGE REPLACE “PLACEHOLDER” WITH YOUR DOMAIN NAME.

Let’s create the directory for our domain:

$ sudo mkdir /var/www/PLACEHOLDER

Change ownership values:

$ sudo chown -R $USER:$USER /var/www/PLACEHOLDER

Permissions of web roots have been unaffected probably but to be sure type:

$ sudo chmod -R 755 /var/www/your_domain

Now we are going to make a new directive file associate with your domain PLACEHOLDER.

$ sudo nano /etc/apache2/sites-available/PLACEHOLDER.conf

We need to configure this new directive file in order to server our content appropriately. This is almost identical to the original except we will update it with our newly created directory and domain name.

<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    ServerName PLACEHOLDER
    ServerAlias www.PLACEHOLDER
    DocumentRoot /var/www/PLACEHOLDER
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

Server Name: establishes the base domain that should match for this virtual host definition.

Server Alias: defines further names that should match as if they were the base name including the suffix (.ca .com .net).

Document Root: We just created this directory to serve our content.

Save and Close the Document.

We need to enable a2ensite tool because we are using a virtual host configuration:

$ sudo a2ensite PLACEHOLDER.conf

Disable the default site defined in 000-default.conf:

$ sudo a2dissite 000-default.conf

Test for configuration errors:

$ sudo apache2ctl configtest

Out should say:

Syntax OK

Restart Apache2:

$ sudo systemctl restart apache2

Test your site by typing into your URL your domain http://PLACEHOLDER. You should have a success message.

We have installed the LAMP stack!

Next steps:

Installation of WordPress

TLS/SSL Certificates

By Published On: January 19th, 2016Categories: software, Technology, Tutorial, WordpressViews: 5571040 words

Spread the knowledge!

STAY IN THE LOOP

Subscribe to our free newsletter.

Related Posts

View all
  • Musings of a Project Manager 1

    Continue reading
  • Okangan College Professorship Pt. 1

    Continue reading
  • Migrate WordPress server to another server;

    Continue reading
  • Let’s Encrypt Ubunutu

    Continue reading