How to Install the LAMP Stack on Ubuntu 18.04

Posted on by Lucas Stanley
Reading Time: 11 minutes

LAMP stack stands for Linux, Apache, MySQL, and PHP - a set of open source software installed on your server to host dynamic websites and applications. Each component of the LAMP stack has a distinct purpose:

  • Linux serves as the operating system.
  • Apache is the web server.
  • MySQL is for database storage and management.
  • PHP is for processing a website’s dynamic content.

While other tech stacks exist, this article guides you through how to install the LAMP stack on an Ubuntu 18.04 system.

Requirements

To follow and complete this tutorial, you will need the following:

  • A system with an Ubuntu 18.04 installation.
  • A non-root, sudo-enabled user account.
  • A configured firewall (usually set up by default in Ubuntu installs).
Note:
Before installing Ubuntu 18.04 on your system, make sure that at least 25 GB of free storage space is available. The minimum requirement is 5 GB for a minimal installation. Also, it is advisable to have a recent backup of your data before you proceed with installing or upgrading your operating system.

How to Install the LAMP Stack on Ubuntu 18.04 

Step 1: Install Linux

Install Ubuntu 18.04 on your server.

Initial Server Setup

Once Ubuntu 18.04 is installed, there are some additional steps to take before you are ready to install the LAMP stack on your Ubuntu system.

Create a New User

Once you log in to your system as a root user, you can create a new user with the following command. In this example, the name of the new user is john.

# adduser john

You will be prompted for a password for your newly-created account as well as a few more details that you can skip by pressing Enter. Make sure to use a strong password and don’t use the same one you might have used on another account.

root@ubuntu:~# adduser john
Adding user `john' ...
Adding new group `john' (1000) ...
Adding new user `john' (1000) with group `john' ...
Creating home directory `/home/john' ...
Copying files from `/etc/skel' ...
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
Changing the user information for john
Enter the new value, or press ENTER for the default
        Full Name []:
        Room Number []:
        Work Phone []:
        Home Phone []:
        Other []:
Is the information correct? [Y/n] Y
Granting Root Privileges

When you think about root privileges on a Linux system, think of administrative rights on a Windows OS. Granting root privileges to your new user allows them to perform administrative tasks such as editing configuration files or restarting your system without the need to log out and log back in as a root user.

Granting root privileges to your new account adds the user to the sudo group, allowing them to run commands as root by prefixing each command with sudo. To add your user to a sudo group, use the following command.

# usermod -aG sudo john

Here is the output.

root@ubuntu:~# usermod -aG sudo john
root@ubuntu:~# getent group sudo 
sudo:x:27:john

Once completed, proceed to the next step of installing Apache.

Step 2: Install Apache

Apache is a free and open source web server software that works with different operating systems, including Ubuntu 18.04. It is widely used, well-documented, and works great with PHP. Before we install Apache, it is essential to update the repositories. Use the following command to do so.

# sudo apt update

If this is the first time using the sudo command, you will be prompted for your root password. Once you input it and click Enter, you will see a similar output as below.

