I had this problem when installing a site on a CentOS server, connecting to a database on another server. It was giving the error as Can't connect to mysql server 'another_server'.
It turned out the connection to the database was being prevented by SELinux.
Issuing the following command (as root) told SELinux to allow the connection:
It turned out the connection to the database was being prevented by SELinux.
Issuing the following command (as root) told SELinux to allow the connection:
setsebool httpd_can_network_connect_db=1