How to install phpMyAdmin on Ubuntu + NGINX

How to install phpMyAdmin on Ubuntu + NGINX

phpMyAdmin is a very popular tool for managing MySQL databases. It can do many things, from modifying data to optimizing databases. But, the one thing it lacks by default is NGINX support. Just running sudo apt install phpmyadmin has support for Apache and Lighttpd, but nothing for NGINX.

Installing

To install phpMyAdmin, simply run:

sudo apt install phpMyAdmin

and if you’re prompted for which web server to configure, select nothing and continue the install. All files will be placed in /usr/share/phpmyadmin.

NGINX

I prefer to make a symlink instead of telling NGINX to read files directly from /usr/share. So, run:

sudo ln -s /usr/share/phpmyadmin /var/www/phpmyadmin

and you now have the equivalent of a folder containing phpMyAdmin in /var/www/phpmyadmin.

Next, create a file(/etc/nginx/sites-available/phpmyadmin.conf), and place the following in:

server {
        listen [::]:80; 
        listen *:80;

        index index.php;
        root /var/www/phpmyadmin;
        server_name phpmyadmin.example.com;

        location /{
                try_files $uri $uri/ index.php;
        }


        location ~ \.php$ {
               fastcgi_index index.php;
               try_files $uri =404;
                fastcgi_pass unix:/run/php/php7.0-fpm.sock;
               include /etc/nginx/fastcgi.conf;
        }
         location ~ /\.ht {
                deny all;
        }
}

You may need to change the PHP rules if you’re using a different version, but aside from that, all you need to change is the server name. Now, enable the site:

sudo ln -s /etc/nginx/sites-available/phpmyadmin.conf /etc/nginx/sites-enabled

Check the config:

nginx -t

and restart NGINX:

sudo service nginx restart

Using phpMyAdmin

You should now be able to go to the subdomain you configured, and be able to sign into phpmyadmin with any MySQL user. Preferably, sign in with a root MySQL user, so you don’t need to change users for each database you want to modify. However, if you’re using PHP 7, you’ll notice a ton of deprecation errors, which will follow you around. The solution is to disable php-fpm error reporting, which can be done by adding:

error_reporting = off    

to /etc/php/7.0/fpm/php.ini. Remove any other uncommented lines for error_reporting if you want this to work. After reloading php, you should not see any errors!

You know have phpMyAdmin working with NGINX!

Cloudflare

If you have Cloudflare, you might want to add a page rule to disable all caching, and increase the security level to maximum so bots can’t brute-force their way in to your database. Although, you should have nothing to fear because you have off-site DB backups 🙂 .

source

Leave a Reply(Markdown is On)

%d bloggers like this: