Ubuntu 18.04 Server / How to Install phpMyAdmin
To install phpMyAdmin on Ubuntu 18.04 Server, prepare Apache, PHP, and MySQL or MariaDB, then install the phpmyadmin package and log in with a database account. Before installation, restrict access paths so that the admin tool is not exposed externally, and do not change the authentication settings for the database root.
Things to Check Before Installation
phpMyAdmin is a tool for managing MySQL or MariaDB databases and tables through a web browser. This article describes the case of using Apache on an existing Ubuntu 18.04 Server. If you are using a separate web server and database server or using Nginx, the connection path and settings will be different.
The standard security maintenance for Ubuntu 18.04 LTS ended in May 2023. For existing systems, it is recommended to upgrade to a supported Ubuntu version. If you cannot upgrade immediately, check whether Ubuntu Pro's security maintenance is applied and the update scope for phpMyAdmin, PHP, and database packages. For more details, refer to Ubuntu Security Maintenance Guide.
The following example assumes you have sudo privileges, Apache, PHP, and MySQL or MariaDB already installed, and can access the server via SSH. Back up your database and check package repositories and existing site configurations before installation. Since Apache settings may be automatically applied during installation, restrict access from external sources first using a firewall or private network.
Restricting the Management Path in Apache
The following example shows how to connect directly to Apache and allow only local connections to the server. First, create the file /etc/apache2/conf-available/phpmyadmin-local.conf and save the following content.
<Location /phpmyadmin>
Require local
</Location>
After activating the settings, check the syntax and reload Apache only if it passes successfully.
sudo a2enconf phpmyadmin-local
sudo apache2ctl configtest
When Syntax OK is displayed, execute the following command. If there are errors, modify the settings and check again.
sudo systemctl reload apache2
This configuration applies to the example path. If you have other aliases or virtual hosts, check those paths as well. If a reverse proxy is in front, Apache might see the proxy address as the client address, so access restrictions cannot be guaranteed with this example alone. Review the handling of actual client addresses by trusted proxies and the firewall separately. You can check the Require directive in Apache's access control documentation.
Installing phpMyAdmin
Update the package list and install it. Package availability and versions may vary depending on repository and security maintenance settings.
sudo apt update
sudo apt install phpmyadmin
When an interactive installation screen is displayed, check the following:
- On the web server selection screen, choose Apache2. Ensure it is checked before proceeding. Simply pressing Enter may not select the item.
- If asked about the
dbconfig-commonconfiguration, select Yes if you want the package to configure a database for phpMyAdmin's additional features. This database is different from the application databases you are managing. If you plan to manage existing settings yourself, you can choose No. - On the screen that asks for a password, check the displayed account and purpose, and enter a secure password. The database administrator authentication required during the setup process may vary depending on the authentication method of the existing server.
After installation, check the configuration files and whether the Apache service. The settings for the Ubuntu package are mainly in /etc/phpmyadmin and may vary depending on the package configuration.
ls /etc/phpmyadmin
systemctl status apache2 --no-pager
Access via SSH tunnel
Open the SSH client on the administrator PC and run the following command. Replace user and server with the actual SSH account and server address. It connects port 8080 on the administrator PC to the server's local port 80 and can be used while the SSH connection is maintained.
ssh -L 127.0.0.1:8080:127.0.0.1:80 user@server
Open http://127.0.0.1:8080/phpmyadmin in the browser on the same PC. The browser and SSH client must run on the same PC, and Apache on the server must serve the path on local port 80. When the login screen appears, enter the allowed database username and password. Ending the SSH session will also close the tunnel.
If your environment is configured to access directly via HTTPS, a valid TLS certificate and separate access restrictions are required. Set the allowed IPs in your firewall or Apache according to the actual administrator address, and check the access results from both allowed and disallowed addresses. It is recommended not to expose the admin page to the entire internet.
Login accounts and permissions
phpMyAdmin login is authenticated using a MySQL or MariaDB account. Use a dedicated account with permissions only for the databases and operations necessary for your operations. The account’s host and permissions must match the settings on the actual database server. Double-check the target and backup before uploading files or making data changes.
The Linux root account and the database root account are different. If the database root is configured for local socket authentication, it may not be usable for web login. Do not try to solve this by directly modifying system tables or emptying the root authentication plugin. Create a separate account with the required permissions and follow the account management documentation for that database product.
When unable to connect
- 403 Forbidden: Check whether access restrictions are applied and whether you are using an SSH tunnel. Also, verify the client address recognized by the proxy and Apache.
- 404 Not Found: Make sure Apache2 was selected during installation and that phpMyAdmin's Apache configuration is enabled. If you are using other virtual hosts or aliases, check those settings as well.
- Login Failed: Verify the database username, password, connection host, and permissions. The web server account or SSH account can be different from the database account.
- PHP Page Error: Check the integration of Apache and PHP, required PHP extensions, and Apache error logs. Installation and configuration paths may vary depending on the distribution package.
If you need to revert configuration changes, restore from an existing backup and recheck the syntax. Disabling the local restriction settings in this article may expose the administration path to external access due to other configurations, so first ensure alternative access controls are applied. For phpMyAdmin's installation and security settings, refer to the official installation documentation.




