12
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Apache経由でのMysql接続時に「[2002]Permission denied」というエラーが起きてしまう場合の対処法

Last updated at Posted at 2016-11-15

症状

Apache+PHP+MySQLという構成のWebアプリケーションにて, MySQLへのコネクション要求時に

SQLSTATE[HY000] [2002] Permission denied

というエラーが発生し, 接続に失敗する.
しかし, コマンドラインのmysqlクライアント等からの接続には成功する.

環境

$ cat /etc/redhat-release
CentOS release 6.8 (Final)

$ httpd -v
Server version: Apache/2.2.15 (Unix)
Server built:   Jul 18 2016 15:24:00

$ php -v
PHP 5.6.28 (cli) (built: Nov  9 2016 07:23:55)
Copyright (c) 1997-2016 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies

MySQLはAmazonのRDSを使用

原因

SELinuxが有効になっており, httpd経由のネットワーク接続が無効になっていた

対処法

この機能は「httpd_can_network_connect」という変数で制御しているようなので,
この値を変更する

$ getsebool httpd_can_network_connect
httpd_can_network_connect --> off
$
$ sudo setsebool -P httpd_can_network_connect 1
$
$ getsebool httpd_can_network_connect
httpd_can_network_connect --> on
$ 

これでおそらく接続できるようになります

参考

12
9
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
12
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?