Ravindra BagaleCourses & study guides मराठी Track your progress

Chapter 16: Amazon RDS

16.5 Point your app at the endpoint

Do not rebuild the applications from Chapters 10 and 11. Change the host from 127.0.0.1 to the endpoint, and use the RDS username, password and database name. The SQL stays the same.

PHP (the PDO line in section 10.3):

$dsn = "mysql:host=appdb.abc123xyz.ap-south-1.rds.amazonaws.com;dbname=appdb;charset=utf8mb4";

Python Flask. In /opt/flaskapp/.env from section 10.4:

DB_HOST=appdb.abc123xyz.ap-south-1.rds.amazonaws.com
DB_USER=admin
DB_PASS=YOUR_PASSWORD
DB_NAME=appdb

Restart the app after the edit. If you created the service in Chapter 10, run sudo service flaskapp restart. Otherwise start Gunicorn again the same way as in that lab.

Node.js Express. Put the same four lines in /opt/nodeapp/.env, then restart the process with pm2 (Chapter 10).

WordPress. In wp-config.php (section 11.1) set:

define('DB_NAME', 'appdb');
define('DB_USER', 'admin');
define('DB_PASSWORD', 'YOUR_PASSWORD');
define('DB_HOST', 'appdb.abc123xyz.ap-south-1.rds.amazonaws.com');

The user wpuser@localhost that you created on the EC2 MariaDB does not exist on RDS. For the lab, use the master user. Or create an application user on RDS itself:

CREATE USER 'appuser'@'%' IDENTIFIED BY 'YOUR_PASSWORD';
GRANT ALL PRIVILEGES ON appdb.* TO 'appuser'@'%';
FLUSH PRIVILEGES;

'%' means any host that can already open a connection. That is safe only because the security group limits who can open port 3306. Do not also open 3306 to the world.

CentOS Stream 9. PHP and the web server cannot open a database connection until SELinux allows it (Chapter 6):

sudo setsebool -P httpd_can_network_connect_db 1