Amazon EC2环境下隐藏phpMyAdmin路由并修改访问路径咨询
How to Change phpMyAdmin's Access Path on Amazon EC2
Got it, let's walk through how to hide phpMyAdmin's default /phpmyadmin route and switch it to a custom path like /sampleroute on your EC2 instance. The steps depend on which web server you're using—here's how to do it for both Apache and Nginx, the most common options on EC2:
For Apache Web Server
- Locate the phpMyAdmin config file
On Ubuntu/Debian systems, this is usually at/etc/phpmyadmin/apache.conf. For Amazon Linux/RHEL, check/etc/httpd/conf.d/phpmyadmin.conf. - Modify the Alias directive
Find the line that looks like:
Change it to your custom route:Alias /phpmyadmin /usr/share/phpmyadminAlias /sampleroute /usr/share/phpmyadmin - Update the Directory block (if needed)
Make sure the<Directory /usr/share/phpmyadmin>block matches the path you set in the Alias—this ensures Apache has permission to serve the phpMyAdmin files. - Remove or redirect the old route (optional but recommended)
To block access to the old/phpmyadminpath entirely, add this line after the new Alias:
Or redirect it to your new custom path:Alias /phpmyadmin /dev/nullRedirect permanent /phpmyadmin https://your-domain.com/sampleroute - Restart Apache
Run the appropriate command for your system:# Ubuntu/Debian sudo systemctl restart apache2 # Amazon Linux/RHEL sudo systemctl restart httpd
For Nginx Web Server
- Find your phpMyAdmin configuration
Look in/etc/nginx/conf.d/phpmyadmin.confor open your site's config file (usually stored in/etc/nginx/sites-available/your-site.conf). - Update the location block
Replace the existinglocation /phpmyadminblock with your custom route:location /sampleroute { root /usr/share/phpmyadmin; index index.php index.html index.htm; location ~ ^/sampleroute/.+\.php$ { root /usr/share/phpmyadmin; fastcgi_pass unix:/var/run/php/php8.1-fpm.sock; # Adjust PHP version to match your setup fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } } - Block the old
/phpmyadminpath (optional)
Add this block to prevent anyone from accessing the default route:location /phpmyadmin { return 404; } - Test and restart Nginx
First verify your config is error-free:
If no issues are found, restart Nginx to apply changes:sudo nginx -tsudo systemctl restart nginx
Extra Security Tips
- Choose a custom route that's not obvious (avoid generic names like
/adminor/dbto reduce brute-force attempts). - Add HTTP basic authentication to your new phpMyAdmin path—this adds an extra layer of login protection even if someone guesses the route.
- Restrict incoming traffic on port 80/443 in your EC2 security group to only trusted IPs if possible.
内容的提问来源于stack exchange,提问作者Nenad Kaevik
相关产品推荐
相关产品推荐

