Home WebserverApache Install phpMyAdmin With LAMP Stack On Ubuntu 18.04 LTS
install phpMyAdmin with LAMP

Install phpMyAdmin With LAMP Stack On Ubuntu 18.04 LTS

By sk

PhpMyAdmin is a free and open source web-based database management tool written in PHP. It allows the database administrators to easily manage single and/or multiple database servers either from a local or remote system via a web browser. This can be useful for those who are not comfortable with MySQL prompt. Using phpMyAdmin, we can do all sorts of database management tasks such as creating, editing, renaming, deleting databases, import and export databases, create tables, fields and fields, execute SQL commands and many. In this tutorial, we will see how to install phpMyAdmin with LAMP stack on Ubuntu 18.04 LTS server operating system.

Install phpMyAdmin With LAMP Stack On Ubuntu 18.04 LTS

Before installing phpMyAdmin on your Ubuntu 18.04 LTS server, make sure you have setup LAMP stack as described in the link below.

Also make sure you've changed the password authentication method for mysql root user as described under section titled "2.2 Change authentication method for MySQL root user" in the above guide. You must do this if you want to manage database server using any external programs such as phpMyAdmin.

Once you've setup LAMP stack, enable 'universe' repository, which is disabled by default on Ubuntu 18.04.  To do so, run:

$ sudo add-apt-repository universe

Now is the time to install phpMyAdmin.

To install phpMyAdmin on Ubuntu 18.04, run:

$ sudo apt update
$ sudo apt install phpmyadmin php-mbstring php-gettext

Now, select the web server that should be automatically configured to run phpMyAdmin. Choose the web server with UP/DOWN arrows and hit the SPACEBAR key. Once you chose the web server, you will see a * (star) symbol in-front of it. Hit the TAB key to choose OK and again hit ENTER key to continue.

phpmyadmin 1

Configure phpMyAdmin with Apache web server

Hit ENTER to continue.

phpmyadmin 2

Choose Yes to configure database for phpmyadmin:

phpmyadmin 3

Provide mysql application password phpmyadmin.

phpmyadmin 4

Re-enter password:

phpmyadmin 5

Once phpmyadmin is installed, enable mbstring php extension and restart Apache service o update the changes as shown below.

$ sudo phpenmod mbstring
$ sudo systemctl restart apache2

You can now verify if mbstring extension is enabled or not by loading into info.php file from the web browser.

php mbstring

As you can see in the above screenshot, mbstring module is enabled.

Create dedicated user to access phpMyAdmin dashboard

Once phpMyAdmin is installed, a database user named 'phpmyadmin' will be automatically created with the administrative password you set during the installation. You can login to phpmyAdmin dashboard using 'phpmyadmin' user or mysql root user. However, it is recommended to create a dedicated user to manage databases via phpMyAdmin web interface.

To do so, login to mysql shell using command:

$ mysql -u root -p

Enter your mysql root password. You will now be in mysql shell.

Enter the following command to create a new dedicated user for phpmyadmin:

CREATE USER 'phpmyadminuser'@'localhost' IDENTIFIED BY 'password';

Here, phpmyadmin is the new user for accessing phpmyadmin dashboard. The password for phpmyadminuser is password. Replace these values with your own.

Next give the appropriate privileges to the 'phpmyadminuser' using command:

GRANT ALL PRIVILEGES ON *.* TO 'phpmyadminuser'@'localhost' WITH GRANT OPTION;

Finally exit from mysql shell:

phpmyadmin 6

Create new user for phpmyadmin

We have now created a dedicated user (phpmyadminuser/password) for managing the databases via phpmyadmin web interface. Let us go ahead and access phpmyadmin dashboard.

Access phpMyAdmin dashboard

Open your web browser and navigate to http://ip-address/phpmyadmin or http://domain/phpmyadmin. You should see the phpmyadmin login page. Log in to the phmyadmin interface either using mysql root user or the new user which we created in the previous step.

phpmyadmin 7

Log in to phpMyAdmin interface

Here is how phpMyAdmin dashboard looks:

phpmyadmin 8

PhpMyAdmin dashboard

From now on, you can manage your databases via phpMyAdmin web interface.

Secure phpMyAdmin

Since phpMyAdmin is an easy target for attackers, the next recommended task is to secure phpyMyAdmin. The most common way to protect phpMyAdmin from unauthorized access is by using Apache's built-in .htaccess authentication and authorization functionalities.

First of all, enable the use of .htaccess file overrides by editing the /phpmyadmin.conf file:

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

Add "AllowOverride All" line within the <Directory /usr/share/phpmyadmin> section as shown below.

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


phpmyadmin 9

Save and close the file.

Restart apache service to update the changes using command:

$ sudo systemctl restart apache2

Next, create a file named .htaccess within /usr/share/phpmyadmin/ directory using command:

$ sudo nano /usr/share/phpmyadmin/.htaccess

Add the following lines in it:

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

Save and close the file.

Now, run the following command to create a new user, for example ostechnix:

$ sudo htpasswd -c /etc/phpmyadmin/.htpasswd ostechnix

Replace 'ostechnix' with any username of your choice. You will asked to provide a password for the new user. Enter it twice.

Sample output:

New password: 
Re-type new password: 
Adding password for user ostechnix