john@ubuntu:/root$ sudo apt update
[sudo] password for john:
Hit:1 http://nl.archive.ubuntu.com/ubuntu bionic InRelease
Get:2 http://nl.archive.ubuntu.com/ubuntu bionic-security InRelease [88.7 kB]
Get:3 http://nl.archive.ubuntu.com/ubuntu bionic-updates InRelease [88.7 kB]
Get:4 http://nl.archive.ubuntu.com/ubuntu bionic-backports InRelease [74.6 kB]
Get:5 http://nl.archive.ubuntu.com/ubuntu bionic-security/main Sources [260 kB]
Get:6 http://nl.archive.ubuntu.com/ubuntu bionic-security/universe Sources [293 kB]
Get:7 http://nl.archive.ubuntu.com/ubuntu bionic-security/restricted Sources [21.7 kB]
Get:8 http://nl.archive.ubuntu.com/ubuntu bionic-security/multiverse Sources [7,972 B]
Get:9 http://nl.archive.ubuntu.com/ubuntu bionic-security/main amd64 Packages [2,029 kB]
Get:10 http://nl.archive.ubuntu.com/ubuntu bionic-security/main i386 Packages [1,098 kB]
Get:11 http://nl.archive.ubuntu.com/ubuntu bionic-security/main Translation-en [361 kB]
Get:12 http://nl.archive.ubuntu.com/ubuntu bionic-security/restricted i386 Packages [23.2 kB]
Get:13 http://nl.archive.ubuntu.com/ubuntu bionic-security/restricted amd64 Packages [572 kB]
Get:14 http://nl.archive.ubuntu.com/ubuntu bionic-security/restricted Translation-en [77.5 kB]
Get:15 http://nl.archive.ubuntu.com/ubuntu bionic-security/universe amd64 Packages [1,166 kB]
Get:16 http://nl.archive.ubuntu.com/ubuntu bionic-security/universe i386 Packages [1,005 kB]
Get:17 http://nl.archive.ubuntu.com/ubuntu bionic-security/universe Translation-en [269 kB]
Get:18 http://nl.archive.ubuntu.com/ubuntu bionic-security/multiverse amd64 Packages [20.9 kB]
Get:19 http://nl.archive.ubuntu.com/ubuntu bionic-security/multiverse i386 Packages [6,480 B]
Get:20 http://nl.archive.ubuntu.com/ubuntu bionic-security/multiverse Translation-en [4,732 B]
Get:21 http://nl.archive.ubuntu.com/ubuntu bionic-updates/multiverse Sources [15.9 kB]
Get:22 http://nl.archive.ubuntu.com/ubuntu bionic-updates/restricted Sources [24.5 kB]
Get:23 http://nl.archive.ubuntu.com/ubuntu bionic-updates/main Sources [520 kB]
Get:24 http://nl.archive.ubuntu.com/ubuntu bionic-updates/universe Sources [470 kB]
Get:25 http://nl.archive.ubuntu.com/ubuntu bionic-updates/main i386 Packages [1,403 kB]
Get:26 http://nl.archive.ubuntu.com/ubuntu bionic-updates/main amd64 Packages [2,374 kB]
Get:27 http://nl.archive.ubuntu.com/ubuntu bionic-updates/main Translation-en [454 kB]
Get:28 http://nl.archive.ubuntu.com/ubuntu bionic-updates/restricted amd64 Packages [596 kB]
Get:29 http://nl.archive.ubuntu.com/ubuntu bionic-updates/restricted i386 Packages [29.9 kB]
Get:30 http://nl.archive.ubuntu.com/ubuntu bionic-updates/restricted Translation-en [81.3 kB]
Get:31 http://nl.archive.ubuntu.com/ubuntu bionic-updates/universe amd64 Packages [1,781 kB]
Get:32 http://nl.archive.ubuntu.com/ubuntu bionic-updates/universe i386 Packages [1,596 kB]
Get:33 http://nl.archive.ubuntu.com/ubuntu bionic-updates/universe Translation-en [386 kB]
Get:34 http://nl.archive.ubuntu.com/ubuntu bionic-updates/multiverse amd64 Packages [27.2 kB]
Get:35 http://nl.archive.ubuntu.com/ubuntu bionic-updates/multiverse i386 Packages [11.6 kB]
Get:36 http://nl.archive.ubuntu.com/ubuntu bionic-updates/multiverse Translation-en [6,808 B]
Get:37 http://nl.archive.ubuntu.com/ubuntu bionic-backports/main Sources [5,476 B]
Get:38 http://nl.archive.ubuntu.com/ubuntu bionic-backports/universe Sources [6,600 B]
Get:39 http://nl.archive.ubuntu.com/ubuntu bionic-backports/main i386 Packages [10.3 kB]
Get:40 http://nl.archive.ubuntu.com/ubuntu bionic-backports/main amd64 Packages [10.3 kB]
Get:41 http://nl.archive.ubuntu.com/ubuntu bionic-backports/main Translation-en [4,824 B]
Get:42 http://nl.archive.ubuntu.com/ubuntu bionic-backports/universe i386 Packages [11.3 kB]
Get:43 http://nl.archive.ubuntu.com/ubuntu bionic-backports/universe amd64 Packages [11.3 kB]
Get:44 http://nl.archive.ubuntu.com/ubuntu bionic-backports/universe Translation-en [5,772 B]
Fetched 17.3 MB in 4s (4,768 kB/s)
Reading package lists... Done
Building dependency tree
Reading state information... Done
116 packages can be upgraded. Run 'apt list --upgradable' to see them.

After your repositories update, use the following command to initiate the Apache install.

