How to Install LAMP on Ubuntu 18.04

This guide shows how to install a LAMP stack on Ubuntu 18.04 (LTS).

What is a LAMP Stack

LAMP is a set of free software name acronyms that are commonly used together to run dynamic websites or servers.

  • L – Linux operating system
  • A – Apache, a HTTP and reverse proxy server
  • M – MySQL or MariaDB relational database management system
  • P – PHP programming language.

This series of tutorials will guide you through the steps necessary to install Apache, create Apache virtual hosts, generate a free Let’s Encrypt SSL certificate, install and secure MySQL and install PHP 7.2.

The detailed tutorials that are part of this series are listed at the end of this page.

If you are in a hurry and don’t want to read more detailed documentation you can install LAMP Stack on your Ubuntu 18.04 server by following our Quickstart section.

Requirements

Before, you must have an account with sudo privileges and make sure your Ubuntu 18.04 server can access the Internet.

Steps to install LAMP stack on Ubuntu 18.04

1. Installing Apache

Apache is available in Ubuntu repositories. Update the packages index and install Apache with the following commands:

sudo apt update && sudo apt install apache2

2. Installing MySQL

This step is to install the MySQL packages. run the following command:

sudo apt install mysql-server

When the installation is completed, run the mysql_secure_installation command to improve the security of the MySQL installation:

sudo mysql_secure_installation

You will be asked to set the root password, remove the anonymous user, restrict root user access to the local machine and remove the test database. You should answer “Y” (yes) to all questions.

If you want to install MariaDB instead of MySQL, check our tutorial for installation instructions.

3. Installing PHP

Ubuntu 18.04 LTS ships with the latest and greatest PHP version 7.2. To install PHP and several other most common PHP modules type:

sudo apt install php libapache2-mod-php php-opcache php-cli php-gd php-curl php-mysql

Once the PHP packages are installed restart the Apache service with:

sudo systemctl restart apache2

More Information

For more detailed instructions about each step, please consult the following tutorials.

Tutorials

  1. How to Install Apache on Ubuntu 18.04
  2. How To Set Up Apache Virtual Hosts on Ubuntu 18.04
  3. Secure Apache with Let’s Encrypt on Ubuntu 18.04
  4. How to Install MySQL on Ubuntu 18.04
  5. How to Install MariaDB on Ubuntu 18.04
  6. How to Install PHP on Ubuntu 18.04

Install LAMP stack on Ubuntu 18.04 [Quickstart]

This quickstart will show you how to install the whole LAMP stack in one line in a terminal run the command below on your ubuntu 18.04 server.

sudo apt install lamp-server^

This will install all the requisite packages and their dependencies.

While installing, one will be prompted to create a root user for the database. Select a strong password which is also easy to remember.

To verify whether Apache web server is running, run command:

systemctl status apache2

If it’s running, you’ll get the output below:

● 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
           └─apache2-systemd.conf
   Active: active (running) since Tue 2019-05-14 14:59:37 UTC; 1 day 10h ago
 Main PID: 8025 (apache2)
    Tasks: 6 (limit: 506)
   CGroup: /system.slice/apache2.service
           ├─8025 /usr/sbin/apache2 -k start
           ├─8032 /usr/sbin/apache2 -k start
           ├─8033 /usr/sbin/apache2 -k start
           ├─8034 /usr/sbin/apache2 -k start
           ├─8035 /usr/sbin/apache2 -k start
           └─8036 /usr/sbin/apache2 -k start

May 14 14:59:37 vm1 systemd[1]: Stopped The Apache HTTP Server.
May 14 14:59:37 vm1 systemd[1]: Starting The Apache HTTP Server...
May 14 14:59:37 vm1 apachectl[8011]: AH00558: apache2: Could not reliably determine the server's fully qualified
May 14 14:59:37 vm1 systemd[1]: Started The Apache HTTP Server.

To verify whether mysql server is running, run command:

systemct status mysql

If it’s running, you’ll get the output below:

● mysql.service - MySQL Community Server
   Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
   Active: active (running) since Wed 2019-05-15 10:10:49 UTC; 15h ago
 Main PID: 24384 (mysqld)
    Tasks: 28 (limit: 506)
   CGroup: /system.slice/mysql.service
           └─24384 /usr/sbin/mysqld --daemonize --pid-file=/run/mysqld/mysqld.pid

May 15 10:10:48 vm1 systemd[1]: Starting MySQL Community Server...
May 15 10:10:49 vm1 systemd[1]: Started MySQL Community Server.

To verify PHP is installed, run command:

php -v

If it’s running, you’ll get the output below:

PHP 7.2.17-0ubuntu0.18.04.1 (cli) (built: Apr 18 2019 14:12:38) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
    with Zend OPcache v7.2.17-0ubuntu0.18.04.1, Copyright (c) 1999-2018, by Zend Technologies

Conclusion

That’s It! In this article, we have explained how to install LAMP stack in Ubuntu 18.04. If you have any questions or thoughts to share, don’t forget to leave a comment to reach us.

Leave a Reply