- Lab
- A Cloud Guru
Deploying phpMyAdmin on the LEMP Stack on Ubuntu Linux
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.
Path Info
Table of Contents
-
Challenge
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
andrunning
.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`
-
Challenge
Validate That the php7.2-fpm Service Is Installed, Enabled, and Running
Validate that the
php7.2-fpm
service is running, usingsystemctl
:systemctl status php7.2-fpm.service
The service should be
enabled
andrunning
. -
Challenge
Validate and Secure MariaDB
Check the status of the MariaDB server using
systemctl
:systemctl status mariadb
The server should be
enabled
andrunning
.Secure MariaDB by running the
mysql_secure_installation
script. ***Set the MariaDBroot
password to123456
***:mysql_secure_installation
Our MariaDB installation is now configured and secured.
-
Challenge
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. -
Challenge
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.
-
Challenge
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
-
Challenge
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.
-
Challenge
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
-
Challenge
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.
-
Challenge
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_DNSConnections 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 -
Challenge
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
. -
Challenge
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.
-
Challenge
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 addssl
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.
-
Challenge
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.
-
Challenge
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_DNSWe will get a certificate error. Accept the certificate and proceed.
Log into the phpMyAdmin site with the username
phpmyadmin
and password123456
. This puts us in the Home page for thephpMyAdmin
site.
What's a lab?
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.
Provided environment for hands-on practice
We will provide the credentials and environment necessary for you to practice right within your browser.
Guided walkthrough
Follow along with the author’s guided walkthrough and build something new in your provided environment!
Did you know?
On average, you retain 75% more of your learning if you get time for practice.