How to Setup phpmyadmin on Ubuntu-Nginx (LEMP) Server

MySQL is a must have peice of software for any web server hosting websites. phpmyadmin can be used to manage MySQL on a server. What phpmyadmin does is, it gives graphical user interface for admins to manage MySQL with few clicks. It’s a free software and can be installed on a Ubuntu-Nginx (LEMP) server with few commands.

This tutorial will walk you through the setup of phpmyadmin on your Nginx server. And before I get started, I would like to mention that i’m not using phpmyadmin on my server. There’s nothing more phpmyadmin can do that command line can’t. So I prefer using command line to manage MySQL.

With that being said, let’s start the process of setting up phpmyadmin on Nginx server. I’m going to assume that you’ve followed my LEMP server setup tutorial to set up your server. If you’ve used a different source, it’s best to ask the author of that tutorial rather than following this. Because these codes are written for my Nginx setup and might need some modifications for other setups.

I’m going to use a sub domain for phpmyadmin. I prefer it over having phpmyadmin on a sub directory.

So, we’ll create an Nginx virtual host for phpmyadmin. following command should take care of that. You should always replace with your sub domain.

sudo mkdir -p /var/www/ /var/www/

Change to the directory you just created,

cd /var/www/

Download and unpack phpmyadmin,

sudo wget -O
sudo unzip
sudo mv phpMyAdmin*/* .
sudo rm

Setup permissions for virtual host directory,

sudo chown -R www-data:www-data /var/www/

Now it’s time that we let Nginx know our intention of running a virtual host on /var/www/ Procedure is same as adding a new domain or sub domain to the server. So let’s create a Nginx virtual host file for

sudo nano /etc/nginx/sites-available/

And paste this lot into that file,

server {
    access_log   /var/log/nginx/;
    error_log    /var/log/nginx/;
        root /var/www/;
        index index.php;
        location / {
                try_files $uri $uri/ /index.php?$args; 
        location ~ .php$ {
                include fastcgi_params;
                fastcgi_pass unix:/var/run/php5-fpm.sock;

Create a symbolic link to it on the sites-enabled directory,

sudo ln -s /etc/nginx/sites-available/ /etc/nginx/sites-enabled/

Restarting Nginx will activate to new virtual host.

sudo service nginx restart

phpmyadmin should now be online for you on your chosen sub domain. You can use any MySQL user account on your server to login to phpmyadmin. For example, you can use username root with MySQL root password to login to phpmyadmin.


Hey!! I'm Tharindu. I'm from Sri Lanka. I'm a part time freelancer and this is my blog where I write about everything I think might be useful to readers. If you read a tutorial here and want to hire me, contact me here.

Related Articles

Leave a Reply

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

Back to top button