Cannot connect to PgSQL via Laravel SQLSTATE[08006] [7] FATAL - php

I'm trying to connect to pgsql via laravel and finally got everything setup (pgsql server running, pdo installed, all libs installed). I'm running on a VPS (CentOS) managed via CPanel/WHM.
Here's what I'm doing:
I'm trying to create a user database via artisan (Laravel's command line) using migrate:install.
For those that don't use Laravel, artisan uses php's PDO for pgsql to connect. Here are my settings:
'pgsql' => array(
'driver' => 'pgsql',
'host' => 'localhost',
'database' => 'dbname',
'username' => 'username',
'password' => 'password',
'charset' => 'utf8',
'prefix' => '',
),
I've also setup a test.php file:
$dbconn = pg_connect("host=localhost port=5432 dbname=dbname user=username password=password");
which also fails. I used phpPgAdmin to see what's up and all of the permissions are set correctly, the database shows up, the username is correct, same with password. I checked where postgre (version 8.4.12 btw) was running and phpPgAdmin tells me "localhost:5432".
The error I get via the command line is the following:
SQLSTATE[08006] [7] FATAL: no pg_hba.conf entry for host "::1", user "myusername", database "my_database", SSL OFF
Now, I tried to find the pg_hba.conf file but I'm not entirely sure where to look for it. Same goes for the error/access logs for pg and google hasn't been any help as far as this goes.
Any idea on what I can do?

localhost points to IPV6 ::1 address on your system. Postgresql makes the difference between ipv6 and ipv4 addresses when dealing with access list.

I was able to install/configure everything correctly. I changed the "host" to 127.0.0.1, not sure why that made a difference but it did :)

Related

"Unable to connect to your database server using the provided settings."

how to import mysqldb into heroku postgres?
I am getting an error In codeigniter
these are my settings:
$active_group = 'default';
$query_builder = TRUE;
'hostname' => 'localhost',
'username' => 'root',
'password' => '',
'database' => 'whatsapp',
'dbdriver' => 'mysqli',
'dbprefix' => '',
You should post the error you are getting, this way others can maybe help you.
I found also this solution that, may or may not be helpful:
For me the issue was in the php.ini file. The property mysql.default_socket was pointing to file in a non-existent directory. The property was pointing to /var/mysql/mysql.sock but in OSX, the file was located in /tmp/mysql.sock.
Source: CodeIgniter: Unable to connect to your database server using the provided settings Error Message
You can use mysql-postgresql-converter Dump MySQL database in PostgreSQL-compatible format
mysqldump -u username -p --compatible=postgresql databasename > database.sql
then use the converter to transfer data into *.psql file. then load new dump into a fresh PostgreSQL database

Doctrine fails to connect to MYSQL database in linked docker container

I am using two Docker container, one having ubuntu and an apache webserver running, the other one a mysql server. The containers are linked and i can connect from the ubuntu container onto the mysql server. For the connection I use in the ubuntu container:
mysql -u root -h mysql
where the second 'mysql' is the name of the container. I can connect to it through the container id as well, so the connection works as well as connecting onto the database from the windows environment.
What doesnt work is the connection from doctrine to the database within the PHP application which is in the ubuntu container.
The config looks like this:
'doctrine' => array(
'connection' => array(
'orm_default' => array(
'driverClass' => 'Doctrine\DBAL\Driver\PDOMySql\Driver',
'params' => array(
'host' => 'mysql',
'port' => '3306',
'user' => 'root',
'password' => '',
'dbname' => 'db_name',
'charset' => 'utf8',
)
)
),
)
But I get the Error message
Uncaught PDOException: could not find driver in /var/www/vendor/zendframework/zend-servicemanager/src/ServiceManager.php
and
Zend\ServiceManager\Exception\ServiceNotCreatedException: An abstract factory could not create an instance of doctrine.entitymanager.ormdefault(alias: doctrine.entitymanager.orm_default). in /var/www/vendor/zendframework/zend-servicemanager/src/ServiceManager.php
Does anyone have any idea how to solve this and where exactly the error comes from?
I have already tried to put in the container ID as 'host' and commented out the 'password' field as it is not used.
Thanks in advance
Jonathan
You need to have pdo_mysql allowed on your system, it doesn't seem a connectivity issue but a php configuration problem.
Can you try to do this command inside your php container
php -i | grep pdo_mysql
Just to understand if php has this module

Undefined index: REMOTE_ADDR while Laravel migrate

When I run php artisan migrate on my local server (running by php artisan serve) I get the following error:
[ErrorExeption]
Undefined index: REMOTE_ADDR
I tried also php artisan migrate --database db_name, output is like this:
[InvalidArgumentExeption]
Database [db_name] not configured.
My app/config/local/database.php looks like following:
'connections' => array(
'mysql' => array(
'driver' => 'mysql',
'host' => 'localhost', // also tried 127.0.0.1
'database' => 'db_name',
'username' => 'root',
'password' => 'mypassword',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
)
)
I'm sure MySQL works, I checked it via command line and phpMyAdmin.
Also I included HostnameLookups On inside my httpd.conf, then restarted apache, but nothing helps.
I use Laravel 4.2, Debian.
Any ideas? Thanks in advance.
P.S. Sorry for my English:)
UPD:
Output of php artisan env is Current application environment: local
UPD2:
I created simple route:
Route::get('/test', function() {
return $_SERVER["REMOTE_ADDR"];
});
It returns ::1, but when I execute echo $_SERVER["REMOTE_ADDR"]; in php interactive mode (php -a) I get a Notice: Undefined index: REMOTE_ADDR
When you get an artisan error, that error has possibly nothing to do with the command currently tried to run with artisan, but with some any other coding error you recently made. Search in your code for any recent reference to REMOTE_ADDR.
If you haven't done so, make sure you're accessing SERVER_ADDR using the $_SERVER array to obtain the value of SERVER_ADDR, which is an element of this array.
$_SERVER['SERVER_ADDR'];
If that doesn't work, it may mean that your server doesn't provide that information.
From PHP.net:
There is no guarantee that every web server will provide any of these; servers may omit some, or provide others not listed here.

