Postgress and PHP "Ident authentication failed for user" - php

On my local server (Ubuntu 14.04) all work ok. But on test server (Centos) i cannot connect from PHP (Yii 1.1) to my database.
On both servers i used same dump, user name, password, postgres and php code versions.
On local server apache. On Test nginx.
CDbConnection failed to open the DB connection: SQLSTATE[08006] [7]
FATAL: Ident authentication failed for user "tripinsu"
pg_hba.conf:
local all all md5
host all all 127.0.0.1/32 ident
host all all ::1/128 ident

I fixed. Not sure what i changed. I just copy my correct config from ubuntu.
local all postgres peer
local all all md5
host all all 127.0.0.1/32 md5
host all all ::1/128 md5
I hope this help somebody else

Related

How can I connect to a postgres database using php via an open ssh tunnel?

I need to connect to a postgres database on a remote server using PHP. I've opened an SSH tunnel on the local machine, local port 8000. The tunnel seems to work fine.
The problem arises when I attempt to connect to the db with PHP. The following code:
$ConnectionString = "host=127.0.0.1:8000 user=username password=passphrase dbname=databasename sslmode=require port=5432";
pg_connect($ConnectionString);
produces the following error:
Warning: pg_connect(): Unable to connect to PostgreSQL server: could not translate host name "127.0.0.1:8000" to address: Unknown host in [path]\mappage.php on line 22
Not connected
How, then, can I open a database connection via SSH?
For what it's worth, I can connect to the remote PostgreSQL database with PGAdmin using SSH.
As written in the manual it should be:
$ConnectionString = "host=127.0.0.1 port=8000 user=username password=passphrase dbname=databasename sslmode=require";
You had port twice and once incorrectly.
Once you've set up the tunnel, you connect to your database via 127.0.0.1. e.g. (MySQL Example):
ssh -L 127.0.0.1:8000:127.0.0.1:5432 sshuser#example.com
After that the connection parameters for my database are:
Host: 127.0.0.1 (localhost would try to connect to socket)
Port: 8000
User: username
Pass: passphrase

psql: FATAL: Ident authentication failed for user "root"

Hi i am using postgresql .
my
Postgres User : postgres
Passwprd : abc123
but when i type root#xxxx:~#psql -U postgres -W
it says
root#xxxx:~# Ident authentication failed for user "root"
but when i su postgres cd and then type following command
#psql -U postgres -W
it is working correctly and i can access to all databases .
when i try to access my site it gives me the error in posstgres error log
password authentication failed for user "postgres"
why is this happening , please help me , thanks in advance
UPDATE
my pg_hba.conf
# Database administrative login by Unix domain socket
local all postgres trust
# TYPE DATABASE USER CIDR-ADDRESS METHOD
# "local" is for Unix domain socket connections only
local all all trust
# IPv4 local connections:
host all all 127.0.0.1/32 trust
# IPv6 local connections:
host all all ::1/128 md5
You have to create a role name root
create role root login

PHP on CentOS 6.5 can not connect to Postgres DB [duplicate]

This question already has an answer here:
Can't Connect to PostgreSQL with PHP pg_connect()
(1 answer)
Closed 8 years ago.
I have a CentOS 6.5 virtual machine, which run on VirtualBox.
On it I have set up Apache, PHP, PHP Postgres extension (php-pgsql) and Postgres database.
I modified the pg_hba.conf file to allow connections:
# "local" is for Unix domain socket connections only
local all all peer
# IPv4 local connections:
host all all 127.0.0.1/32 ident
# IPv6 local connections:
host all all ::1/128 ident
host all all 192.168.0.0/24 trust
host all all 0.0.0.0/0 md5
This is my iptables file:
Chain INPUT (policy ACCEPT)
target prot opt source destination
ACCEPT tcp -- anywhere anywhere state NEW tcp dpt:8090
ACCEPT tcp -- anywhere anywhere state NEW tcp dpt:postgres
Chain FORWARD (policy ACCEPT)
target prot opt source destination
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
Now, when I connect from my host machine (ip: 192.168.0.117) to Postgres with the client pgAdmin3 (user: postgres, password: postgres) I am able to do that and everything works fine but PHP running on my CentOS VM can not connect to database:
$connection_string = "host=localhost port=5432 dbname=rt_prezzario user=postgres password=postgres";
$resource = pg_connect($connection_string);
This is the warning that PHP triggers when I run those two code lines:
Warning: pg_connect(): Unable to connect to PostgreSQL server: could not connect to server: Permission denied Is the server running on host "localhost" (::1) and accepting TCP/IP connections on port 5432?
Anyone have suggestions?
SELinux is likely blocking the connection. You should be able to find a log entry in /var/log/messages when the connection was blocked.
Try setting this flag in SELinux:
setsebool -P httpd_can_network_connect_db on
RedHat has some documentation on this SELinux flag: 1