# sudo apt apt install apache2

If all goes well, you will receive the following output. You have to confirm a few options during the installation. Enter Y when prompted, and the rest is done automatically.

john@ubuntu:/root$ sudo apt install apache2
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
  apache2-bin apache2-data apache2-utils libapr1 libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap liblua5.2-0 ssl-cert
Suggested packages:
  www-browser apache2-doc apache2-suexec-pristine | apache2-suexec-custom openssl-blacklist
The following NEW packages will be installed:
  apache2 apache2-bin apache2-data apache2-utils libapr1 libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap liblua5.2-0 ssl-cert
0 upgraded, 10 newly installed, 0 to remove and 116 not upgraded.
Need to get 1,729 kB of archives.
After this operation, 6,997 kB of additional disk space will be used.
Do you want to continue? [Y/n] Y
Get:1 http://nl.archive.ubuntu.com/ubuntu bionic/main amd64 libapr1 amd64 1.6.3-2 [90.9 kB]
Get:2 http://nl.archive.ubuntu.com/ubuntu bionic/main amd64 libaprutil1 amd64 1.6.1-2 [84.4 kB]
Get:3 http://nl.archive.ubuntu.com/ubuntu bionic/main amd64 libaprutil1-dbd-sqlite3 amd64 1.6.1-2 [10.6 kB]
Get:4 http://nl.archive.ubuntu.com/ubuntu bionic/main amd64 libaprutil1-ldap amd64 1.6.1-2 [8,764 B]
Get:5 http://nl.archive.ubuntu.com/ubuntu bionic/main amd64 liblua5.2-0 amd64 5.2.4-1.1build1 [108 kB]
Get:6 http://nl.archive.ubuntu.com/ubuntu bionic-security/main amd64 apache2-bin amd64 2.4.29-1ubuntu4.21 [1,070 kB]
Get:7 http://nl.archive.ubuntu.com/ubuntu bionic-security/main amd64 apache2-utils amd64 2.4.29-1ubuntu4.21 [83.8 kB]
Get:8 http://nl.archive.ubuntu.com/ubuntu bionic-security/main amd64 apache2-data all 2.4.29-1ubuntu4.21 [160 kB]
Get:9 http://nl.archive.ubuntu.com/ubuntu bionic-security/main amd64 apache2 amd64 2.4.29-1ubuntu4.21 [95.1 kB]
Get:10 http://nl.archive.ubuntu.com/ubuntu bionic/main amd64 ssl-cert all Setting up apache2 (2.4.29-1ubuntu4.21) ...
Enabling module mpm_event.
Enabling module authz_core.
Enabling module authz_host.
Enabling module authn_core.
Enabling module auth_basic.
Enabling module access_compat.
Enabling module authn_file.
Enabling module authz_user.
Enabling module alias.
Enabling module dir.
Enabling module autoindex.
Enabling module env.
Enabling module mime.
Enabling module negotiation.
Enabling module setenvif.
Enabling module filter.
Enabling module deflate.
Enabling module status.
Enabling module reqtimeout.
Enabling conf charset.
Enabling conf localized-error-pages.
Enabling conf other-vhosts-access-log.
Enabling conf security.
Enabling conf serve-cgi-bin.
Enabling site 000-default.
Created symlink /etc/systemd/system/multi-user.target.wants/apache2.service → /lib/systemd/system/apache2.service.
Created symlink /etc/systemd/system/multi-user.target.wants/apache-htcacheclean.service → /lib/systemd/system/apache-htcacheclean.service.
Processing triggers for libc-bin (2.27-3ubuntu1.4) ...
Processing triggers for systemd (237-3ubuntu10.44) ...
Processing triggers for man-db (2.8.3-2ubuntu0.1) ...
Processing triggers for ufw (0.36-0ubuntu0.18.04.1) ...
Processing triggers for ureadahead (0.100.0-21) ...

Once the installation is complete, verify that Apache successfully installed by running the following command.

# service apache2 status

Here is the output.

john@ubuntu:/root$ 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
           └─apache2-systemd.conf
   Active: active (running) since Sat 2022-01-29 17:07:42 CET; 4min 25s ago
 Main PID: 2161 (apache2)
    Tasks: 55 (limit: 2316)
   CGroup: /system.slice/apache2.service
           ├─2161 /usr/sbin/apache2 -k start
           ├─2163 /usr/sbin/apache2 -k start
           └─2164 /usr/sbin/apache2 -k start

