Installing LAMP Stack


In this article we are going to look at installing the LAMP stack (Linux, Apache, Mysql, PHP) on a fresh install of Ubuntu 18 server. Before continuing you should have access to an Ubuntu server with root access. My article on Virtualization vs AWS ECS can help you get started if you need to install Ubuntu.

First off in the stack is Linux, and as mentioned, you’ll need an Ubuntu server with root access. Thats it for the “L” of a LAMP stack. Once you have Ubuntu ub, launch a terminal.

Next we will install Apache 2.4. To do so first lets run an update on our server to ensure we have the latest packages, and then install the Apache package. To do this you must have sudo priviledges:

sudo apt-get update sudo apt-get apache2

Installing Apache will start an Apache service, you can check with this:

sudo service apache2 status

● apache2.service - The Apache HTTP Server
   Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
  Drop-In: /lib/systemd/system/apache2.service.d
   Active: active (running) since Sun 2018-12-02 03:26:09 UTC; 54s ago
 Main PID: 2492 (apache2)
    Tasks: 55 (limit: 4704)
   CGroup: /system.slice/apache2.service
           ├─2492 /usr/sbin/apache2 -k start
           ├─2494 /usr/sbin/apache2 -k start
           └─2495 /usr/sbin/apache2 -k start

Dec 02 03:26:09 ip-10-0-0-212 systemd[1]: Starting The Apache HTTP Server...
Dec 02 03:26:09 ip-10-0-0-212 systemd[1]: Started The Apache HTTP Server.

And to be more specific check the line:

Active: active (running) since Sun 2018-12-02 03:26:09 UTC; 54s ago

Now Apache is installed and running, that takes care of the A in LAMP. Next up We’ll tackle MySql.

There are two different types of MySql that you can install, client or server. The MySql client is used when you want to connect to a MySql server, where the server is what will actually run a database. We want to install the server software:

sudo apt-get install mysql-server

Now Mysql is installed and running as a service, similar to Apache. To check MySql service:

sudo service mysql status

● mysql.service - MySQL Community Server
   Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
   Active: active (running) since Sun 2018-12-02 03:54:54 UTC; 2min 53s ago
 Main PID: 3776 (mysqld)
    Tasks: 27 (limit: 4704)
   CGroup: /system.slice/mysql.service
           └─3776 /usr/sbin/mysqld --daemonize --pid-file=/run/mysqld/

Dec 02 03:54:54 ip-10-0-0-212 systemd[1]: Starting MySQL Community Server...
Dec 02 03:54:54 ip-10-0-0-212 systemd[1]: Started MySQL Community Server.

Now with MySql installed, that takes care of the M in LAMP. Lastly we have the P, which is PHP. Lets install the latest version of PHP:

sudo apt-get install php

PHP isn’t a service like Mysql or Apache, but can be checked with the php command:

php --version

PHP 7.2.10-0ubuntu0.18.04.1 (cli) (built: Sep 13 2018 13:45:02) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
    with Zend OPcache v7.2.10-0ubuntu0.18.04.1, Copyright (c) 1999-2018, by Zend Technologies

And with that we have the entire LAMP stack, Linux, Apache, MySql, and PHP.

Bonus - Lightsail

With Amazon Web Services Lightsail service we can launch an EC2 instance that is pre-configured LAMP stack. The process is similar to launching an EC2 instance, but instead of dealing with the intricacies of launching a new instance like setting up a VPC and security groups, Lightsail offers a simple GUI to launch a pre-configured instance.

Start by logging into AWS and visiting the Lightsail page.

LAMP stack with Lightsail

Select the region you want to run your Lightsail instance in.

LAMP stack with Lightsail

To install the LAMP stack, select LAMP(PHP 7). Notice there are other handy pre-configured instance types including Wordpress and NodeJS.

LAMP stack with Lightsail

Give your instance a name and optionally some tags to help identify your new Lightsail instance

LAMP stack with Lightsail

And finally Create Instance

You’ll now have a Lightsail instance running LAMP stack similar to the server setup in the beginning of this article.

comments powered by Disqus
Social Media