Connecting to MSSQL server using LAMP

I have a LAMP server (Ubuntu 12.04, Apache/2.2.22, MySQL 5.5.24, PHP 5.3.10).
However I also want to connect to other MsSQL server on other machine using Apache & PHP
with a credentials of:
Server name: HENYO-GP-TEST\HENYO_GPTEST
IP: 192.168.1.36
Username: someuser
Password: somepass
Database: somedb
I already installed FreeDTS using 'apt-get install freetds-common freetds-bin unixodbc php5-sybase', then configured it by 'vim /etc/freetds/freetds.conf' then edit the bottom part like this
# A typical Microsoft server
[192.168.1.36]
host = 192.168.1.36
port = 1433
tds version = 8.0
but upon testing using 'tsql -S 192.168.1.36 -U someuser -P somepass -D somedb', the following error occured.
locale is "en_PH.UTF-8"
locale charset is "UTF-8"
using default charset is "UTF-8"
Default database being set to FAC
Error 20009 (severity 9):
Unable to connect: Adaptive Server is unavailable or does not exist
OS error 111, "Connection refused"
There was a problem connecting to the server
But I know the server is on because I can ping it.
Is the connection to MSSQL server (reside on other machine) possible using LAMP?
If it is possible? What are my mistakes on the installation and configuration? Thanks in advance.
Pinging a server doesn't necessarily imply that a particular port is open; it may respond to ICMP requests, but there's no guarantee that a given port is open. Have you confirmed that port 1433 is open on the remote server and that there is nothing blocking traffic to that port?
Your SQL Server is running on an instance named HENYO_GPTEST (HENYO-GP-TEST is the server name, and HENYO_GPTEST is the instance name), but you are not specifying this instance name anywhere.
I'm not familiar with FreeTDS, so I don't know how to specify that, but you need to specify this instance name in order to connect to the server.

Accessing mysql dbase with MysqlWorkBench on VirtualBox (Vagrant - ZF - BoilerPLate)

Does anyone know hot to connect to VB MySQL via MysqlWorkBench. I can log in in virtual box via terminal, but I can not connect it throught MySqlWorkBench. Also I can ping google on vb, ifconfig gave me 10.0.2.15 address, and when I enter it in MysqlWorkBench I got error:
Failed to Connect to MySQL at 127.0.0.1:3306 through SSH tunnel at 10.0.2.15:2222 with user davs
My Virtual box use port 2222 for connecting. Also when I try to connect with ip 127.0.0.1
Failed to Connect to MySQL at 127.0.0.1:3306 through SSH tunnel at 127.0.0.1:2222 with user davs Failed to Connect to MySQL at 127.0.0.1:3306 through SSH tunnel at 127.0.0.1:2222 with user davs
Any advice will be helpfull, thanks.
This looks like an old question but since I just ran into the problem, here are the settings that I used on MysqlWorkbench to get everything working on my mac:
Connection Method: Standard TCP/IP over SSH
SSH Hostname: 127.0.0.1:2222
SSH Key File: /Users//.vagrant.d/insecure_private_key
Mysql Hostname: 127.0.0.1
Mysql Server Port: 3306
Username: root
Password: vagrant
Your settings may be slightly different but the key part is using the insecure private key as was mentioned earlier.
Use the 'insecure private key' located at: ~/.vagrant.d/insecure_private_key

Categories