Installing phpMyAdmin for Apache on Ubuntu 18.04

Installing phpMyAdmin for Apache on Ubuntu 18.04 / 19.10

Last updated on | 31 replies

In this guide we will install and configure phpMyAdmin to work with Apache on Ubuntu Server 18.04 / 19.10.


You should be using a non-root user with sudo privileges as explained in Ubuntu 18.04 Initial Server Setup.

You should also have your LAMP stack already installed and serving web pages before continuing with this guide. Please see Installing a LAMP Stack (Apache, MySQL, PHP) on Ubuntu 18.04 / 19.10.

1. Install phpMyAdmin

Let’s begin by updating the package lists and installing phpMyAdmin on Ubuntu 18.04 / 19.10. Below we have two commands separated by &&. The first command will update the package lists to ensure you get the latest version and dependencies for phpMyAdmin. The second command will then download and install phpMyAdmin. Press y and ENTER when asked to continue.

sudo apt update && sudo apt install phpmyadmin

The order of the following screens in the phpMyAdmin Package configuration may vary depending on your setup.

If you are prompted to choose a web server, press SPACE to put a star [*] beside apache2, then press TAB to highlight OK and press ENTER.

Select Yes and press ENTER to install and configure the database.

The MySQL application password is only used internally by phpMyAdmin to communicate with MySQL. You can leave this blank and a password will be generated automatically. Just press ENTER to continue.

2. Test phpMyAdmin

You should now be able to access the phpMyAdmin web interface by visiting your server’s domain name or public IP address followed by /phpmyadmin. e.g. or

If you don’t have a domain name yet or don’t know your IP, you can find out with:

ip a | grep -Eo 'inet (addr:)?([0-9]*\.){3}[0-9]*' | grep -Eo '([0-9]*\.){3}[0-9]*' | grep -v ''

You will have set up the root user and password when installing MySQL for the first time. However, remote login might be disabled for root. If you get an error  “Access denied for user ‘root’@’localhost'”, you should continue to Step 3 to create a superuser just for phpMyAdmin.

3. Create MySQL User

If you weren’t able to log in as root above, you can now create a superuser account just for phpMyAdmin.

In terminal, log into MySQL as root. You may have created a root password when you installed MySQL for the first time or the password could be blank, in which case you can just press ENTER when prompted for a password.

sudo mysql -p -u root

Now add a new MySQL user with the username of your choice. In this example we are calling it pmauser (php my admin user). Make sure to replace  password_here with your own (generate a password).

The % symbol tells MySQL to allow this user to log in from anywhere remotely. If you want heightened security, you could replace this with an IP address.

CREATE USER 'pmauser'@'%' IDENTIFIED BY 'password_here';

Now we will grant superuser privileges to our new user pmauser.

GRANT ALL PRIVILEGES ON *.* TO 'pmauser'@'%';

Now exit MySQL.


You should now be able to access phpMyAdmin using this new user account.

If you would like to set up some additional security for phpMyAdmin, continue to the next step.

4. Obscure phpMyAdmin URL

Bots and attackers continuously scan web servers for the default phpMyAdmin login page, so it is recommended that you change the URL to something else.

In this example we are going to change it from to

Open the phpMyAdmin configuration file for Apache using the nano text editor.

sudo nano /etc/apache2/conf-available/phpmyadmin.conf

Change the Alias from /phpmyadmin to /pmahidden – you can change this to whatever you want.

# phpMyAdmin default Apache configuration

Alias /pmahidden /usr/share/phpmyadmin

Save and close nano (Press CTRL + X and then press y and ENTER to save changes)

Now you must reload the Apache service for changes to take effect.

sudo service apache2 reload

You should now be able to access phpMyAdmin at

5. Protect with .htpasswd

We can further protect the phpMyAdmin login page with .htpasswd. This adds another line of defence against bots and hackers.

5.1  Allow .htaccess Overrides

To set up .htpasswd, we must first change the phpMyadmin Apache configuration file to allow .htaccess Overrides.

Open the config file in nano text editor.

sudo nano /etc/apache2/conf-available/phpmyadmin.conf

Add AllowOverride All underneath DirectoryIndex index.php

<Directory /usr/share/phpmyadmin>
    Options SymLinksIfOwnerMatch
    DirectoryIndex index.php
    AllowOverride All

Save and close nano (Press CTRL + X and then press y and ENTER to save changes)

Now reload the Apache service.

sudo service apache2 reload

5.2 Set up .htpasswd

We are going to create a new .htaccess file in the phpMyAdmin install directory using the nano text editor.

sudo nano /usr/share/phpmyadmin/.htaccess

Paste in the following. (Use the right mouse button to paste if using PuTTY on Windows)

AuthType Basic
AuthName "Restricted Access"
AuthUserFile /etc/phpmyadmin/.htpasswd
Require valid-user

Save and close nano (Press CTRL + X and then press y and ENTER to save changes)

We can now generate the .htpasswd file using the htpasswd tool.

In this example, we are creating a new user called pmauser (php my admin user), though you can change this to whatever you want.

