How to Install phpMyAdmin on Ubuntu 26.04

By 

•

Published on

•

9 min read

Illustrated browser with database tables beside a database cabinet and a key

When you need to browse a database table, run a query, or import a SQL file, phpMyAdmin lets you do it from your browser. It is a PHP application that connects to MySQL or MariaDB using the same database accounts you use from the command line.

This guide explains how to install phpMyAdmin on Ubuntu 26.04 with Apache or Nginx, create a MySQL login, and access the interface through a local connection or an SSH tunnel.

Quick Reference

ItemLocation or command
Install phpMyAdminsudo apt install phpmyadmin
Local addresshttp://localhost/phpmyadmin/
Application files/usr/share/phpmyadmin
Main configuration/etc/phpmyadmin/config.inc.php
Packaged Apache configuration/etc/phpmyadmin/apache.conf
Default PHP-FPM socket on Ubuntu 26.04/run/php/php8.5-fpm.sock
Repeat the package configurationsudo dpkg-reconfigure -plow phpmyadmin

Prerequisites

You will need an Ubuntu 26.04 machine and a user with sudo privileges . You should also have a running web server, PHP, and a database server before installing phpMyAdmin.

If you are starting with a fresh server, follow the LAMP guide for Apache or the LEMP guide for Nginx. Choose one stack. You do not need both web servers.

The examples below use MySQL 8.4 and PHP 8.5 from the Ubuntu repositories. The phpMyAdmin package also supports MariaDB, but the database commands in this walkthrough were tested with MySQL.

We will restrict the interface to local connections. On a remote server, you will reach it through SSH, so you do not need to open another firewall port or publish the login page on the internet.

Step 1: Install phpMyAdmin

Ubuntu 26.04 includes phpMyAdmin 5.2.3 in the Universe repository . Start by updating the package index:

Terminal
sudo apt update

Install phpMyAdmin:

Terminal
sudo apt install phpmyadmin

The package installs its required PHP extensions, including the MySQL driver and mbstring. You do not need to download an archive or add a PPA.

During installation, you will be asked which web server to configure automatically. For Apache, press Space to select apache2, then Tab and Enter to continue. Highlighting the entry without pressing Space does not select it.

For Nginx, leave both entries unselected and continue. The installer has no Nginx option, so we will add its configuration in the next step.

When asked whether to configure the database with dbconfig-common, choose Yes. At the application password prompt, you can leave the field blank to generate a random password. If you enter one yourself, the installer asks you to confirm it.

This creates a database named phpmyadmin and an internal control user for features such as saved preferences and bookmarks. The password belongs to that internal account. We will create a separate user for signing in to the browser interface.

Step 2: Configure the Web Server

Follow the section for your web server, then continue to Step 3.

Apache

The package provides an alias that maps /phpmyadmin to /usr/share/phpmyadmin. Enable the configuration if it is not already enabled:

Terminal
sudo a2enconf phpmyadmin

If a2enconf reports that the configuration does not exist, apache2 was not selected during installation. To create the missing link, follow the 404 entry in the Troubleshooting section below.

Open the packaged configuration:

Terminal
sudo nano /etc/phpmyadmin/apache.conf

Find the opening <Directory /usr/share/phpmyadmin> line and add Require local directly below it:

/etc/phpmyadmin/apache.confapache
<Directory /usr/share/phpmyadmin>
    Require local

These are the first two lines of the existing block. Keep the remaining directives and the closing </Directory> tag in place. This restriction allows local requests, including connections forwarded through SSH, and rejects other clients.

Check the configuration and restart Apache to load the PHP extensions installed with phpMyAdmin:

Terminal
sudo apache2ctl configtest
sudo systemctl restart apache2

The configuration check should report Syntax OK. If it reports an error, correct the indicated file and line before restarting the service.

Nginx

Nginx sends PHP requests to PHP-FPM. If your existing Nginx installation does not have it, install PHP-FPM and the MySQL extension:

Terminal
sudo apt install php-fpm php-mysql

Create a snippet for phpMyAdmin:

Terminal
sudo nano /etc/nginx/snippets/phpmyadmin.conf

Add the following configuration:

/etc/nginx/snippets/phpmyadmin.confnginx
location = /phpmyadmin {
    absolute_redirect off;
    return 301 /phpmyadmin/;
}

location ^~ /phpmyadmin/ {
    root /usr/share;
    index index.php;

    allow 127.0.0.1;
    allow ::1;
    deny all;

    location ~ ^/phpmyadmin/(setup|templates|libraries)/ {
        deny all;
    }

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/run/php/php8.5-fpm.sock;
    }
}

The exact-match location adds the missing trailing slash, and absolute_redirect off keeps the port you use through an SSH tunnel. The root directive maps /phpmyadmin/index.php to /usr/share/phpmyadmin/index.php. The access rules permit loopback connections, and the nested PHP location passes scripts to PHP-FPM. The deny all location blocks requests to internal directories.

The ^~ prefix keeps a general PHP location elsewhere in your server block from taking over these requests. Do not remove the nested PHP handler; without it, the ^~ location serves the PHP source code as a plain file download.

Open the server block that handles localhost or the default requests on port 80. On an unchanged Ubuntu Nginx installation, it is /etc/nginx/sites-available/default. Add this line inside its existing server { ... } block:

nginx
include snippets/phpmyadmin.conf;

The include belongs directly inside the server block, alongside its other locations. It does not go inside another location block.

Check the configuration, restart PHP-FPM to load the installed extensions, and reload Nginx:

