1

I'm having a little trouble with my dev environment for a CakePHP based project. The thing is, CakePHP can connect in production, but if I run trough XAMPP on my PC, then throws me a FATAL: no pg_hba.conf entry for host "myexternalip", user "dbuser", database "dbname", SSL off

but using the same parameters I can connect from my PC trough pgAdmin.

I've tried some googling tips that I've found like copy the libpq.dll from c:\xampp\php to c:\xampp\apache\bin but, no luck, had checked pnp.ini and extension=php_pdo_pgsql.dll line is uncommented, had tried reboot apache several times but nothing changes

The project is hosted under heroku platform and my /app/config/database.php looks like

public $production = array(
    'datasource' => 'Database/Postgres',
    'persistent' => false,
    'host' => 'anywhere.at.amazonaws.com',
    'login' => 'dbuser',
    'password' => 'dbpwd',
    'database' => 'dbname',
    'encoding' => 'utf8',
);

here's the Stack Trace

- CORE\Cake\Model\Datasource\DboSource.php line 260 → Postgres->connect()
- CORE\Cake\Model\ConnectionManager.php line 105 → DboSource->__construct(array)
- CORE\Cake\Model\Model.php line 3613 → ConnectionManager::getDataSource(string)
- CORE\Cake\Model\Model.php line 1155 → Model->setDataSource(string)
- CORE\Cake\Model\Model.php line 3640 → Model->setSource(string)
- CORE\Cake\Model\Model.php line 827 → Model->getDataSource()

Can anyone give me another hint that could help?

Luiz Eduardo
  • 380
  • 4
  • 13
  • you can change "What to Log" section in postgres.conf on sever, to see which IP you connect from with Pgadmin... – Vao Tsun Apr 20 '15 at 07:22
  • 1
    At a guess, `pg_hba.conf` has an entry for `127.0.0.1`, and PgAdmin is making a connection to the loopback address but XAMPP is connecting to the external host address. Or at least, that's how the source address selection works out. Could be an IPv4 vs IPv6 issue too. **Show the contents of your pg_hba.conf if you want help with pg_hba.conf**. – Craig Ringer Apr 20 '15 at 08:46
  • I do not have access to ph_hba.conf because the postgres server is hosted in heroku platform – Luiz Eduardo Apr 20 '15 at 16:16

1 Answers1

1

After while I found a solution.

The problem is that's not straightforward.

As the Postgres server is hosted under heroku platform, the default configuration on server is require ssl, so I've came across to this configuration:

public $production = array(
    ......
    'sslmode' => 'require',
);

Now the error has changed to a sslmode value "require" invalid when ssl support is not compiled

then I've googled it and seems that at least under XAMPP v5.5.19, the libpq.dll inside PHP folder wasn't compiled with ssl support

here's the question that helped me solve this problem: How to installPostgreSQL client library for PHP on Windows with SSL enabled

Seems that pgAdmin's libpq.dll was compiled with ssl support, so that is the cause that I could connect through pgAdmin, but not with php

thanks for help folks!

Community
  • 1
  • 1
Luiz Eduardo
  • 380
  • 4
  • 13