You have successfully installed Apache on your system.

Make sure that the firewall allows HTTP and HTTPS traffic. Apache uses an uncomplicated firewall (UFW) in place of iptables for managing firewall rules. Use the following command to verify if UFW has a profile set for Apache.

# sudo ufw app list

In the output below, we see the profile for Apache.

john@ubuntu:/root$ sudo ufw app list
Available applications:
  Apache
  Apache Full
  Apache Secure
  OpenSSH

To check if traffic to ports 80 and 443 (HTTP and HTTPS) is enabled, take a look at the full profile details for Apache.

# sudo ufw app info "Apache Full"

Here is the output.

john@ubuntu:/root$ sudo ufw app info "Apache Full"
Profile: Apache Full
Title: Web Server (HTTP,HTTPS)
Description: Apache v2 is the next generation of the omnipresent Apache web
server.

Ports:
  80,443/tcp

The last thing to do is allow incoming HTTP and HTTPS traffic with the following command.

# sudo ufw allow "Apache Full"

The output is as follows.

john@ubuntu:/root$ sudo ufw allow "Apache Full"
Rules updated
Rules updated (v6)

After completing these steps, verify that everything is working as intended by inputting the server IP in your Internet browser and pressing Enter. If you see a page similar to the image below, Apache installed correctly, and the firewall is configured for HTTP and HTTPS traffic.

H3: Step 3: Install MySQL

Ideal for both small and large applications, MySQL grants access to databases you will use to organize and store information.

To start the installation process, we will use the apt install command.

# sudo apt install mysql-server

The output for this command is a list of package information to install as well as the amount of disk space they require.

john@ubuntu:/root$ sudo apt install mysql-server
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
  libaio1 libcgi-fast-perl libcgi-pm-perl libencode-locale-perl libevent-core-2.1-6 libfcgi-perl libhtml-parser-perl
  libhtml-tagset-perl libhtml-template-perl libhttp-date-perl libhttp-message-perl libio-html-perl liblwp-mediatypes-perl
  libtimedate-perl liburi-perl mysql-client-5.7 mysql-client-core-5.7 mysql-common mysql-server-5.7 mysql-server-core-5.7
Suggested packages:
  libdata-dump-perl libipc-sharedcache-perl libwww-perl mailx tinyca
The following NEW packages will be installed:
  libaio1 libcgi-fast-perl libcgi-pm-perl libencode-locale-perl libevent-core-2.1-6 libfcgi-perl libhtml-parser-perl
  libhtml-tagset-perl libhtml-template-perl libhttp-date-perl libhttp-message-perl libio-html-perl liblwp-mediatypes-perl
  libtimedate-perl liburi-perl mysql-client-5.7 mysql-client-core-5.7 mysql-common mysql-server mysql-server-5.7
  mysql-server-core-5.7