We have now added an extra layer of security to access phpMyAdmin web interface. From now on, whenever you try to access the phpMyAdmin web interface, you will prompted to enter the additional username and its password that you just configured in the previous step.

phpmyadmin 10

Once you entered the correct username and password, you will be redirected to the actual phpmyadmin authentication login page. Just enter your database credentials to access the dashboard.


Thanks for stopping by!

Help us to help you:

Have a Good day!!

You May Also Like


A random linux user February 9, 2019 - 2:42 am

Thank You for this tutorial, works like a charm.

Jean April 12, 2019 - 7:07 pm

Awesome! Thanks for great tutorial.

fk May 1, 2019 - 11:15 pm

Thank you. This is very good and accurate.

subadrun May 4, 2019 - 12:41 am

how to fix ERROR 1698 (28000): Access denied for user ‘root’@’localhost’

sk May 4, 2019 - 12:12 pm

Instructions to fix this error is given in this guide. Please have a look under “2.1 Setup database administrative user (root) password” section. https://ostechnix.com/install-apache-mariadb-php-lamp-stack-ubuntu-16-04/

Bashar May 10, 2019 - 6:37 pm

Thanks a lot it worked perfectly!

hkm May 25, 2019 - 6:48 am

thank you

alvaro June 20, 2019 - 8:24 pm

pls help my

Configuring phpmyadmin
An error occurred while installing the database:

ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/var/run/mysqld/mysqld.sock’ (2) . 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:

retry (skip questions)

sk June 20, 2019 - 8:37 pm

Check this link. https://stackoverflow.com/questions/11657829/error-2002-hy000-cant-connect-to-local-mysql-server-through-socket-var-run.
As mentioned in this link, just install only mysql, not mysql-client and see if it solves your problem. .

sk June 20, 2019 - 8:38 pm

Setup LAMP stack as described in this guide. https://ostechnix.com/install-apache-mysql-php-lamp-stack-on-ubuntu-18-04-lts/
And then, try to install Phpmyadmin.

DEMOS June 24, 2019 - 3:42 am

Thanks a lot. Since now my problem with “Access denied for user ‘root’@’localhost’ (using password: YES)” is solved!!!

Arvind July 24, 2019 - 12:00 pm

It was Really Awesome till I found. Without any Error, I installed it. I just go through each step and I didnt get any error during installation. Thanks.
Now Please tell me How to install wordpress after that.

sk July 24, 2019 - 6:26 pm

We will publish a separate guide for wordpress installation. Thanks for your positive feedback.

panca September 26, 2019 - 10:24 am


Michael Mendes November 2, 2019 - 9:07 am

Thank you!

alamin November 6, 2019 - 5:22 am

I do all thing before section ‘Access phpMyAdmin dashboard’ but phpmyadmin is 404 not found. Please give a solution!

sk November 6, 2019 - 12:27 pm

That’s odd. Have you already setup LAMP stack? If yes, please try on a fresh system. The instructions given in this guide have been properly tested in Ubuntu 18.04 LTS server and it worked fine for me.

Arif November 9, 2019 - 9:41 am


Not Found
The requested URL was not found on this server.

Arif November 9, 2019 - 11:09 pm

phpmyadmin.conf file not found, why?

sk November 10, 2019 - 10:09 pm

Try on a freshly installed system again. The guide is working for me as far as I tested.

J.F November 16, 2019 - 3:31 am

Hello! Thanks a lot for the tutorial!

I had phpmyadmin is 404 not found problem and solved it doing:

sudo vi /etc/apache2/apache2.conf

Include /etc/phpmyadmin/apache.conf

//RESTART apache2
sudo systemctl restart apache2


Jelly December 24, 2019 - 9:45 pm

At the stage “Now, select the web server that should be automatically configured to run phpMyAdmin.” I have hit Enter. And when I remove and reinstall the all, I don’t have the new ask for reconfigure PhpMySql.
Help me please !

AndyN January 17, 2020 - 8:42 pm

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

phpmyadmin.conf is blank and empty new file when you run this command.. is the path diferent/changed

sk January 18, 2020 - 2:35 pm

The path to phpmyadmin.conf is correct when I tested it in Ubuntu 18.04 server. May be it is changed now. Please check the phpmyadmin official documentation.

bloon head January 17, 2020 - 11:03 pm

dude thanks please dont change this guide accpet i hate that update change things and this probly wont work in a year so ive done it and duplicated hard disks plus made a copy of all the files needed to do this from scratch and saved this guide … its awesome thanks

Diaz Alief January 30, 2020 - 11:25 pm

Not Found
The requested URL was not found on this server.

Apache/2.4.29 (Ubuntu) Server at Port 80

Alexandre March 28, 2020 - 8:16 pm

Thank you very much for your explanations. It works perfectly.

Pankaj kumar August 27, 2020 - 12:39 am

I need to access the PHPMyAdmin from the outside the ubuntu but I’m not able to do that. could you please tell me the solution. I have disabled the firewall as well.

sk August 27, 2020 - 11:49 am

What do you mean by outside? Do you want to access it from WAN or just LAN? If you want to access it from WAN, you may need a public IP.


Leave a Comment

* By using this form you agree with the storage and handling of your data by this website.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More