How To

Install phpMyAdmin with Nginx on Ubuntu 18.04: Setup and Config

phpMyAdmin is a free, open-source PHP application for managing MySQL and MariaDB servers through a browser. It lets you create databases, manage user accounts and privileges, run SQL queries, and import or export data in multiple formats. All of this works without touching the MySQL command line.

This guide covers how to install phpMyAdmin with Nginx on Ubuntu 18.04. The setup differs from the Apache version because the phpMyAdmin installer has no built-in Nginx configuration option. You will configure Nginx manually using a reusable snippet file that can be included in any server block.

<strong>Prerequisite:</strong>&nbsp;You need sudo access and a LEMP stack (Linux, Nginx, MySQL, PHP 7) already installed and running.

Install phpMyAdmin with Nginx: Run the apt Wizard and Create a MySQL Admin User

Update the package index and install phpMyAdmin:

bashsudo apt updatesudo apt install phpmyadmin

The installer launches a web server selection dialog. Nginx is not listed as an option. Press Tab to move the cursor to OK and press Enter without selecting any server. Nginx configuration happens manually in the next section.

When prompted to use dbconfig-common, select Yes. This creates the phpMyAdmin internal configuration database without manual SQL steps. Set and confirm an application password when prompted.

Create a dedicated MySQL admin user. In Ubuntu systems running MySQL 5.7 and later, the root account uses the auth_socket plugin by default. This plugin validates connections through the Unix socket, not a password, so you cannot log in to phpMyAdmin as root using a password.

Create an admin account with mysql_native_password authentication:

bashsudo mysql
sqlCREATE USER 'padmin'@'localhost' IDENTIFIED BY 'your-strong-password';GRANT ALL PRIVILEGES ON *.* TO 'padmin'@'localhost' WITH GRANT OPTION;

WITH GRANT OPTION allows this user to create additional MySQL users and grant them privileges — the same capability as root. Exit the MySQL shell.

Configure Nginx to Serve phpMyAdmin Using a Reusable Snippet

Create a reusable Nginx snippet that can be included in any server block on this server:

bashsudo nano /etc/nginx/snippets/phpmyadmin.conf

Paste the following configuration:

nginxlocation /phpmyadmin {    root /usr/share/;    index index.php index.html index.htm;    location ~ ^/phpmyadmin/(.+\.php)$ {        try_files $uri =404;        root /usr/share/;        fastcgi_pass unix:/run/php/php7.2-fpm.sock;        fastcgi_index index.php;        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;        include /etc/nginx/fastcgi_params;    }    location ~* ^/phpmyadmin/(.+\.(jpg|jpeg|gif|css|png|js|ico|html|xml|txt))$ {        root /usr/share/;    }}

Three directives worth understanding:

  • root /usr/share/: apt installs phpMyAdmin to /usr/share/phpmyadmin/. Setting the root to /usr/share/ lets Nginx resolve it through the /phpmyadmin URI prefix
  • fastcgi_pass unix:/run/php/php7.2-fpm.sock: passes PHP requests to PHP-FPM via Unix socket. Unix sockets are faster than TCP loopback for local communication. Adjust the path if you are using a different PHP version
  • try_files $uri =404: if a requested PHP file does not exist on disk, Nginx returns a 404 instead of passing the non-existent path to PHP-FPM, which blocks a common attack vector

Save the file. Open your domain’s Nginx server block and add the include directive inside server { }:

nginxinclude snippets/phpmyadmin.conf;

Test and reload Nginx:

bashsudo nginx -tsudo systemctl reload nginx

Access phpMyAdmin and Secure the Login URL

Open https://your_domain_or_ip/phpmyadmin in a browser. Log in with the padmin credentials you created earlier. The dashboard shows your databases in the left sidebar and server information in the main panel.

Rename the default path. The /phpmyadmin URL is publicly known and actively scanned by automated bots. Rename the location by replacing location /phpmyadmin with a custom path like location /dbmanager in the snippet file. Reload Nginx after the change.

Add HTTP Basic Auth as a second layer. For production environments, add auth_basic "Authentication Required" and auth_basic_user_file /etc/nginx/.htpasswd inside the phpMyAdmin location block. Create the password file with sudo htpasswd -c /etc/nginx/.htpasswd padmin. This requires attackers to pass two separate authentication steps before reaching the phpMyAdmin login page.

phpMyAdmin is now installed and accessible through Nginx on your Ubuntu 18.04 server. Use it to manage databases, create users, run queries, and handle data imports and exports from the browser. Leave a comment below if you run into any issues.

Cyber Defence

Recent Posts

Install MariaDB on Ubuntu 18.04: Two Methods and Secure Setup

MariaDB is an open-source, multi-threaded relational database management system and a fully backward-compatible replacement for MySQL.…

6 minutes ago

Install Odoo 11 on Ubuntu 18.04: Virtualenv and Nginx Proxy Setup

Odoo 11 is an open-source all-in-one business software platform covering CRM, e-commerce, billing, accounting, manufacturing,…

11 minutes ago

Install Odoo on Ubuntu 18.04: Deploy Version 12 with Nginx

Odoo is the most widely used open-source all-in-one business software suite. It integrates CRM, e-commerce, billing,…

16 minutes ago

Install phpMyAdmin on Ubuntu 18.04 with Apache: Setup Guide

phpMyAdmin is a free, open-source PHP application that provides a browser-based interface for managing MySQL and…

2 days ago

Install Zabbix on Ubuntu 18.04: Server Setup with MySQL Backend

Zabbix is a mature open-source infrastructure monitoring platform that collects metrics from network devices, servers, virtual…

2 days ago

Install Gradle on Ubuntu 18.04: Set Up OpenJDK and Environment

Gradle is a powerful open-source build automation tool used primarily for Java, Kotlin, Groovy, and Android…

2 days ago