I am moving a running site from staging to production. The production environment has 2 servers, one for frontend and the other for the database.

The issue is when I try to browse the website, I get this error

PDOException SQLSTATE[HY000] [2002] Permission denied in [ROOT]/core/lib/Drupal/Component/DependencyInjection/PhpArrayContainer.php on line 79

The real problem is I am sure that the database connection is set right. Permissions and ports are set right.

I tried the same database connection info from an external PHP file on the same server and I got successfully connected.

Also, I tried drush st and it told me that database status is Connected, and Drupal bootstrap status is Success.

Even tried drush sqlc and I got connected to the remote database. I can list tables, execute queries, etc.

Any ideas what might be the problem?

  • The mentioned php file - did you executed it from CLI or browser? Is it possible that you're using two different php configs - one for CLI and another for apache/fpm?
    – zaporylie
    Commented Jun 20, 2018 at 13:16

3 Answers 3


In case you're using SELinux see this article.

setsebool -P httpd_can_network_connect 1

setsebool -P httpd_can_network_connect_db 1


Wild guess- I saw that error after making some changes to my MAMP environment (specifically, I upgraded MAMP Pro). It turned out that the server was using one version of PHP, and the CLI (e.g., DRUSH) was using another. When I got one to work, the other would fail.

When I got both environments using the same PHP version, the issue was resolved.


In the sites/default/settings.php file, change the value of host key from localhost to

Code sample

$databases['default']['default'] = array (
  'database' => 'foo',
  'host' => '',
  • 1
    But he said that db host is a remote host...
    – zaporylie
    Commented Jun 20, 2018 at 13:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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