2016-12-10 39 views
1

CakePHP3は自分のPostgreSQLデータベースに接続できません。CakePHPはPostgresに接続できません。しかし、Pgadmin4は

私のセットアップは以下の通りです:

  • のWindows 10ホスト
  • CentOS7 VirtualboxのVMゲスト
    • のPostgreSQL 9.6
    • のApache 2.4
    • PHP 7

エラー:

CakePHPはデータベースに接続できません。

SQLSTATE [08006] [7]サーバーに接続できませんでした:Permission deniedサーバーがホスト "localhost" ?サーバーに接続できませんでした:アクセスが拒否されましたサーバーがホスト "localhost"(127.0.0.1)で実行されており、ポート5432でTCP/IP接続を受け入れていますか?

私はlocalhost,127.0.0.1192.168.2.31をapp.phpのホスト値として指定しようとしました。彼らはすべて同じエラーを出します。

すべて失われていない、私は以下のようにPostgreSQLのに到達することができます:

  • は、SSH経由で接続Pgadmin4
  • を使用して、私のワークステーションを介してサーバに接続して、私はpsqlの
を使用して接続することができます

[[email protected] ~]$ psql -U my_user -h 127.0.0.1 -d my_db

更新#1

デフォルトデータベース構成

'default' => [ 
      'className' => 'Cake\Database\Connection', 
      'driver' => 'Cake\Database\Driver\Postgres', 
      'persistent' => true, 
      'host' => 'localhost', 
      /** 
      * CakePHP will use the default DB port based on the driver selected 
      * MySQL on MAMP uses port 8889, MAMP users will want to uncomment 
      * the following line and set the port accordingly 
      */ 
      //'port' => 5432, 
      'username' => 'user', 
      'password' => 'pass', 
      'database' => 'my_db', 
      'schema' => 'public', 
      'encoding' => 'utf8', 
      'timezone' => 'UTC', 
      'flags' => [], 
      'cacheMetadata' => true, 
      'log' => false, 

      /** 
      * Set identifier quoting to true if you are using reserved words or 
      * special characters in your table or column names. Enabling this 
      * setting will result in queries built using the Query Builder having 
      * identifiers quoted when creating SQL. It should be noted that this 
      * decreases performance because each query needs to be traversed and 
      * manipulated before being executed. 
      */ 
      'quoteIdentifiers' => false, 

      /** 
      * During development, if using MySQL < 5.6, uncommenting the 
      * following line could boost the speed at which schema metadata is 
      * fetched from the database. It can also be set directly with the 
      * mysql configuration directive 'innodb_stats_on_metadata = 0' 
      * which is the recommended value in production environments 
      */ 
      //'init' => ['SET GLOBAL innodb_stats_on_metadata = 0'], 

      //'url' => env('DATABASE_URL', null), 
     ] 

更新#2

phpinfoデータを有しながらPostgreSQLの

PDO 
PDO support enabled 
PDO drivers  mysql, pgsql, sqlite 

pdo_pgsql 
PDO Driver for PostgreSQL enabled 
PostgreSQL(libpq) Version 9.2.15 
Module version 7.0.13 
Revision $Id: f9b0c62eba234361d62f16fcbaaa120353ab5175 $ 

pgsql 
PostgreSQL Support enabled 
PostgreSQL(libpq) Version 9.2.15 
PostgreSQL(libpq) PostgreSQL 9.2.15 on x86_64-redhat-linux-gnu, compiled by gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-4), 64-bit 
Multibyte character support  enabled 
SSL support  enabled 
Active Persistent Links  0 
Active Links 0 
Directive Local Value Master Value 
pgsql.allow_persistent On On 
pgsql.auto_reset_persistent Off Off 
pgsql.ignore_notice Off Off 
pgsql.log_notice Off Off 
pgsql.max_links Unlimited Unlimited 
pgsql.max_persistent Unlimited Unlimited 

更新#3

について実行中: tcpdump -i lo port 5432 -w pg.cap

psqlを使用したときにいくつかのパケットがありました。しかし、私はCakePHPを通して自分のサイトにアクセスするときにパケットを取得しません。RedHatのに基づいて、Linuxディストリビューションに

pg_hba.conf

host all    all    ::1/128     md5 
host all    all    0.0.0.0/0    md5 
host all    all    127.0.0.1/32   md5 
+0

データベース構成の 'DATABASE_CONFIG'クラスを表示してください。 – Artegon

+0

私の更新#1を参照してください。 – TekiusFanatikus

+0

ステップ1 - データソースの設定で資格情報を確認し、コマンドラインで同じものを使用します。 – Artegon

答えて

1

は、データベースサーバーに接続するようにApacheを有効/無効に設定値httpd_can_network_connect_dbあります。デフォルト状態では、この値はoffに設定されています。これは、Appache が接続できないことを意味します。

それはあなたのボックスで許可されているかどうかを確認するには、次の

getsebool httpd_can_network_connect_db 

、それはoffを返す場合、あなたがそれを許可する必要があります

setsebool -P httpd_can_network_connect_db on 

-Pがリブートして、この設定を永続化)

詳細については、SELinux Booleansおよび⁠Configuring Booleansを参照してください。

+0

奇数私はVM上でこれを2回実行しなければならず、再起動時に次のメッセージが表示されます。SELinuxポリシーのロードに失敗しました。この問題を回避するには、VMを起動する前にselinux = 0にする必要があります... – TekiusFanatikus

関連する問題