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.

up vote 1 down vote accepted

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

Have you created user with APP Server IP in your database. If not please create the user first.

CREATE USER ‘username’@’APP_SERVER_IP’ IDENTIFIED BY ‘password’; GRANT ALL PRIVILEGES ON . TO ‘username’@’APP_SERVER_IP’; FLUSH PRIVILEGES;

and then use this user in your drupal site to connect with database.

If it is not working then please check the MySQL Database port on DB Server. If it is not open then open it first.

  • It didn't work. fyi I'm able to connect using drush, so the port is not the issue. I also used the root on my settings.php and it's not working either. – 113408 Apr 26 '17 at 9:16

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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