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 phpmyadmin.example.com with your sub domain.

sudo mkdir -p /var/www/phpmyadmin.example.com/htdocs/ /var/www/phpmyadmin.example.com/logs/

Change to the directory you just created,

cd /var/www/phpmyadmin.example.com/htdocs/

Download and unpack phpmyadmin,

sudo wget -O phpmyadmin.zip http://sourceforge.net/projects/phpmyadmin/files/latest/
sudo unzip phpmyadmin.zip
sudo mv phpMyAdmin*/* .
sudo rm phpmyadmin.zip

Setup permissions for virtual host directory,

sudo chown -R www-data:www-data /var/www/phpmyadmin.example.com/

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

sudo nano /etc/nginx/sites-available/phpmyadmin.example.com

And paste this lot into that file,

server {
        server_name phpmyadmin.example.com;
 
    access_log   /var/log/nginx/phpmyadmin.example.com.access.log;
    error_log    /var/log/nginx/phpmyadmin.example.com.error.log;
 
        root /var/www/phpmyadmin.example.com/htdocs;
        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/phpmyadmin.example.com /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.

Tharindu

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