How To

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 MariaDB servers. It lets you create and delete databases, manage user accounts and privileges, run SQL queries, and import or export data in formats including CSV, SQL, and JSON. All of this works without touching the MySQL command line.

This guide covers how to install phpMyAdmin on Ubuntu 18.04 with Apache and how to secure it with an extra layer of HTTP Basic Authentication. Before starting, make sure the LAMP stack (Linux, Apache, MySQL, PHP) is already installed and running on your server.

<strong>Prerequisite:</strong>&nbsp;You need sudo access and an existing LAMP installation.

Install phpMyAdmin on Ubuntu: The apt Installation Wizard

Update the package list and install phpMyAdmin:

bashsudo apt update &amp;&amp; sudo apt upgradesudo apt install phpmyadmin

The installer runs an interactive wizard with three prompts:

  1. Web server selection: use the Space bar to select apache2, then press Enter. This automatically configures Apache to serve phpMyAdmin at /phpmyadmin
  2. Database configuration: when asked whether to use dbconfig-common, select Yes. This creates phpMyAdmin’s internal configuration database without manual SQL steps
  3. Password: set a password for phpMyAdmin to use internally for its own database connection

After the wizard completes, restart Apache to load the phpMyAdmin configuration:

bashsudo systemctl restart apache2

Create a MySQL Admin User and Access the phpMyAdmin Dashboard

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

Instead, create a dedicated MySQL admin user with mysql_native_password authentication:

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

WITH GRANT OPTION gives this user the ability to create other MySQL users and grant them permissions — the same capability the root account has. Use a strong password and note it down.

Open https://your_domain_or_ip/phpmyadmin in a browser and log in with the padmin credentials you just created. The phpMyAdmin dashboard shows your databases in the left sidebar and server information in the main panel. Use the interface to create databases, run queries, import and export data, and manage user accounts.

Secure phpMyAdmin with HTTP Basic Authentication

The /phpmyadmin URL is publicly known and frequently targeted by automated scanners. Adding HTTP Basic Auth creates a second authentication barrier before the phpMyAdmin login form appears.

Create the Basic Auth password file using Apache’s htpasswd tool. The -c flag creates the file. To add more users later, run the same command without -c:

bashsudo htpasswd -c /etc/phpmyadmin/.htpasswd padmin

Edit the Apache phpMyAdmin configuration at /etc/apache2/conf-available/phpmyadmin.conf. Inside the <Directory /usr/share/phpmyadmin> block, add these directives:

apacheAuthType basicAuthName "Authentication Required"AuthUserFile /etc/phpmyadmin/.htpasswdRequire valid-user

Restart Apache to apply the changes:

bashsudo systemctl restart apache2

Accessing /phpmyadmin now prompts for the Basic Auth credentials first, then the phpMyAdmin MySQL login form. Anyone without the Basic Auth password cannot reach the phpMyAdmin login page at all.

One more security step. Rename the default /phpmyadmin alias to something less predictable, such as /dbadmin or a random string. Change the Alias directive in /etc/apache2/conf-available/phpmyadmin.conf and restart Apache. This significantly reduces automated scan traffic targeting your admin panel.

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

Cyber Defence

Recent Posts

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…

40 minutes 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…

45 minutes ago

Install TeamViewer on Ubuntu 18.04: Download the .deb and Set Up

TeamViewer is a proprietary cross-platform remote access application for remote control, desktop sharing, file transfer, and online meetings. It is one of the most widely used remote support tools in the world, available for Windows, macOS, Linux, iOS, and Android. TeamViewer is not included in the Ubuntu repositories because it is proprietary software. This guide covers how to install TeamViewer on Ubuntu 18.04 using the official .deb package. The same steps apply to Ubuntu 16.04, Debian, Linux Mint, and Elementary OS. <strong>Prerequisite:</strong>&nbsp;You&nbsp;need&nbsp;sudo&nbsp;access. Install TeamViewer on Ubuntu: Download the .deb Package Download the official TeamViewer .deb package. The _amd64.deb suffix indicates this package is for 64-bit x86-64 systems. For ARM-based machines, download the appropriate package from the TeamViewer Linux downloads page: bashwget https://download.teamviewer.com/download/linux/teamviewer_amd64.deb Install the package using apt. The ./ prefix tells apt this is a local file path, not a package name from the repositories:…

50 minutes ago

Install Nagios Core on Ubuntu 18.04: Build from Source Guide

Nagios is one of the most widely used open-source infrastructure monitoring systems in the world. It…

55 minutes ago

Install Laravel on Ubuntu 18.04 with Composer: Setup Guide

Laravel is an open-source PHP web application framework built around an expressive, developer-friendly syntax. It is…

19 hours ago

Install Kodi on Ubuntu 18.04: Add the Official PPA and Set Up

Kodi (formerly XBMC, short for Xbox Media Center) is a free, open-source, cross-platform media player and…

19 hours ago