If you have already set up a local LEMP stack (Linux, Nginx, MariaDB, PHP-FPM) and WordPress as shown in "How To Install WordPress on Localhost (LEMP Stack)", follow this guide to install phpMyAdmin to easily manage your databases using a web interface.
This guide covers the phpMyAdmin installation, Nginx configuration, database user setup, and how to access phpMyAdmin from your local web browser.
Step 1: Install the phpMyAdmin Package
Update your package list and install phpMyAdmin:
sudo apt update
sudo apt install phpmyadmin
Note on PHP Extensions
If you skipped installing optional PHP modules during your LEMP setup, you might need to install them now:
sudo apt install php-mysqli php-mbstring php-zip php-gd php-xml php-curl php-bz2 php-intl
Note: PHP 8.x includes the php-json extension by default. If you are installing a different version, such as PHP 7 or older, you may need to install the php-json extension manually.
Interactive Setup Prompts
During installation, handle the setup prompts as follows:
Web Server Selection
The prompt will list apache2 and lighttpd. Do NOT select either box. Press TAB to highlight OK, then press ENTER.
Nginx handles server blocks differently and does not require this auto-configuration.
Database Configuration (dbconfig-common)
Select Yes when asked to configure a database for phpMyAdmin.
Application Password
Enter a password for phpMyAdmin's internal database management user, or press ENTER to let it auto-generate a password.
Step 2: Configure Nginx Access
Since Nginx does not serve files from /usr/share/phpmyadmin by default, choose one of the following two methods depending on your web root setup.
Option A: Create a Symlink
Recommended if your site root is /var/www/html:
Create a symbolic link directly into your web root:
sudo ln -s /usr/share/phpmyadmin /var/www/html/phpmyadmin
Note: If your WordPress site is installed in a subdirectory like /var/www/html/wordpress, you can place the symlink inside that folder instead:
sudo ln -s /usr/share/phpmyadmin /var/www/html/wordpress/phpmyadmin
Option B: Add a location /phpmyadmin Block to Nginx
If you prefer not to use a symlink, open your active WordPress server block configuration:
sudo nano /etc/nginx/sites-available/wordpress
Add the following block inside your main server { ... } block. Verify that the PHP-FPM socket version matches your installed PHP version, such as php8.3-fpm or php8.4-fpm.
# --- phpMyAdmin Block ---
location ^~ /phpmyadmin {
root /usr/share;
index index.php index.html index.htm;
location ~ ^/phpmyadmin/(.+\.php)$ {
try_files $fastcgi_script_name =404;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass unix:/run/php/php8.3-fpm.sock; # Adjust PHP version as needed
}
location ~* ^/phpmyadmin/(.+\.(jpg|jpeg|gif|css|png|js|ico|html|xml|txt))$ {
root /usr/share;
expires max;
log_not_found off;
}
}
Test and Reload Nginx
After adding the configuration, test the Nginx configuration:
sudo nginx -t
Then reload Nginx to apply the changes:
sudo systemctl reload nginx
Step 3: Create a Dedicated Admin Database User
On Debian/Ubuntu, MariaDB’s root account uses unix_socket authentication by default, which prevents browser logins via phpMyAdmin.
Note on Existing Users
If you only need to manage your WordPress database, you can log in directly using your existing wp_user account.
To manage all databases with full administrative privileges, create a dedicated admin account below.
Open MariaDB Terminal
Run:
sudo mysql -u root
Create the Administrator Account
Replace pma_admin and password with your preferred username and password:
CREATE USER 'pma_admin'@'localhost' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON *.* TO 'pma_admin'@'localhost' WITH GRANT OPTION;
FLUSH PRIVILEGES;
EXIT;
Step 4: Access and Test phpMyAdmin
Open your web browser and navigate to:
http://localhost/phpmyadmin
Log in using your credentials:
- Username: The Username set in Step 3.
- Password: The password set in Step 3.
Troubleshooting
404 Not Found at /phpmyadmin:
502 Bad Gateway / Access Denied:
Access Denied Error for root:
Once logged in, you can use phpMyAdmin through your web browser to manage your MySQL/MariaDB databases on the local LEMP installation.
With phpMyAdmin configured for Nginx and PHP-FPM, you can conveniently manage your local databases through a browser instead of relying only on the MariaDB terminal.
.webp)