Deploying phpMyAdmin on the LEMP Stack on Ubuntu Linux

1 hour
  • 15 Learning Objectives

About this Hands-on Lab

Before we can start building our world-changing website or application on LEMP, we have to lay the foundation for the stack. In this hands-on lab, we will walk through deploying phpMyAdmin on Ubuntu Linux.

When the lab is complete, we will have a running phpMyAdmin installation on Ubuntu Linux.

Learning Objectives

Successfully complete this lab by achieving the following learning objectives:

Validate That the NGINX Server Is Installed, Enabled, and Running

Become root:

sudo su -

Check the status of the NGINX service:

systemctl status nginx

The service should be enabled and running.

Verify that we can load the default NGINX web page using curl:

By Public IP:

curl http://`cat /tmp/public_ip.txt`

By Public DNS:

curl http://`cat /tmp/public_dns.txt`
Validate That the php7.2-fpm Service Is Installed, Enabled, and Running

Validate that the php7.2-fpm service is running, using systemctl:

systemctl status php7.2-fpm.service

The service should be enabled and running.

Validate and Secure MariaDB

Check the status of the MariaDB server using systemctl:

systemctl status mariadb

The server should be enabled and running.

Secure MariaDB by running the mysql_secure_installation script. Set the MariaDB root password to 123456:

mysql_secure_installation

Our MariaDB installation is now configured and secured.

Install phpMyAdmin

Install phpMyAdmin from the Ubuntu software repository using apt-get:

apt-get -y install phpmyadmin

This will launch a configuration dialog.

We’re going to configure phpMyAdmin with NGINX. Do NOT select anything. Just use the Tab key to get down to OK, and hit Enter.

Select Yes to create a new database using dbconfig-common.

We will need to provide a password for the new phpmyadmin user. Use 123456. Once this is done, installation and configuration is complete.

Configure NGINX to Work with phpMyAdmin – Part 1

The lab server has been created with a pre-configured server block. We will validate the NGINX configuration and examine it.

Validate the NGINX server configuration:

nginx -t

Let’s look at the virtual host configurations:

cd /etc/nginx/conf.d
ls -la

There are two virtual host configurations, one for the default site configuration, and a template for the phpMyAdmin configuration.

Configure NGINX to Work with phpMyAdmin – Part 2

We need to enable the configuration for phpMyAdmin:

mv phpmyadmin.conf.template phpmyadmin.conf

Validate that the NGINX configuration is still OK:

nginx -t
Configure NGINX to Work with phpMyAdmin – Part 3

Let’s take a look at the phpMyAdmin configuration:

more phpmyadmin.conf

We can see a few key things about the configuration:

  • The server supports HTTP connections.
  • The server name is configured as the EC2 instance’s DNS name.
  • The document root location is /usr/share/phpmyadmin/.
  • The logs for this virtual host are going to their own log files, separate from the logs for the main server.
  • PHP is configured for this virtual host.
Configure NGINX to Work with phpMyAdmin – Part 4

PHP is configured to communicate over a UNIX socket (/run/php/php7.2-fpm.sock).

Now, let’s reload the NGINX service to pick up the phpmyadmin virtual host configuration. We’ve already validated the NGINX configuration (above), so we’re good to go with a reload:

systemctl reload nginx
systemctl status nginx
Configure NGINX to Work with phpMyAdmin – Part 5

Verify that the phpMyAdmin site is available using the curl command:

curl -H "http://`cat /tmp/public_dns.txt`" http://`cat /tmp/public_dns.txt`

If everything is working as it should, we will see a lot of code.

Test HTTP Connection to phpMyAdmin

Verify that we can connect to phpMyAdmin using a web browser. We can get the Public DNS for the lab server in /home/cloud_user/server_info.txt. Connect to http://OUR_PUBLIC_DNS

Connections to the default NGINX web server instance can be made via the Public IP. This is also in /home/cloud_user/server_info.txt. Connect to http://OUR_PUBLIC_IP

Validate the phpMyAdmin SSL Certificate

Before we configure the phpMyAdmin site to use SSL/TLS, we want to verify that the SSL certificate is good:

cd /etc/nginx/ssl/phpMyAdmin

Verify that the X509 certificate was correctly generated using the openssl verify command:

openssl verify -CAfile ca-cert.pem server-cert.pem

We should see: server-cert.pem: OK.

Check the Properties of the phpMyAdmin SSL Certificate

We can display information about the CA and server SSL certificate information using openssl x509:

openssl x509 -in ca-cert.pem -noout -text
openssl x509 -in server-cert.pem -noout -text

Note that the CN entries are different. This is important. If the CN is the same for the CA and the server certificate, we will get an error and SSL will fail.

Secure phpMyAdmin with SSL

Edit the phpmyadmin.conf file:

vi /etc/nginx/conf.d/phpmyadmin.conf

Change the listen lines from port 80 to 443 and add ssl after 443:

listen 443 ssl;
and
listen [::]:443 ssl;

Add the following lines after the server_name configuration line:

ssl_certificate /etc/nginx/ssl/phpMyAdmin/server-cert.pem;
ssl_certificate_key /etc/nginx/ssl/phpMyAdmin/server-key.pem;

Save and exit.

Load the New NGINX Configuration for phpMyAdmin

Before we reload NGINX to pick up the new configuration, validate:

nginx -t

If everything checks out, reload:

systemctl reload nginx

Our SSL configuration is now active.

Log into the phpMyAdmin Site

Verify that we can connect to phpMyAdmin using HTTPS with a web browser. We can get the Public DNS for the lab server in /home/cloud_user/server_info.txt. Connect to https://OUR_PUBLIC_DNS

We will get a certficate error. Accept the certificate and proceed.

Log into the phpMyAdmin site with the username phpmyadmin and password 123456. This puts us in the Home page for the phpMyAdmin site.

Additional Resources

Big State College (BSC) is a Large Ten Conference school in a Midwestern state. BSC is looking to deploy a centralized web hosting service using the LEMP stack.

As the engineers tasked with executing this project, we will be deploying and configuring phpMyAdmin on an Ubuntu Linux server, for managing the new MariaDB environment. Let's begin!

Connecting to the Lab Server

Use the credentials provided on the hands-on lab overview page, and log in using an SSH connection to the Public IP or DNS of the server as cloud_user.

Making a SSH connection using the ssh command. Replace <<public_IP_or_DNS>> with the Public IP or DNS provided on the overview page.

ssh cloud_user@<<public_IP_or_DNS>>

If you can't use ssh or prefer a GUI client, use the credentials provided on the hands-on lab overview page to configure your SSH connection to the lab server.

Lab Git Repository

Feel free to explore the configurations and code from the lab at: GitHub - linuxacademy/content-lemp-deep-dive

What are Hands-on Labs

Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.

Get Started
Who’s going to be learning?

How many seats do you need?

  • $499 USD per seat per year
  • Billed Annually
  • Renews in 12 months

Ready to accelerate learning?

For over 25 licenses, a member of our sales team will walk you through a custom tailored solution for your business.


$2,495.00

Checkout
Sign In
Welcome Back!

Psst…this one if you’ve been moved to ACG!