Configure phpMyAdmin on Nginx to Manage AWS RDS Databases
In this article, I will guide you through the process of configuring phpMyAdmin on an Nginx server to connect seamlessly to an AWS RDS instance.
STEP 1: Install Nginx and phpMyAdmin
- Install Nginx
sudo apt install -y nginx
- Install phpMyAdmin
sudo apt install -y phpmyadmin
STEP 2:Configuring Nginx to Serve phpMyAdmin
- When installing phpMyAdmin, you might see a prompt for selecting a web server. Don’t be confused by the prompt; simply select “Apache” and confirm with “Yes” for the database configuration.
Note: After the installation, two directories will be created:
- Configuration files:
/etc/phpmyadmin
- Web interface files:
/usr/share/phpmyadmin
Step 3: Create a Virtual Host for phpMyAdmin
- Navigate to
/etc/nginx/sites-available
and create a new configuration file namedphpmyadmin.conf
sudo vim /etc/nginx/sites-available/phpmyadmin
server {
listen 80;
server_name 43.204.36.166;
root /usr/share/phpmyadmin;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ =404;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php8.3-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg)$ {
expires max;
log_not_found off;
}
location ~ /\.ht {
deny all;
}
}
Note:replacing the PHP-FPM socket path with the version installed on your system (e.g., php8.3-fpm.sock
):
Choose Your Configuration Style:
- Path-Based: Serve phpMyAdmin under a specific path, such as
/phpmyadmin
. - Port-Based: Configure Nginx to listen on a different port if needed.
- Name-Based: Set up different server names if hosting multiple domains.
Feel free to choose the approach that best suits your needs!
Enable the Configuration:
- Create a symbolic link to enable the new virtual host configuration:
sudo ln -s /etc/nginx/sites-available/phpmyadmin /etc/nginx/sites-enabled/
sudo systemctl restart nginx
- Note: If you see an error message like the one displayed, don’t worry. This error indicates that no database connection details are specified in the phpMyAdmin configuration file.
Step 4: Configure phpMyAdmin to Connect to RDS
- Edit the phpMyAdmin Configuration File:
- Open the phpMyAdmin configuration file located at
/etc/phpmyadmin/config.inc.php
:
sudo vim /etc/phpmyadmin/config.inc.php
- Add an entry for your RDS instance in the configuration file. You’ll need to specify the server, username, and password for your RDS instance. Add the following configuration to connect phpMyAdmin to your RDS instance
/* Authentication type */ $cfg['Servers'][$i]['auth_type'] = 'config'; // Change this to 'cookie' for more security
/* Server parameters */
$cfg['Servers'][$i]['host'] = 'your-rds-endpoint.amazonaws.com'; // Replace with your RDS endpoint
$cfg['Servers'][$i]['port'] = '3306'; // Default MySQL port
$cfg['Servers'][$i]['user'] = 'your-rds-username'; // Replace with your RDS username
$cfg['Servers'][$i]['password'] = 'your-rds-password'; // Replace with your RDS password
Make sure to replace placeholders (your-rds-endpoint.amazonaws.com
, your-rds-username
, and your-rds-password
) with your actual RDS details.
- Save and Close the File:
sudo systemctl reload nginx
After configuring the config.inc.php
file, you should be able to see and select your RDS instance from the phpMyAdmin login page. This means that phpMyAdmin has been properly configured to connect to your AWS RDS instance, and you can now manage your databases through the phpMyAdmin web interface.