sudo htpasswd -c /etc/phpmyadmin/.htpasswd pmauser

You will be asked to enter a new password twice (generate a password).

That’s it, you’re done! Visit phpMyAdmin in your browser and you should now be prompted to enter login details.

6. Manually Update phpMyAdmin (Optional)

The repositories often don’t give you the latest releases of phpMyAdmin. If you would like to manually upgrade to the the latest version, see:

What Next?

By now you will have successfully implemented your LAMP stack (Apache/MySQL/PHP) for Ubuntu 18.04 / 19.10 and can administer MySQL through phpMyAdmin.

You may now want to configure SSL for you domain or set up an FTP server.

Let me know if this helped. Follow me on Twitter, Facebook and YouTube, or 🍊 buy me a smoothie.

31 replies

Leave a reply

Your email address will not be published. Required fields are marked *

    1. Please try

      sudo add-apt-repository ppa:phpmyadmin/ppa

      sudo apt-get update

      sudo apt-get install phpmyadmin

  1. On ubuntu version 19.04 if I try to install it from the shell, it answers me like this: The phpmyadmin package has no versions available, but is named by another
    package. This could indicate that the package is missing, obsolete
    or is available only within another source

  2. hey man, can’t we use root as user name and blank password ? like the one they did in XAMPP. (while using xampp, if we go to localhost/phpmyadmin we never see the login page. i hope you know it. like that one, can’t we skip the login autentication and use the root and the blank password while configuring phpmyadmin ? atleast the root user thing ?)

  3. i have installed phpmyadmin correctly but when i try to check it via localhost/phpmyadmin ,it says NOT FOUND the URL was not found in this server.
    what can be a problem here?

    1. Try this fix:

      sudo ln -s /etc/phpmyadmin/apache.conf /etc/apache2/conf-available/phpmyadmin.conf
      sudo a2enconf phpmyadmin
      sudo service apache2 reload

  4. Thank You for the Tutorial,

    It is working perfectly!

    But There are some issues, It is not possible to create database, the message is
    Create database
    No Privileges

    1. I followed your tutorial and i got is working perfectly but I was surprised that i couldnt access phpmyadmin with the user (firmtech) i earlier created. i get the errors below:

      #1045 – Access denied for user ‘firmtech’@’localhost’ (using password: YES)

      mysqli_real_connect(): (HY000/1045): Access denied for user ‘phpmyadmin’@’localhost’ (using password: YES)

      Connection for controluser as defined in your configuration failed.

      mysqli_real_connect(): (HY000/1045): Access denied for user ‘firmtech’@’localhost’ (using password: YES)

  5. I’m new learner LAMP stack, every your page i visit all very usefull. IT is not my major, So some purpose of changing in this article i don’t know that task to do?

  6. Thank you very much for your unique tutorial that I found working, until then I had been trying with mariadb and it always caused me a connection error 🙂

  7. I am having a problem when i’m trying to enter to the website by using the ip address/phpmyadmin, it says “The requested URL /phpmyadmin was not found on this server.”

  8. When I login to phpMyAdmin I have some annoying warning:

    Warning in ./libraries/sql.lib.php#613 count(): Parameter must be an array or an object that implements Countable Backtrace ./libraries/sql.lib.php#2128: PMA_isRememberSortingOrder(array) ./libraries/sql.lib.php#2079: PMA_executeQueryAndGetQueryResponse( array, boolean true, string 'phpmyadmin', string 'pma__favorite', NULL, NULL, NULL, NULL, NULL, NULL, string '', string './themes/pmahomme/img/', NULL, NULL, NULL, string 'SELECT * FROM`pma__favorite`', NULL, NULL, ) ./sql.php#221: PMA_executeQueryAndSendQueryResponse( array, boolean true, string 'phpmyadmin', string 'pma__favorite', NULL, NULL, NULL, NULL, NULL, NULL, string '', string './themes/pmahomme/img/', NULL, NULL, NULL, string 'SELECT * FROM`pma__favorite`', NULL, NULL, )
  9. I get the following error when I follow your guide, and the same when I retry.

    An error occurred while installing the database: │ │ │ │ ERROR 1045 (28000): Access denied for user 'debian-sys-maint'@'localhost' (using password: │ │ YES) . Your options are: │ │ * abort - Causes the operation to fail; you will need to downgrade, │ │ reinstall, reconfigure this package, or otherwise manually intervene │ │ to continue using it. This will usually also impact your ability to │ │ install other packages until the installation failure is resolved. │ │ * retry - Prompts once more with all the configuration questions │ │ (including ones you may have missed due to the debconf priority │ │ setting) and makes another attempt at performing the operation. │ │ * retry (skip questions) - Immediately attempts the operation again, │ │ skipping all questions. This is normally useful only if you have │ │ solved the underlying problem since the time the error occurred. │ │ * ignore - Continues the operation ignoring dbconfig-common errors. │ │ This will usually leave this package without a functional database. │ │ │ │ Next step for database installation: │ │ │ │ abort │ │ retry │ │ retry (skip questions) │ │ ignore │ │ │ │ │ │