This is a strange one, I have an AWS EC2 instance setup where Im attempting to install Wordpress and use an RDS for the database. I can connect to the database from the instance just fine with mysql client and the credentials work along with the RDS endpoint.

I have a security group setup for the RDS that will only accept port 3306 connections from the instance ip and I can telnet to it just fine from the instance but I can't from my local machine so I know that the DB security group is working fine.

The EC2 instance has a security group allowing ports 80,22,443 and 3306 in and everything out so that should be fine too.

However at the WP install step for setting up the database it doesn't accept the credentials every time and returns 'Error establishing a database connection'. I have tried adding the details to wp-config.php but then it complains that it needs wp-config-sample.php to continue the process.

The Wordpress directory and files are all owned by apache in the instance and permissions are 755/644 for dirs & files.


After some Googling and asking around I was advised to check SELinux settings and found the problem after running this command:

sudo tail -100 /var/log/audit/audit.log | audit2why

which returns this:

type=AVC msg=audit(1525088932.314:74428): avc:  denied  { name_connect } for  pid=14435 comm="httpd" dest=3306 scontext=system_u:system_r:httpd_t:s0 tcontext=system_u:object_r:mysqld_port_t:s0 tclass=tcp_socket

    Was caused by:
    One of the following booleans was set incorrectly.
    Allow httpd to can network connect

    Allow access by executing:
    # setsebool -P httpd_can_network_connect 1
    Allow httpd to can network connect db

    Allow access by executing:
    # setsebool -P httpd_can_network_connect_db 1

and after running the advised command I was then able to proceed with the installation, I did have to follow some further Wordpress instructions and create the wp-config.php file manually.

This excellent post helped me a lot.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.