Laravel 4 artisan migration unable to connect to remote mysql db [HY000] [1450] Access denied for user 'myuser'#'mypc' (using password: YES)

EDIT: I finally realised artisan is trying to connect to my machine instead of the remote database host specified in config. I assumed it would retrieve the hosts address along with the username and password. I'll try to specify the host's address on commandline and post back.
EDIT 2: I found the problem. Technical support for the host mislead me to my first edit. The problem was a mismatch in the password between a '1' and an 'l'. Sorry to have wasted your time.
I'm developing a Laravel 4 web app and I'm trying to execute migrations from sentry into a remote mysql database. I have been able to connect via phpmyadmin using the same credentials stored into laravel without any hassle, but artisan won't work.
Here's artisan command and output:
$ php artisan migrate --package=cartalyst/sentry
[PDOException]
SQLSTATE[HY000] [1045] Access denied for user 'myuser'#'mypc' (using password: YES)
migrate [--bench[="..."]] [--database[="..."]] [--path[="..."]] [--package[="..."]] [-- pretend] [--seed]
Laravel connection config:
'default' => 'mysql',
[...]
'mysql' => array(
'driver' => 'mysql',
'host' => 'hostname.example.com',
'database' => 'mydb',
'username' => 'myuser',
'password' => 'supersecretpassword',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
),
I don't have mysql installed locally, just apache, php and phpmyadmin. My box is archlinux and I don't have access to the remote host.
Any ideas?
You need to grant rights to that user on that host (this is the machine from where you connect):
GRANT ALL ON mydb.* TO myuser#mypc IDENTIFIED by 'supersecretpassword';

CakePHP: Can't access MySQL database

I'm new to CakePHP and am just running through the configuration process, but am stumped why Cake can't access my MySQL database. The Cake info page says my tmp directory is writable, the FileEngine is being used for caching (don't know what this means), and my database configuration file is present, but that CakePHP cannot connect to the database.
Here are my setup details:
PHP 5.3 (pre-installed on Snow Leopard)
MySQL 5.1.40 64-bit
CakePHP 1.2.4.8284
Here are the steps I went through:
Created a MySQL schema called cake_blog
Created a MySQL user called cake_blog_user
Granted cake_blog_user the appropriate permissions on cake_blog#localhost and cake_blog#%
Copied the database.php.default file to database.php and edited the database connection details as appropriate
Here is the relevant configuration data from database.php:
var $default = array(
'driver' => 'mysql',
'persistent' => false,
'host' => 'localhost',
'login' => 'cake_blog_user',
'password' => 'cake_blog_password',
'database' => 'cake_blog',
'prefix' => '',
);
Am I missing something here? I should also mention that if I insert an echo mysql_error(); into the /cake/libs/view/pages/home.ctp file right before it tests the database connection, the error displayed is "No such file or directory." I have no idea what file or directory it's talking about.
Thanks!
What usually bites me in it's that MySQL thinks of 'localhost' as 'connect thru the unix socket' and '127.0.0.1' 'connect thru TCP port'. With things like XAMPP (at least on mac) the unix socket file isn't there. Just use 127.0.0.1 instead.
var $default = array(
'driver' => 'mysql',
'persistent' => false,
'host' => '127.0.0.1',
'login' => 'cake_blog_user',
'password' => 'cake_blog_password',
'database' => 'cake_blog',
'prefix' => '',
);
Should work all the time.
If it is the socket, just edit /etc/php.ini to reflect the following
pdo_mysql.default_socket=/tmp/mysql.sock
and
mysql.default_socket = /tmp/mysql.sock
I believe you can also do the following
<?php
public $default = array(
'driver' => 'mysql',
'persistent' => false,
'host' => 'localhost',
'login' => 'cake_blog_user',
'password' => 'cake_blog_password',
'database' => 'cake_blog',
'prefix' => '',
'port' => '/tmp/mysql.sock',
)
?>
doing this might mean you need to edit the database.php file when you go live on the production server.
Thanks everyone for pointing me in the right direction. The mysql.sock file has been moved to /tmp/mysql.sock instead of its default location at /var/mysql/mysql.sock. Editing the php.ini file to reflect this has fixed the problem.
check your phpinfo and use the socket listed. that worked for me.
On Ubuntu, if you installed both 7.0 and 5.6 versions of PHP this wont work.
Youll need to switch if you have both versions:
Look first if is 7.0 version: the command is php -v.
Next do
sudo a2dismod php7.0
sudo a2enmod php5.6
sudo service apache2 restart

Categories