If you see a 404 error when opening phpMyAdmin on Nginx or Apache, the web server cannot find the phpMyAdmin files at the URL you requested. This usually happens because the files are installed in a different directory, the alias or location block is misconfigured, or the PHP handler is not processing the request correctly. Below are the exact steps to diagnose and fix the issue on both servers.
Why phpMyAdmin Returns a 404
A 404 error means the server looked for a file or directory at the requested URL and did not find it. With phpMyAdmin, the most common causes are:
- Wrong installation path: The phpMyAdmin files are not in the directory the web server is configured to serve.
- Missing or incorrect alias/location block: On Apache, an
Aliasdirective may point to a nonexistent directory. On Nginx, alocationblock may reference the wrong path or lack the necessary directives. - PHP not installed or not enabled: If PHP is missing, the server may treat the PHP file as plain text or return a 404 if the handler is not set.
- File permissions: The web server user cannot read the phpMyAdmin directory.
- Symlink issues: If you created a symlink, it may be broken (pointing to a non-existent target).
How to Fix on Apache
On Apache, phpMyAdmin is often installed in /usr/share/phpmyadmin (Debian/Ubuntu) or /var/www/html/phpmyadmin (manual install). The configuration file is usually /etc/phpmyadmin/apache.conf or a snippet in /etc/apache2/conf-available/.
- Verify the installation directory: Run
ls -la /usr/share/phpmyadminor check where you extracted the files. If the directory is empty or missing, reinstall or re-extract phpMyAdmin. - Check the Apache configuration: Look for a line like
Alias /phpmyadmin /usr/share/phpmyadmin. If it points to a wrong path, correct it. Also ensure the<Directory>block hasRequire all granted(or appropriate access). - Enable the configuration: On Debian/Ubuntu, run
sudo a2enconf phpmyadminand thensudo systemctl reload apache2. On other systems, include the config file in the mainhttpd.conf. - Test with a simple PHP file: Create
/usr/share/phpmyadmin/test.phpwith<?php phpinfo(); ?>. If you get a 404 for that too, the directory is not being served. If you get a blank page or the PHP code, the PHP handler is broken. - Check file permissions: Ensure the web server user (often
www-data) has read and execute permissions on the directory:sudo chown -R www-data:www-data /usr/share/phpmyadmin(adjust to your user/group).
How to Fix on Nginx
Nginx does not use .htaccess files, so all configuration is in server blocks. A common setup is:
location /phpmyadmin {
root /usr/share/;
index index.php;
}
If the path is wrong, you get a 404. Here are the steps:
- Confirm the files exist: Check
ls -la /usr/share/phpmyadminor wherever you placed the files. If you downloaded a zip, make sure you extracted it to the correct directory and that the folder name matches the URL (e.g.,/phpmyadmin). - Set the correct root: If your files are in
/usr/share/phpmyadmin, therootmust be/usr/shareand the location must be/phpmyadmin. If the files are in/var/www/html/phpmyadmin, the root is/var/www/html. - Add PHP handling: Inside the location block, add:
location ~ ^/phpmyadmin/(.*\.php)$ { include snippets/fastcgi-php.conf; fastcgi_pass unix:/run/php/php8.1-fpm.sock; # adjust version } - Test the configuration: Run
sudo nginx -tand reload withsudo systemctl reload nginx. - Check for try_files conflicts: If you have a
try_files $uri =404;in a parent location, it may override the phpMyAdmin location. Ensure the phpMyAdmin location is more specific or addtry_files $uri $uri/ =404;inside it.
Common Misconception: It’s a PHP Error
Many users assume a 404 means PHP is broken. In most cases, PHP is fine—the server simply cannot find the file. To confirm, create a file named info.php in the same directory with <?php phpinfo(); ?> and try to access it. If you get a 404, the directory is wrong. If you see the PHP info page, then PHP works and the issue is specifically with the phpMyAdmin files (maybe a missing index.php or a permission issue).
How to Choose the Right Fix
Start by checking the simplest thing: does the URL match the directory name? If you installed phpMyAdmin in /var/www/html/phpmyadmin, the URL should be http://yourdomain/phpmyadmin. If you used a different name (e.g., pma), the URL changes accordingly. If you are using a reverse proxy or a subdomain, the configuration is different—ensure the proxy passes the correct path.
Frequently Asked Questions
Why do I get a 404 only for /phpmyadmin but other pages work?
This indicates that the web server is serving other files correctly, but the specific location block for phpMyAdmin is missing or misconfigured. On Apache, check if the alias is defined. On Nginx, check if the location block exists and has the correct root.
I installed phpMyAdmin but the URL shows a 404. Did I install it in the wrong place?
Yes, that is the most likely cause. The web server only serves files from the document root (or aliased paths). If you extracted the files to /opt/phpmyadmin but the server expects them in /var/www/html, you need to either move the files or create a symlink: sudo ln -s /opt/phpmyadmin /var/www/html/phpmyadmin.
How do I fix a 404 error after updating PHP or phpMyAdmin?
Updates can change file locations or permissions. After an update, check that the configuration files still point to the correct paths. On Debian/Ubuntu, updates may overwrite the Apache config, so re-enable it with a2enconf phpmyadmin. On Nginx, ensure the PHP-FPM socket version matches the installed PHP version.
Can a firewall or SELinux cause a 404?
No, a firewall blocks connections (giving a timeout or connection refused), not a 404. SELinux, however, can cause a 404 if it denies the web server read access to the phpMyAdmin directory. Check SELinux audit logs with ausearch -m avc and, if needed, restore the correct context: sudo restorecon -Rv /usr/share/phpmyadmin.
What if I get a 404 but the file exists and permissions are correct?
This can happen if your web server is using a different document root than you think. For example, on Apache with virtual hosts, the DocumentRoot may point to a different directory. Check the virtual host configuration. On Nginx, check the server block’s root directive.
Is it safe to expose phpMyAdmin to the public internet?
No, it is not recommended. phpMyAdmin is a frequent target for brute-force attacks. If you must access it remotely, use a VPN or SSH tunnel. Alternatively, restrict access by IP address in the server configuration. For example, on Apache, add Require ip 192.168.1.0/24 inside the Directory block; on Nginx, use allow 192.168.1.0/24; deny all; inside the location block.