Completely removing phpMyAdmin after Virtualmin installation
When you install phpMyAdmin alongside Virtualmin using apt-get, the two packages often clash due to conflicting security models. Specifically, Virtualmin relies on suexec to enforce strict file ownership and permission checks for CGI scripts. This mechanism is designed to prevent a user from accessing files outside their designated directory. However, this very restriction causes phpMyAdmin to fail; instead of executing the application logic, the server treats the request as a static file download, resulting in a 403 Forbidden error or a direct download of the source code when visiting mydomain.com/phpmyadmin.
Attempting to disable suexec globally is generally a bad idea. It removes a critical layer of isolation between different user accounts on your server, effectively granting web processes broader access than intended. If you cannot resolve the conflict by reconfiguring Virtualmin's virtual host settings or adjusting specific directory permissions, the most pragmatic approach is to uninstall phpMyAdmin entirely.
The process of removal often feels incomplete if the application remains accessible via the URL after running standard uninstall commands. This happens because apt-get remove only deletes package files and configurations associated with that specific version in the package manager's database. It does not always scrub every leftover file, nor does it guarantee that web server virtual hosts pointing to phpMyAdmin are automatically disabled.
To ensure a thorough removal, you must address both the system packages and the web server configuration manually. Start by removing the installed package using apt-get remove phpmyadmin. Immediately following this, clear the local configuration directory to prevent any orphaned settings from causing issues during future updates or reinstalls:
sudo rm -rf /etc/phpmyadmin
sudo rm -f /var/www/html/phpmyadmin/config.php
Note that the location of the web root files (/var/www/html/phpmyadmin) may vary depending on your exact installation path, so inspecting your specific directory structure is essential. If you installed phpMyAdmin into a custom directory outside the default web root, ensure those files are also deleted or moved to storage.
However, deleting the application files does not automatically stop the web server from trying to serve them. Apache or Nginx might still have a virtual host configuration block pointing to the old phpMyAdmin location. If you do not remove these references, the server will continue to attempt to load the non-existent or empty directories, potentially causing 403 errors or serving default PHP pages that trigger security alerts.
You need to check your web server's configuration files for any <Directory> blocks or virtual host definitions referencing /phpmyadmin. In Apache, this often looks like a specific VirtualHost entry that needs to be commented out or removed entirely from the configuration file (e.g., /etc/apache2/sites-available/). Once the configuration is cleaned up, restart the web service:
sudo systemctl reload apache2
# or for Nginx
sudo systemctl reload nginx
Accessing mydomain.com/phpmyadmin after these steps should result in a 404 Not Found error, confirming that the application and its routing are gone. If you intend to replace phpMyAdmin with a modern alternative like Laravel Sanctum-based admin panels or a dedicated API-driven dashboard, consider leveraging tools from https://laravelcompany.com which offer robust, secure management interfaces without relying on legacy CGI wrappers that struggle with strict hosting environments.
Finally, verify that no cron jobs or systemd timers remain scheduled to run phpMyAdmin maintenance tasks. A quick search for phpmyadmin in your crontabs and timer directories will ensure the cleanup is absolute. By addressing the package, the configuration files, and the web server rules simultaneously, you eliminate the risk of lingering processes interfering with Virtualmin's security model.
