While many users need the functionality of a database management system like MySQL, they may not feel comfortable interacting with the system solely from the MySQL prompt.
phpMyAdmin was created so that users can interact with MySQL through a web interface. In this guide, we’ll discuss how to install and secure phpMyAdmin so that you can safely use it to manage your databases on an Ubuntu 20.04 system.
1-Click deploy a database using DigitalOcean Managed Databases. Let DigitalOcean focus on scaling, maintenance, and upgrades for your database.
In order to complete this guide, you will need:
ufw
. To set this up, follow our initial server setup guide for Ubuntu.Additionally, there are important security considerations when using software like phpMyAdmin, since it:
For these reasons, and because it is a widely-deployed PHP application which is frequently targeted for attack, you should never run phpMyAdmin on remote systems over a plain HTTP connection.
If you do not have an existing domain configured with an SSL/TLS certificate, you can follow this guide on securing Apache with Let’s Encrypt on Ubuntu. This will require you to register a domain name, create DNS records for your server, and set up an Apache Virtual Host.
You can use APT package repository to install phpMyAdmin from the default Ubuntu repositories.
As your non-root sudo user, update your server’s package index:
Following that you can install the phpmyadmin
package. Along with this package, the official documentation also recommends that you install a few PHP extensions onto your server to enable certain functionalities and improve performance.
If you followed the prerequisite LAMP stack tutorial, several of these modules will have been installed along with the php
package. However, it’s recommended that you also install these packages:
php-mbstring
: A module for managing non-ASCII strings and convert strings to different encodingsphp-zip
: This extension supports uploading .zip
files to phpMyAdminphp-gd
: Enables support for the GD Graphics Libraryphp-json
: Provides PHP with support for JSON serializationphp-curl
: Allows PHP to interact with different kinds of servers using different protocolsBe aware that if you’re using a version of PHP other than the default one installed in the prerequisite LAMP stack tutorial, you will need to install the appropriate versions of these module packages. For instance, if you’re using PHP version 8.0, you will need to install the php8.0-mbstring
package instead of the default php-mbstring
package.
Run the following command to install these packages onto your system. Please note, though, that the installation process requires you to make some choices to configure phpMyAdmin correctly. We’ll walk through these options shortly:
Here are the options you should choose when prompted in order to configure and install phpmyadmin correctly:
apache2
Warning: When the prompt appears, “apache2” is highlighted, but not selected. If you do not hit SPACE
to select Apache, the installer will not move the necessary files during installation. Hit SPACE
, TAB
, and then ENTER
to select Apache.
Yes
when asked whether to use dbconfig-common
to set up the databaseNote: Assuming you installed MySQL by following Step 2 of the prerequisite LAMP stack tutorial, you may have decided to enable the Validate Password plugin. As of this writing, enabling this component will trigger an error when you attempt to set a password for the phpmyadmin user:
To resolve this, select the abort option to stop the installation process. Then, open up your MySQL prompt:
Or, if you enabled password authentication for the root MySQL user, run this command and then enter your password when prompted:
From the prompt, run the following command to disable the Validate Password component. Note that this won’t actually uninstall it, but just stop the component from being loaded on your MySQL server:
Following that, you can close the MySQL client:
Then try installing the phpmyadmin
package again and it will work as expected:
Once phpMyAdmin is installed, you can open the MySQL prompt once again with sudo mysql
or mysql -u root -p
and then run the following command to re-enable the Validate Password component:
The installation process adds the phpMyAdmin Apache configuration file into the /etc/apache2/conf-enabled/
directory, where it is read automatically. To finish configuring Apache and PHP to work with phpMyAdmin, the only remaining task in this section of the tutorial is to is explicitly enable the mbstring
PHP extension, which you can do by typing:
Afterwards, restart Apache for your changes to be recognized:
phpMyAdmin is now installed and configured to work with Apache. However, before you can log in and begin interacting with your MySQL databases, you will need to ensure that your MySQL users have the privileges required for interacting with the program.
When using phpMyAdmin with MySQL 8.0 (if you haven’t already, you’ll need to Install MySQL on Ubuntu before continuing with this guide), it’s important to understand the authentication method compatibility with different PHP versions:
MySQL 8.0 uses caching_sha2_password
as its default authentication plugin, which is more secure than the older mysql_native_password
. However, this can cause compatibility issues with older PHP versions:
caching_sha2_password
caching_sha2_password
caching_sha2_password
You can check your PHP version by running:
If you’re using PHP 7.2 or 7.3 and encounter authentication issues, you have two options:
Upgrade PHP (Recommended):
Switch to mysql_native_password (Alternative): If upgrading PHP isn’t possible, you can modify the MySQL user to use the older authentication method:
Warning: Using mysql_native_password
is less secure than caching_sha2_password
. It’s recommended to upgrade PHP instead of switching authentication methods.
To check which authentication method your MySQL user is using:
This will help you ensure your setup is using the appropriate authentication method for your PHP version.
When you installed phpMyAdmin onto your server, it automatically created a database user called phpmyadmin which performs certain underlying processes for the program. Rather than logging in as this user with the administrative password you set during installation, it’s recommended that you log in as either your root MySQL user or as a user dedicated to managing databases through the phpMyAdmin interface.
In Ubuntu systems running MySQL 5.7 (and later versions), the root MySQL user is set to authenticate using the auth_socket
plugin by default rather than with a password. This allows for some greater security and usability in many cases, but it can also complicate things when you need to allow an external program like phpMyAdmin to access the user.
In order to log in to phpMyAdmin as your root MySQL user, you will need to switch its authentication method from auth_socket
to one that makes use of a password, if you haven’t already done so. To do this, open up the MySQL prompt from your terminal:
Next, check which authentication method each of your MySQL user accounts use with the following command:
In this example, you can see that the root user does in fact authenticate using the auth_socket
plugin. To configure the root account to authenticate with a password, run the following ALTER USER
command. Be sure to change password
to a strong password of your choosing:
Note: The previous ALTER USER
statement sets the root MySQL user to authenticate with the caching_sha2_password
plugin. Per the official MySQL documentation, caching_sha2_password
is MySQL’s preferred authentication plugin, as it provides more secure password encryption than the older, but still widely used, mysql_native_password
.
However, some versions of PHP don’t work reliably with caching_sha2_password
. PHP has reported that this issue was fixed as of PHP 7.4, but if you encounter an error when trying to log in to phpMyAdmin later on, you may want to set root to authenticate with mysql_native_password
instead:
Then, check the authentication methods employed by each of your users again to confirm that root no longer authenticates using the auth_socket
plugin:
You can see from this output that the root user will authenticate using a password. You can now log in to the phpMyAdmin interface as your root user with the password you’ve set for it here.
Alternatively, some may find that it better suits their workflow to connect to phpMyAdmin with a dedicated user. You can create a user that connects either locally or remotely. For details on how to allow remote connection access to MySQL, you’ll need to configure MySQL to accept connections from other IP addresses. To start mysql locally, open up the MySQL shell once again:
If you have password authentication enabled for your root user, as described in the previous section, you will need to run the following command and enter your password when prompted in order to connect:
From there, create a new user and give it a strong password:
Note: Again, depending on what version of PHP you have installed, you may want to set your new user to authenticate with mysql_native_password
instead of caching_sha2_password
:
Then, grant your new user appropriate privileges. For example, you could grant the user privileges to all tables within the database, as well as the power to add, change, and remove user privileges, with this command (see our guides on creating MySQL users and granting permissions and managing PostgreSQL roles and permissions for more details):
Following that, exit the MySQL shell:
You can now access the web interface by visiting your server’s domain name or public IP address followed by /phpmyadmin
:
Log in to the interface, either as root or with the new username and password you just configured.
When you log in, you’ll see the user interface, which will look something like this:
Now that you’re able to connect and interact with phpMyAdmin, all that’s left to do is harden your system’s security to protect it from attackers.
Because of its ubiquity, phpMyAdmin is a popular target for attackers, and you should take extra care to prevent unauthorized access. One way of doing this is to place a gateway in front of the entire application by using Apache’s built-in .htaccess
authentication and authorization functionalities. For more details, see our guide on how to install and secure phpMyAdmin with Apache.
To do this, you must first enable the use of .htaccess
file overrides by editing your phpMyAdmin installation’s Apache configuration file.
Use your preferred text editor to edit the phpmyadmin.conf
file that has been placed in your Apache configuration directory. Here, we’ll use nano
:
Add an AllowOverride All
directive within the <Directory /usr/share/phpmyadmin>
section of the configuration file, like this:
When you have added this line, save and close the file. If you used nano
to edit the file, do so by pressing CTRL + X
, Y
, and then ENTER
.
To implement the changes you made, restart Apache:
Now that you have enabled the use of .htaccess
files for your application, you need to create one to actually implement some security.
In order for this to be successful, the file must be created within the application directory. You can create the necessary file and open it in your text editor with root privileges by typing:
Within this file, enter the following information:
Here is what each of these lines mean:
AuthType Basic
: This line specifies the authentication type that you are implementing. This type will implement password authentication using a password file.AuthName
: This sets the message for the authentication dialog box. You should keep this generic so that unauthorized users won’t gain any information about what is being protected.AuthUserFile
: This sets the location of the password file that will be used for authentication. This should be outside of the directories that are being served. We will create this file shortly.Require valid-user
: This specifies that only authenticated users should be given access to this resource. This is what actually stops unauthorized users from entering.When you are finished, save and close the file.
The location that you selected for your password file was /etc/phpmyadmin/.htpasswd
. You can now create this file and pass it an initial user with the htpasswd
utility:
You will be prompted to select and confirm a password for the user you are creating. Afterwards, the file is created with the hashed password that you entered.
If you want to enter an additional user, you need to do so without the -c
flag, like this:
Then restart Apache to put .htaccess
authentication into effect:
Now, when you access your phpMyAdmin subdirectory, you will be prompted for the additional account name and password that you just configured:
After entering the Apache authentication, you’ll be taken to the regular phpMyAdmin authentication page to enter your MySQL credentials. By adding an extra set of non-MySQL credentials, you’re providing your database with an additional layer of security. This is desirable, since phpMyAdmin has been vulnerable to security threats in the past.
If you’re using Nginx instead of Apache, check out our guide on installing and securing phpMyAdmin with Nginx for detailed instructions on setting up similar authentication.
Enabling SSL encryption for phpMyAdmin using a free Let’s Encrypt certificate is essential to protect sensitive data from potential attackers. This robust security measure guarantees that all data transmitted between your browser and the server is encrypted.
Start by installing Certbot and its Apache plugin:
Use the following command to obtain a certificate and automatically configure Apache:
The process is straightforward and user-friendly. Follow the prompts to select your domain name and allow HTTPS redirection. After a successful run, Certbot will handle HTTPS traffic for your server, including /phpmyadmin
.
Let’s Encrypt certificates expire every 90 days. Certbot sets up a systemd timer to renew them automatically:
Now you can access phpMyAdmin securely at:
Use this setup to enable phpMyAdmin SSL and prevent credential leaks.
If you’re using phpMyAdmin on a server without a public domain name or don’t want to expose it over the internet, you can tunnel access through SSH.
On your local machine, run:
Replace username
and your_server_ip
with your actual SSH credentials.
This command forwards local port 8888
to the server’s port 80
, where Apache serves phpMyAdmin.
Once the tunnel is active, open your browser and go to:
You now have secure, local-only access to phpMyAdmin — ideal for development or staging environments.
This is one of the best ways to secure phpMyAdmin on Ubuntu 20.04 in restricted-access scenarios.
Here are some of the most frequent errors users encounter while setting up or using phpMyAdmin — and how to fix them:
Cause: Apache didn’t properly link the config.
Fix:
Cause: Wrong credentials or insufficient MySQL privileges.
Fix: Log into MySQL and verify the user has the necessary access:
Cause: Session expired or cookies are corrupted.
Fix: Clear your browser cookies or restart your browser. You can also increase the session lifetime in php.ini
:
Restart Apache:
Cause: .htaccess
permissions or missing AllowOverride All
.
Fix:
Ensure .htaccess
is readable:
Check Apache config:
<Directory /usr/share/phpmyadmin>
AllowOverride All
</Directory>
To limit access even further, restrict phpMyAdmin to specific IP addresses.
Open your Apache config:
Inside the <Directory /usr/share/phpmyadmin>
block, add:
<RequireAll>
Require ip 203.0.113.4
Require valid-user
</RequireAll>
Replace 203.0.113.4
with your actual static IP. Then reload Apache:
This is a must-do if you’re running phpMyAdmin on production. It adds another layer of access control.
To install phpMyAdmin on an Ubuntu server, start by updating your package index using:
Then install the required packages:
These PHP modules ensure full functionality. During installation, select apache2
when prompted. Also confirm the use of dbconfig-common
to auto-configure the database. You’ll be asked to set a MySQL application password—use a strong one.
Once installed, enable mbstring
:
phpMyAdmin will be available at http://your_domain/phpmyadmin
. After installation, you should secure the interface with SSL and access controls to prevent unauthorized access.
By default, MySQL on Ubuntu uses the auth_socket
plugin for the root user, which doesn’t allow web-based login. To enable login via phpMyAdmin, you need to switch to password authentication.
Log into MySQL:
Then run:
Now, navigate to http://your_domain/phpmyadmin
, enter root
as the username and the password you just set. You’ll be able to log in.
However, for production, it’s not best practice to use the root user for daily tasks. Instead, create a separate user with limited privileges for accessing phpMyAdmin and keep root access disabled unless necessary.
Securing phpMyAdmin involves multiple layers of protection. First, enable HTTPS using Let’s Encrypt to encrypt traffic:
Next, enable .htaccess
authentication:
AuthType Basic
AuthName "Restricted Area"
AuthUserFile /etc/phpmyadmin/.htpasswd
Require valid-user
Use the htpasswd
utility to generate credentials:
Optionally, restrict access by IP in Apache’s configuration by adding:
<Directory /usr/share/phpmyadmin>
Order Deny,Allow
Deny from all
Allow from your.ip.address.here
</Directory>
Finally, restart Apache:
These steps dramatically improve security against unauthorized access.
For private, secure access, use SSH tunneling. This is especially useful when working from a trusted device or local development environment.
On your local machine, run:
This command creates a secure tunnel from your local port 8888 to the remote server’s port 80. You can now access phpMyAdmin at:
This method avoids exposing phpMyAdmin over the internet. Only users with SSH access to the server can reach the interface.
To improve this setup, consider using SSH keys instead of passwords and enabling two-factor authentication on your local SSH client.
A 403 error typically means that the server is denying access to phpMyAdmin due to a misconfiguration. Start by checking if Apache is set to allow overrides:
<Directory /usr/share/phpmyadmin>
AllowOverride All
</Directory>
Make sure .htaccess
exists and is readable by the web server. Check file ownership and permissions:
Restart Apache to apply changes:
If you’ve restricted by IP or via a .htaccess
file, ensure your client IP is allowed. Finally, check Apache error logs (/var/log/apache2/error.log
) to identify the specific reason for denial.
CSRF token mismatches happen when your session token is no longer valid. Common reasons include session timeout, expired login cookies, or corrupted sessions.
To fix this:
To increase session lifetime, edit php.ini
:
Then restart Apache:
This error can also appear if you restore a browser session from history or switch networks (causing IP mismatch). Always ensure phpMyAdmin is accessed freshly with a valid login.
Changing the URL helps obscure phpMyAdmin from bots and common scanners. Move the directory:
Then update Apache configuration:
Alias /dbadmin /usr/share/dbadmin
Save the config, then reload Apache:
Now, phpMyAdmin is accessible at http://your_domain/dbadmin
.
Make sure any hardcoded paths in the config or scripts are updated too. This method isn’t foolproof, but it adds another layer of security through obscurity.
If you want to remove phpMyAdmin and all related files, run:
Check if any database named phpmyadmin
exists in MySQL:
Removing it ensures there are no leftover credentials or sensitive information. You may also want to delete Apache config files:
This ensures a clean uninstall and frees up system resources.
Yes, phpMyAdmin works with Nginx, but setup differs since Nginx doesn’t support .htaccess
or built-in PHP. You’ll need PHP-FPM and custom rules.
Ensure PHP-FPM is installed:
Add to your Nginx config:
Secure with HTTPS using Certbot and consider adding basic auth.
Full guide: DigitalOcean phpMyAdmin on Nginx
The default installation path is:
Apache configuration is usually stored in:
To confirm it’s enabled:
You can also check Apache’s active configuration by running:
This will show you virtual host and alias mappings. If you modified the URL path or changed the default folder, remember to update any dependent scripts or users with the new location.
Absolutely. Check out our phpMyAdmin on Nginx guide for detailed instructions.
You should now have phpMyAdmin successfully installed, configured, and secured on your Ubuntu server. This web-based interface offers a user-friendly and powerful alternative to managing MySQL or MariaDB databases via the command line. With phpMyAdmin, you can easily create and manage databases, run SQL queries, import/export data, configure user privileges, and handle everyday administrative tasks.
In this guide, you’ve also taken key steps to harden your setup:
.htaccess
authentication to block unauthorized usersWhether you’re using this on a production server or a local development environment, the combination of these practices ensures that your database management layer is both functional and secure.
What’s next?
If you want to go further:
Launch a pre-configured Ubuntu server in minutes with DigitalOcean Droplets – a scalable, SSD-backed environment perfect for running phpMyAdmin and your entire LAMP stack.
You’re now ready to manage your databases confidently through a secure and intuitive interface.
Continue building with DigitalOcean Gen AI Platform.
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
Hello Mark,
thanks for the tutorial, could follow well. Just had a problem to access phpmyadmin via localhost. I got a 404 error.
What helped was:
Source: https://help.ubuntu.com/community/ApacheMySQLPHP#Troubleshooting_Phpmyadmin_.26_mysql-workbench
In case anybody else has the same problem. Cheers, Thomas
Hi Mark!
I followed the tutorial but the address to access phpmyadmin does not work. I have an error “The request URL was not found on this server”. And apparently the file sudo nano /etc/apache2/conf-available/phpmyadmin.conf does not exist because when i tried to open it was empty. I need help for today. Please
Thanks a lot.
This doesnt help for the Worpress Droplet. I keep getting errors about user debian-sys-maint not having enough rights to configure phpmyadmin package while installing.
Package phpmyadmin is not available, but is referred to by another package. This may mean that the package is missing, has been obsoleted, or is only available from another source
E: Package ‘phpmyadmin’ has no installation candidate
Hi all. Mark, thank you for the great tutorial. I did something unintended, namely, I copied this phrase into my terminal and now I have a user username.
It is no big problem, but I want to keep my administration nice and tidy. How can I remove this user username? I have created a user with the name that I want to use, so that I can enter phpmyadmin.
Hello Mark,
I’m trying to run a create table SQL and it’s giving me the following error:
Here is my SQL:
Here’s a screencast: https://gyazo.com/4ec6302e8f595327455908cb91c34a83
It seems to be working fine for some other types (e.g. mediumint / date). For example the following sql works:
Followed the above instructions a few times and it’s giving me the same error. Any insight on what the issue is?
Thanks in advance, Will
Step 2 — Adjusting User Authentication and Privileges -> I completed this step on a brand new D.O. Ubuntu 20.4 install that followed the D.O. LAMP guide and I’ve lost all access to MySQL. Per the LAMP setup guide I configured a complex password for MySQL in case authentication needed to be switched from UNIX_Socket to Password (seems they recommend against it) and… I cannot log into MySQL nor change the password. Surely I had a misstep but can’t figure out where!
Mark, would you be able to do a similar guide for a LEMP stack? Cheers
:D What I like DigitalOcean is guide article is best with detail on how to get me walkthrough any technical problem.
Clear and know what the step will be error and get fix. Keep it up.