PDOException: SQLSTATE[HY000] [2003] Can't connect to MySQL server I recently tried to setup a dev environment for my production site and replicated the same architecture.

I've a server hosting Drupal, a second server for mysql and a memcached server. All the setup was good. 


Exported the Prod DB
Installed Drush
Made sure the latest code is pulled
run Drush status 

Drupal version         :  7.37
 Site URI               :  http://default
 Database driver        :  mysql
 Database hostname      :  ip address
 Database port          :  3306
 Database username      :  username
 Database name          :  dbname
 PHP configuration      :  /etc/php.ini
 PHP OS                 :  Linux
 Drush script           :  /usr/local/bin/drush
 Drush version          :  8.1.9
 Drush temp directory   :  /tmp
 Drush configuration    :
 Drush alias files      :
 Drupal root            :  /path/to/root/folder
 Drupal Settings File   :  sites/default/settings.php 
 Site path              :  sites/default 


The issue is when trying to load the website I get : 

PDOException: SQLSTATE[HY000] [2003] Can't connect to MySQL server on 'ip-address' (13) in lock_may_be_available() (line 167 of /var/www/cw/html/includes/lock.inc).

Any idea why this is happening ? If I run drush sqlc I'm able to connect to the remote database.

Any help will be much appreciated.
For anyone having the SAME error code, please check if you have SELinux enable by typing sestatus. If that's the case then your firewall is most likely blocking the connection to the db. 

To allow it you can use the following command line :

setsebool httpd_can_network_connect_db=1