This guide walks you through installing phpMyAdmin on a CentOS server running Nginx, giving you a web-based interface to manage MySQL or MariaDB databases. You’ll need root or sudo access to your server, a working Nginx installation, and PHP with the necessary extensions (php-fpm, php-mysqlnd, etc.) already configured. By the end, you’ll have phpMyAdmin accessible via HTTPS on your domain or IP.
What You’ll Need
- A CentOS server (7, 8, or 9) with Nginx installed and running.
- PHP 7.4 or newer with php-fpm and the mysqli or pdo_mysql extension enabled.
- MySQL or MariaDB server installed and running.
- Root or sudo access to the command line.
- Optional but recommended: a domain name pointing to your server and an SSL certificate (Let’s Encrypt).
Step-by-Step
- Update your system
Runsudo yum update -y(orsudo dnf update -yon CentOS 8+) to ensure all packages are current. - Install EPEL repository
phpMyAdmin is not in the default CentOS repos. Install EPEL:sudo yum install epel-release -y(orsudo dnf install epel-release -y). - Install phpMyAdmin
Runsudo yum install phpmyadmin -y(orsudo dnf install phpmyadmin -y). This installs the package and its dependencies, including PHP extensions if needed. - Configure phpMyAdmin for Nginx
The default configuration is for Apache. Create an Nginx server block or edit an existing one to serve phpMyAdmin. Typically, you’ll add alocationblock inside your server block. For example, create/etc/nginx/conf.d/phpmyadmin.confwith:server { listen 80; server_name your_domain_or_IP; root /usr/share/phpMyAdmin; index index.php; location / { try_files $uri $uri/ =404; } location ~ \.php$ { include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_pass unix:/run/php-fpm/www.sock; # Adjust to your php-fpm socket fastcgi_index index.php; } location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ { expires max; log_not_found off; } }Adjust the
fastcgi_passto match your php-fpm configuration (check/etc/php-fpm.d/www.conffor the listen directive). - Set proper file ownership and permissions
Ensure the web server can read the phpMyAdmin files:sudo chown -R root:nginx /usr/share/phpMyAdmin(or useapacheif that’s your nginx user) andsudo chmod -R 755 /usr/share/phpMyAdmin. - Configure phpMyAdmin to connect to MySQL
Edit/etc/phpMyAdmin/config.inc.php(or/etc/phpmyadmin/config.inc.php). Ensure the$cfg['Servers'][$i]['host']is set tolocalhostor127.0.0.1. If you use a socket, set it accordingly. For most setups, the default works. - Test and restart Nginx and PHP-FPM
Runsudo nginx -tto check the configuration. Then restart services:sudo systemctl restart nginxandsudo systemctl restart php-fpm. - Access phpMyAdmin
Open your browser and go tohttp://your_domain_or_IP/. You should see the phpMyAdmin login page. Log in with a MySQL user (e.g., root). - Secure with HTTPS (recommended)
Use Let’s Encrypt to get a free SSL certificate:sudo yum install certbot python3-certbot-nginx -ythensudo certbot --nginx -d your_domain. Follow the prompts.
Common Mistakes
- Wrong php-fpm socket path – If the socket path in your Nginx config doesn’t match the one in php-fpm, you’ll get a 502 Bad Gateway error.
- Missing PHP extensions – phpMyAdmin requires the mysqli extension. If it’s missing, you’ll see a blank page or a warning. Install with
sudo yum install php-mysqlnd. - File permissions too restrictive – If Nginx can’t read the phpMyAdmin files, you’ll get a 403 Forbidden error. Ensure the ownership and permissions are correct.
- Using Apache’s .htaccess directives – Nginx ignores .htaccess files. If you copied an Apache config, you’ll need to translate those rules into Nginx syntax.
- Not restarting services after changes – Always restart Nginx and php-fpm after modifying configs.
Tips
- Use a dedicated subdomain – Serve phpMyAdmin on something like
db.example.comto avoid exposing it on the main domain and to simplify SSL configuration. - Restrict access by IP – Add
allow YOUR_IP; deny all;in the server block to limit who can reach phpMyAdmin. This is a strong security measure. - Enable two-factor authentication – phpMyAdmin supports plugins like the TOTP (time-based one-time password) to add a second layer of security.
- Keep it updated – Regularly run
sudo yum update phpmyadminto get security patches. - Backup your config – Before editing config files, copy them:
sudo cp /etc/phpMyAdmin/config.inc.php /etc/phpMyAdmin/config.inc.php.bak.
Troubleshooting
- 502 Bad Gateway – This usually means Nginx can’t reach php-fpm. Check the socket path in your Nginx config and the
listendirective in/etc/php-fpm.d/www.conf. Also verify php-fpm is running:sudo systemctl status php-fpm. - 403 Forbidden – Likely permission issues. Check that the
rootdirective points to the correct directory and that the user running Nginx has read access. Also check SELinux:sudo setsebool -P httpd_can_network_connect 1orsudo chcon -R -t httpd_sys_content_t /usr/share/phpMyAdmin. - Blank page after login – This often indicates a PHP error. Check the PHP error log:
sudo tail -f /var/log/php-fpm/error.log. Make sure the mysqli extension is enabled in/etc/php.ini. - “Cannot load mysqli extension� – Install it with
sudo yum install php-mysqlndand restart php-fpm. - Access denied for user – You’re using wrong credentials or the MySQL user is not allowed to connect from localhost. Check your MySQL user permissions.
- SSL certificate not working – If using Let’s Encrypt, ensure port 80 is open and that your domain resolves to your server. Run
sudo certbot renew --dry-runto test.
Frequently Asked Questions
Can I install phpMyAdmin without EPEL?
Yes, you can download the tarball from the official phpMyAdmin site and place it in your web root, but EPEL is the easiest method on CentOS.
Is it safe to use phpMyAdmin on a public server?
It can be safe if you use HTTPS, strong passwords, restrict access by IP, and keep it updated. Avoid using the root MySQL account for web access.
How do I change the default login timeout?
Edit config.inc.php and set $cfg['LoginCookieValidity'] = 3600; (or your desired seconds). Also ensure PHP’s session.gc_maxlifetime is at least as high.
Why do I get a 404 when accessing phpMyAdmin?
Your Nginx server block may not be pointing to the correct root, or the location block is misconfigured. Double-check the root and try_files directives.
Can I use phpMyAdmin with MariaDB?
Yes, phpMyAdmin works with both MySQL and MariaDB. No special configuration is needed.
How do I uninstall phpMyAdmin?
Run sudo yum remove phpmyadmin and delete any Nginx config files you created for it.
Related
Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.
More cards in this drawer
- Mac Start Up Automatically After Power Failure?
- Expose Self-Hosted Service Securely Without Cloudflare Tunnel
- Nano Delivery for Functional Foods: What It Can and Can’t Do4.00
- Disable Apple Watch Turn-by-Turn Vibration While Driving
- Convert Play FLAC in iTunes: Full Guide
- Soda Foundation Charter: What It Means