0 upgraded, 21 newly installed, 0 to remove and 116 not upgraded.
Need to get 19.7 MB of archives.
After this operation, 156 MB of additional disk space will be used.
Do you want to continue? [Y/n] Y
Get:1 http://nl.archive.ubuntu.com/ubuntu bionic/main amd64 mysql-common all 5.8+1.0.4 [7,308 B]
Get:2 http://nl.archive.ubuntu.com/ubuntu bionic-updates/main amd64 libaio1 amd64 0.3.110-5ubuntu0.1 [6,476 B]
Get:3 http://nl.archive.ubuntu.com/ubuntu bionic-security/main amd64 mysql-client-core-5.7 amd64 5.7.36-0ubuntu0.18.04.1 [6,638 kB]
Get:4 http://nl.archive.ubuntu.com/ubuntu bionic-security/main amd64 mysql-client-5.7 amd64 5.7.36-0ubuntu0.18.04.1 [1,942 kB]
Get:5 http://nl.archive.ubuntu.com/ubuntu bionic-security/main amd64 mysql-server-core-5.7 amd64 5.7.36-0ubuntu0.18.04.1 [7,426 kB]
Get:6 http://nl.archive.ubuntu.com/ubuntu bionic/main amd64 libevent-core-2.1-6 amd64 2.1.8-stable-4build1 [85.9 kB]
Get:7 http://nl.archive.ubuntu.com/ubuntu bionic-security/main amd64 mysql-server-5.7 amd64 5.7.36-0ubuntu0.18.04.1 [2,906 kB]
Get:8 http://nl.archive.ubuntu.com/ubuntu bionic/main amd64 libhtml-tagset-perl all 3.20-3 [12.1 kB]
Get:9 http://nl.archive.ubuntu.com/ubuntu bionic/main amd64 liburi-perl all 1.73-1 [77.2 kB]
Get:10 http://nl.archive.ubuntu.com/ubuntu bionic/main amd64 libhtml-parser-perl amd64 3.72-3build1 [85.9 kB]
Get:11 http://nl.archive.ubuntu.com/ubuntu bionic/main amd64 libcgi-pm-perl all 4.38-1 [185 kB]
Get:12 http://nl.archive.ubuntu.com/ubuntu bionic/main amd64 libfcgi-perl amd64 0.78-2build1 [32.8 kB]
Get:13 http://nl.archive.ubuntu.com/ubuntu bionic/main amd64 libcgi-fast-perl all 1:2.13-1 [9,940 B]
Get:14 http://nl.archive.ubuntu.com/ubuntu bionic/main amd64 libencode-locale-perl all 1.05-1 [12.3 kB]
Get:15 http://nl.archive.ubuntu.com/ubuntu bionic/main amd64 libhtml-template-perl all 2.97-1 [59.0 kB]
Get:16 http://nl.archive.ubuntu.com/ubuntu bionic/main amd64 libtimedate-perl all 2.3000-2 [37.5 kB]
Get:17 http://nl.archive.ubuntu.com/ubuntu bionic/main amd64 libhttp-date-perl all 6.02-1 [10.4 kB]
Get:18 http://nl.archive.ubuntu.com/ubuntu bionic/main amd64 libio-html-perl all 1.001-1 [14.9 kB]
Get:19 http://nl.archive.ubuntu.com/ubuntu bionic/main amd64 liblwp-mediatypes-perl all 6.02-1 [21.7 kB]
Get:20 http://nl.archive.ubuntu.com/ubuntu bionic/main amd64 libhttp-message-perl all 6.14-1 [72.1 kB]
Get:21 http://nl.archive.ubuntu.com/ubuntu bionic-security/main amd64 mysql-server all 5.7.36-0ubuntu0.18.04.1 [9,944 B]
Fetched 19.7 MB in 2s (10.5 MB/s)
Preconfiguring packages ...

Next, use this custom, pre-installed security script to take care of unnecessary system threats and lock down access to your database.

# sudo mysql_secure_installation

When executed, the system asks if you would like to put a password-protected layer on your database. After you type Y to continue and set up your password, it prompts you to select a level of password validation. 

The low password setting requires eight characters in length. The strong setting requires the following:

  • Must be eight characters in length.
  • Must have numeric, mixed case, and special characters.
  • It cannot include common dictionary words. 

When finished with choosing a level of password protection, continue the installation by establishing a password for the MySQL root user.

Note:
Establishing a password for the MySQL root user is an important step because having a basic password will expose your database to serious security threats.

After that, the system prompts a few changes in the MySQL configuration to increase security and remove some common threats. Make the appropriate selections for your setup to continue.

john@ubuntu:/root$ sudo mysql_secure_installation

Securing the MySQL server deployment.

Connecting to MySQL using a blank password.

VALIDATE PASSWORD PLUGIN can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD plugin?

Press y|Y for Yes, any other key for No: Y

There are three levels of password validation policy:

LOW    Length >= 8
MEDIUM Length >= 8, numeric, mixed case, and special characters
STRONG Length >= 8, numeric, mixed case, special characters and dictionary                  file

Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 2
Please set the password for root here.

New password:

Re-enter new password:

Estimated strength of the password: 100
Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : Y
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.

Remove anonymous users? (Press y|Y for Yes, any other key for No) : Y
Success.


Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network.

Disallow root login remotely? (Press y|Y for Yes, any other key for No) : Y
Success.

By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.


Remove test database and access to it? (Press y|Y for Yes, any other key for No) : Y
 - Dropping test database...
Success.

 - Removing privileges on test database...
Success.

Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.

Reload privilege tables now? (Press y|Y for Yes, any other key for No) : Y
Success.

All done!

Log in to the MySQL console with the following command to test if MySQL is working correctly.

# sudo mysql

The output is as follows.

