Skip to content

Contact sales

By filling out this form and clicking submit, you acknowledge our privacy policy.
  • Labs icon Lab
  • A Cloud Guru
Google Cloud Platform icon
Labs

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.

Google Cloud Platform icon
Labs

Path Info

Level
Clock icon Intermediate
Duration
Clock icon 1h 0m
Published
Clock icon Jan 10, 2020

Contact sales

By filling out this form and clicking submit, you acknowledge our privacy policy.

Table of Contents

  1. 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 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`
    
  2. Challenge

    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.

  3. Challenge

    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.

  4. 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.

  5. 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.

  6. 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
    
  7. 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.
  8. 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
    
  9. 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.

  10. 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_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

  11. 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.

  12. 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.

  13. 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 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.

  14. 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.

  15. 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_DNS

    We will get a certificate 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.

The Cloud Content team comprises subject matter experts hyper focused on services offered by the leading cloud vendors (AWS, GCP, and Azure), as well as cloud-related technologies such as Linux and DevOps. The team is thrilled to share their knowledge to help you build modern tech solutions from the ground up, secure and optimize your environments, and so much more!

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.

Start learning by doing today

View Plans