Alex Grebeshkov

System administration. Cloud solutions. Information security. Business & entrepreneurship

PhpMyAdmin + Nginx Installation and Configuration for CentOS 7 Quick How-To

Please, share if you find the info useful!

Recently I found out that most tutorials and how-tos on installing PhpMyAdmin and configuring it to work with Nginx web server under the CentOS 7 end up in failure if being followed step-by-step. That’s why I give you this simple to follow manual that will give you 100% working PhpMyAdmin environment in about 10 minutes.

I assume that you’ve already installed and configured Nginx and PHP, so let’s go straight to PhpMyAdmin installation.

1. Add the EPEL (Extra Packages for Enterprise Linux) Repository

First of all, we add the EPEL repository to the system, as PhpMyAdmin package is not available in the default CentOS repos:

sudo yum install epel-release

2. Install PhpMyAdmin package

To install the PhpMyAdmin package, run:

sudo yum install phpmyadmin

This will download the package will all the dependencies and install them.

3. Configuring Nginx

After the installation is complete, you have to create a config file for Nginx in /etc/nginx/conf.d/, as PhpMyAdmin does not do it automatically. Let’s do it straight away:

sudo nano /etc/nginx/conf.d/phpMyAdmin.conf

This will open nano (you may use any text editor you like, for example, vi). Now you can paste this dummy config contents and edit it to your liking:

server {
listen 80;
server_name phpmyadmin.YourDomain.com;
root /usr/share/phpMyAdmin;

location / {
index index.php;
}

## Images and static content is treated different
location ~* ^.+.(jpg|jpeg|gif|css|png|js|ico|xml)$ {
access_log off;
expires 30d;
}

location ~ /\.ht {
deny all;
}

location ~ /(libraries|setup/frames|setup/libs) {
deny all;
return 404;
}

location ~ \.php$ {
include /etc/nginx/fastcgi_params;
fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /usr/share/phpMyAdmin$fastcgi_script_name;
}
}

Some notes. server_name stands for the subdomain that you would like to assign for your PhpMyAdmin installation. You can name it anything you like: pma.yourdomain.com, db.yourdomain.com etc. Note, that you will also have to change the DNS settings for your subdomain and point the CNAME DNS record to the public IP address of your server.

You can download this dummy configuration file here.

To enable the configuration, restart Nginx:

sudo service nginx restart

4. Test the setup

Now you are ready to go and test the configuration. Just visit http://phpmyadmin.yourdomain.com and if you did everything correctly, you should see this:

That is it.

Let me know in the comments if this tutorial helped you set up the phpMyAdmin for Nginx on CentOS.


You can find even more information on setting up the LAMP stack for CentOS 7 server in my online course “CentOS Linux Server Setup Essentials”. Do check it out, as this is a comprehensive guide to personal server setup: from CentOS installation to configuring personal web hosting platform.


 

Tags: , , , ,

Leave a Reply