Terminal
sudo nginx -t
sudo systemctl restart php8.5-fpm
sudo systemctl reload nginx

Nginx should report that the syntax is OK and the configuration test is successful. If you use a different PHP version, replace php8.5-fpm and its socket path with the version installed on your machine.

Step 3: Create a MySQL Login

On a default Ubuntu MySQL installation, root authenticates through the Unix socket using the operating system account. That is why sudo mysql works in a terminal while signing in as root from phpMyAdmin fails.

Keep that authentication method and create a password-authenticated user for the databases you want to manage. Open the MySQL shell:

Terminal
sudo mysql

In this example, we will create a database named appdb and a user named dbuser:

sql
CREATE DATABASE appdb;
CREATE USER 'dbuser'@'localhost' IDENTIFIED BY 'replace-with-a-strong-password';
GRANT ALL PRIVILEGES ON appdb.* TO 'dbuser'@'localhost';

Replace the example password before running the statement. If the database already exists, skip CREATE DATABASE and use its name in the grant. You can also use an existing password-authenticated account with the permissions you need.

The grant lets dbuser manage appdb, including its tables and data. It does not grant access to every database or permission to create other users. For server-wide administration, continue using sudo mysql or assign the specific additional privileges your work requires.

MySQL 8.4 uses caching_sha2_password for new users by default, and the Ubuntu PHP driver supports it. You do not need to enable mysql_native_password or change the root account.

Warning
Keep the real database password out of version control. Do not commit SQL files containing credentials. For application configuration, use an appropriate secret store or a local .env file excluded through .gitignore.

Exit the MySQL shell:

sql
EXIT;

Step 4: Access phpMyAdmin

If your browser runs on the Ubuntu machine itself, open:

url
http://localhost/phpmyadmin/

For a remote server, run the following command on your computer, replacing username and server_ip with your SSH account and server address:

Terminal
ssh -N -L 127.0.0.1:8080:127.0.0.1:80 username@server_ip

Keep the terminal open while using phpMyAdmin. The command forwards port 8080 on your computer to port 80 on the server through the encrypted SSH connection. The web server receives a loopback connection, which the access rules allow.

Open the forwarded address in your computer’s browser:

url
http://127.0.0.1:8080/phpmyadmin/

Here, localhost and 127.0.0.1 refer to the machine running the browser. Without the tunnel, entering localhost/phpmyadmin on your laptop would contact your laptop, not the remote Ubuntu server.

Sign in with dbuser and the password you set in Step 3:

phpMyAdmin login page in Firefox on Ubuntu 26.04 with username and password fields

After signing in, you should see appdb in the left sidebar. Select it to browse tables, run queries from the SQL tab, or upload a dump through Import:

phpMyAdmin dashboard on Ubuntu 26.04 showing the appdb database and the dbuser MySQL connection

The databases and actions available depend on the MySQL user’s privileges. The phpMyAdmin login does not give that user additional database permissions.

When you finish, log out of phpMyAdmin and press Ctrl+C in the tunnel terminal. For more forwarding examples, see SSH tunneling .

Troubleshooting

localhost/phpmyadmin returns 404 Not Found
First check which machine localhost points to. On a remote setup, use the forwarded port from Step 4. For Apache, a common cause is leaving apache2 unselected in the installer. In that case, the package does not create the Apache configuration link, and a2enconf reports that the configuration does not exist. Create the link, enable the alias, and reload the service:

Terminal
sudo ln -s /etc/phpmyadmin/apache.conf /etc/apache2/conf-available/phpmyadmin.conf
sudo a2enconf phpmyadmin
sudo apache2ctl configtest
sudo systemctl reload apache2

For Nginx, confirm that include snippets/phpmyadmin.conf; is inside the server block handling the request. The package does not configure Nginx automatically. You do not need to copy phpMyAdmin into /var/www/html or create a document-root symlink with the configuration used here.

403 Forbidden when using the server’s IP address
This is expected with the local access rules in this guide. Use the SSH tunnel. If you already have a tunnel and still receive 403, check that it forwards to 127.0.0.1:80 on the server and that the request reaches the intended virtual host.

Access denied for user root or dbuser
Use the account from Step 3, not the socket-authenticated root account or the internal phpmyadmin control user. To check the same credentials outside the browser, run this on the Ubuntu server:

Terminal
mysql -u dbuser -p

Enter the password at the prompt. If this also fails, check the MySQL username, password, and host entry before changing phpMyAdmin settings. If you can sign in but cannot see a database, review the user’s grants.

Nginx returns 502 Bad Gateway
Check that PHP-FPM is running and that its socket matches the fastcgi_pass directive:

Terminal
systemctl status php8.5-fpm
ls -l /run/php/
sudo tail -n 30 /var/log/nginx/error.log

A missing socket or a connection-refused message usually means PHP-FPM is stopped or Nginx points to a different PHP version. Correct the path or start the matching service, then test the Nginx configuration before reloading it.

Conclusion

You can now manage your database through phpMyAdmin while keeping its login page behind local access. Before changing existing data, take a MySQL backup that you can restore if needed.

Linuxize Weekly Newsletter

A quick weekly roundup of new tutorials, news, and tips.

About the authors

Dejan Panovski

Dejan Panovski

Dejan Panovski is the founder of Linuxize, an RHCSA-certified Linux system administrator and DevOps engineer based in Skopje, Macedonia. Author of 1000+ Linux tutorials with 20+ years of experience turning complex Linux tasks into clear, reliable guides.

View author page