john@ubuntu:~$ sudo mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 10
Server version: 5.7.36-0ubuntu0.18.04.1 (Ubuntu)

Copyright (c) 2000, 2021, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>

Use the following command to exit the console.

mysql>exit

MySQL is installed, secured, and ready to use.

Step 4: Install PHP

PHP is an open source, server-side scripting language. Install the client on your server to process your code and connect to your MySQL databases. Once PHP connects to your databases and has the needed information, it hands that information over to Apache to display the content to your page visitors.

Alongside the PHP client itself, you need to install two libraries:

  • libapache2-mod-php: Integrates PHP into Apache.
  • php-mysql: Allows PHP to connect to MySQL databases.

Install these two libraries with the following command.

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

Here is the output.

john@ubuntu:/root$ sudo apt install php libapache2-mod-php php-mysql
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
  libapache2-mod-php7.2 libsodium23 php-common php7.2 php7.2-cli php7.2-common php7.2-json php7.2-mysql php7.2-opcache
  php7.2-readline
Suggested packages:
  php-pear
The following NEW packages will be installed:
  libapache2-mod-php libapache2-mod-php7.2 libsodium23 php php-common php-mysql php7.2 php7.2-cli php7.2-common php7.2-json
  php7.2-mysql php7.2-opcache php7.2-readline
0 upgraded, 13 newly installed, 0 to remove and 116 not upgraded.
Need to get 4,136 kB of archives.
After this operation, 18.0 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
Creating config file /etc/php/7.2/mods-available/pdo_mysql.ini with new version
Setting up php7.2-cli (7.2.24-0ubuntu0.18.04.10) ...
update-alternatives: using /usr/bin/php7.2 to provide /usr/bin/php (php) in auto mode
update-alternatives: using /usr/bin/phar7.2 to provide /usr/bin/phar (phar) in auto mode
update-alternatives: using /usr/bin/phar.phar7.2 to provide /usr/bin/phar.phar (phar.phar) in auto mode

Creating config file /etc/php/7.2/cli/php.ini with new version
Setting up libapache2-mod-php7.2 (7.2.24-0ubuntu0.18.04.10) ...

Creating config file /etc/php/7.2/apache2/php.ini with new version
Module mpm_event disabled.
Enabling module mpm_prefork.
apache2_switch_mpm Switch to prefork
apache2_invoke: Enable module php7.2
Setting up php-mysql (1:7.2+60ubuntu1) ...
Setting up libapache2-mod-php (1:7.2+60ubuntu1) ...
Setting up php7.2 (7.2.24-0ubuntu0.18.04.10) ...
Setting up php (1:7.2+60ubuntu1) ...
Processing triggers for man-db (2.8.3-2ubuntu0.1) ...
Processing triggers for libc-bin (2.27-3ubuntu1.4) ...
john@ubuntu:/root$

Once installed, test that PHP works by creating a simple PHP script that will run a phpinfo() function and provide all the details of your PHP installation. Place this file in your web root directory so your web server can read it.

# sudo vi /var/www/html/info.php

Place the following text in the file and save it.

<?php
phpinfo();

If you input serverIP/info.php in our browser (serverIP should be replaced with your actual server IP), you will see a page similar to the image below.

PHP works as intended on your server, and you can see all the details regarding your PHP installation here. We can now remove this file with the following command.

# sudo rm /var/www/html/info.php

You have completed the install of the LAMP stack on your Ubuntu server environment.

Wrapping Up

If you followed all of the steps, you were able to install the LAMP stack on your Ubuntu 18.04 server. This installation allows you to host dynamic websites and apps on your server and install various web software for you to work with, including WordPress, Magento, and many more.

Liquid Web’s VPS Hosting, Cloud Dedicated Servers, and Dedicated Servers come with server images that include the LAMP stack upon deployment. We offer 24/7/365 support on core and fully managed servers. Contact our sales team to get your server set up today.

Avatar for Lucas Stanley

About the Author: Lucas Stanley

Lucas is a Linux Support Technician with Nexcess.

Latest Articles

How to use kill commands in Linux

Read Article

Change cPanel password from WebHost Manager (WHM)

Read Article

Change cPanel password from WebHost Manager (WHM)

Read Article

Change cPanel password from WebHost Manager (WHM)

Read Article

Change the root password in WebHost Manager (WHM)

Read Article