I'm trying to setup a new laravel 5.6 project and I'm currently having issues with getting the database migrated. I've fiddled with the hosts names from localhost to 127.etc and the box IP. After creatingthe auth blades I can't create a new user I receive a
SQLSTATE[HY000] [2002] connection refused error.
I have attempted to log into the box to see what's in the database but I get the same error when I connect with the default homestead U&P. I also tried root/root but received the same error.
Here is part DB config
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'unix_socket' => env('DB_SOCKET', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'strict' => true,
'engine' => null,
],
'redis' => [
'client' => 'predis',
'default' => [
'host' => env('REDIS_HOST', '127.0.0.1'),
'password' => env('REDIS_PASSWORD', null),
'port' => env('REDIS_PORT', 6379),
'database' => 0,
],
try it : 'strict' => true, To strict' => false, in DB config Part
I ended up sshing into the homestead vagrant box and running 'artisan migrate:install' which solved the bulk of my problems. I then had to create a database schema partially generated by laravel and the rest edited by myself.
Related
I am struggling in connecting Laravel app with MYSQL database. I can connect to database over MySQL Workbench and also with PDO connection custom string but with Laravel I cannot. Not sure what is wrong.
Custom connection string: It works file is inside laravel app. I put this just for checking
$conn = mysqli_init();
mysqli_ssl_set($conn,NULL,NULL, "BaltimoreCyberTrustRoot.crt.pem", NULL, NULL) ;
mysqli_real_connect($conn, 'sever.host', 'server-username', 'server-password', 'database', 3306, MYSQLI_CLIENT_SSL);
if (mysqli_connect_errno($conn)) {
die('Failed to connect to MySQL: '.mysqli_connect_error());
}
else{
echo "Connected";
}
Then I added in .env file following, beside defining username password host and db name.
BaltimoreCyberTrustRoot.crt.pem file is on same path as .env file
MYSQL_SSL_KEY=BaltimoreCyberTrustRoot.crt.pem
MYSQL_SSL_CERT=BaltimoreCyberTrustRoot.crt.pem
MYSQL_SSL_CA=BaltimoreCyberTrustRoot.crt.pem
MYSQL_SSL_CIPHER=BaltimoreCyberTrustRoot.crt.pem
MYSQL_SSL=true
In config/database.php looks like this
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'unix_socket' => env('DB_SOCKET', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'strict' => true,
'engine' => null,
'options' => (env('MYSQL_SSL')) ? [
PDO::MYSQL_ATTR_SSL_KEY => env('MYSQL_SSL_KEY'), // /path/to/key.pem
PDO::MYSQL_ATTR_SSL_CERT => env('MYSQL_SSL_CERT'), // /path/to/cert.pem
PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_SSL_CA'), // /path/to/ca.pem
PDO::MYSQL_ATTR_SSL_CIPHER => env('MYSQL_SSL_CIPHER')
] : [],
Not sure what is wrong, any idea?
I get these errors:
"error":"SQLSTATE[HY000] [2002] An attempt was made to access a socket in a way forbidden by its access permissions.
[{"file":"D:\home\site\wwwroot\vendor\laravel\framework\src\Illuminate\Database\Connection.php","line":624,"function":"runQueryCallback","class":"Illuminate\Database\Connection","type":"->","args":["select * from backend_token limit 1",[],{}]},
It helps to know which version of Laravel you are on to be absolutely sure, but on Laravel 8 my database config has:
'mysql' => [
'driver' => 'mysql',
'url' => env('DATABASE_URL'),
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'unix_socket' => env('DB_SOCKET', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'prefix_indexes' => true,
'strict' => true,
'engine' => null,
'options' => extension_loaded('pdo_mysql') ? array_filter([
PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
]) : [],
],
Don't change your database.php config but in your .env add MYSQL_ATTR_SSL_CA=/path/to/BaltimoreCyberTrustRoot.crt.pem
FYI sometimes if you are using private IP addresses then edit your hosts file
10.10.10.10 hostname.domain.com
Where of course the ip number matches the ip of the host.
If that doesn't work, add the cipher line from you config PDO::MYSQL_ATTR_SSL_CIPHER => env('MYSQL_SSL_CIPHER'),
Error: SQLSTATE[HY000] [1044] Access denied for user 'tfs_user'#'localhost' to database 'tfs' (SQL: select * from settings)
When i click login/registration page i'm getting this error. i can't understand what's the problem. I updated my .env file with correct database info.
.env file
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=tfs
DB_USERNAME=tfs_user
DB_PASSWORD=tfsdemo01
database.php file
'default' => env('DB_CONNECTION', 'mysql'),
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'unix_socket' => env('DB_SOCKET', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',<
'prefix_indexes' => true,
'strict' => true,
'engine' => null,
],
How can i solve this error, can anyone help me please.
If the mysql server is on the same server as your application use host as localhost
DB_HOST=localhost
I deployed the project to azure and both the webpage displays properly and links work fine, but for the user registration I need to connect the database. Everything works well locally and I followed all the instructions of creating/connecting a sqsl db in azure but I get thte following 3 errors and not sure what to do, how to debug, its a project I was given to deply and didnt create myself,( I am only gona show the first 3 lines of the error since they are long):
UPDATE: It works if I disable the SSL on azure so its got something to do with my local app config for that
1-
SQLSTATE[HY000] [9002] SSL connection is required. Please specify SSL options and retry. (SQL: select count(*) as aggregate from `users` where `email` = ***#***.com)
in Connection.php line 647
at Connection->runQueryCallback('select count(*) as aggregate from `users` where `email` = ?', array('***#***.com'), object(Closure))
in Connection.php line 607
2-
(2/3) PDOException
SQLSTATE[HY000] [9002] SSL connection is required. Please specify SSL options and retry.
in PDOConnection.php line 50
at PDOConnection->__construct('mysql:host=***.mysql.database.azure.com;port=**+;dbname=uwiredb', '***#***', 'MySQLAzure2017', array(0, 2, 0, false, false))
in Connector.php line 65
at Connector->createPdoConnection('mysql:host=***.mysql.database.azure.com;port=***;dbname=***', '***#***', 'MySQLAzure2017', array(0, 2, 0, false, false))
in Connector.php line 44
3-
(1/3) PDOException
SQLSTATE[HY000] [9002] SSL connection is required. Please specify SSL options and retry.
here is the DB section of my .env file:
DB_CONNECTION=mysql
DB_HOST=mydbserver.mysql.database.azure.com
DB_DATABASE=mydb
DB_USERNAME=myuser
DB_PASSWORD=mypass
MYSQL_SSL=true
And here is the connection part of my database.php file in the config folder, I know the hosts
'connections' => [
'sqlite' => [
'driver' => 'sqlite',
'database' => env('DB_DATABASE', database_path('database.sqlite')),
'prefix' => '',
],
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'homestead'),
'username' => env('DB_USERNAME', 'homestead'),
'password' => env('DB_PASSWORD', ''),
'unix_socket' => env('DB_SOCKET', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'strict' => true,
'engine' => null,
'sslmode' => env('DB_SSLMODE', 'prefer'),
'options' => (env('MYSQL_SSL')) ? [
PDO::MYSQL_ATTR_SSL_KEY => '/ssl/BaltimoreCyberTrustRoot.crt.pem',
] : [],
],
'pgsql' => [
'driver' => 'pgsql',
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '5432'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'charset' => 'utf8',
'prefix' => '',
'schema' => 'public',
'sslmode' => 'prefer',
],
'sqlsrv' => [
'driver' => 'sqlsrv',
'host' => env('DB_HOST', 'localhost'),
'port' => env('DB_PORT', '1433'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'charset' => 'utf8',
'prefix' => '',
],
],
I know the host is set to local but that is how I understood it should be from the azure docs that say:
You can use the PHP getenv method to access the settings. the Laravel code uses an env wrapper over the PHP getenv. For example, the MySQL configuration in config/database.php looks like the following code:
PHP
Copy
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', 'localhost'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
...
],
Thanks
I've setup Laravel 5.0 (that's a requirement) and set it up to use remote MySQL DB. All migrations and data interactions pass OK, but when trying to use Auth login POST, it fails with PDOException in Connector.php line 47:
SQLSTATE[HY000] [2002] No such file or directory, mentioning " PDO->__construct('mysql:host=localhost;dbname=homestead', 'homestead', 'secret', array('0', '2', '0', false, false))"
WHERE did it take that homestead DSN? Why does it skip the database.php config and .env config? If I try to add to .env some socket info (well it should not count here, right?) the socket path passes to the mentioned PDOException call stack, but hostname, login etc. NOT!
Confused. What am I doing wrong?
UPD
Here's the .env:
APP_ENV=local
APP_DEBUG=true
APP_KEY=SomeRandomString
DB_HOST=mysql.someremteohosting.net
DB_DATABASE=mydb
DB_USERNAME=myuser
DB_PASSWORD=mysuperpassword
CACHE_DRIVER=file
SESSION_DRIVER=file
QUEUE_DRIVER=sync
And here's database.php:
<?php
return [
'fetch' => PDO::FETCH_CLASS,
'default' => 'mysql',
'connections' => [
'sqlite' => [
'driver' => 'sqlite',
'database' => storage_path().'/database.sqlite',
'prefix' => '',
],
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', 'localhost'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'strict' => false,
],
'pgsql' => [
'driver' => 'pgsql',
'host' => env('DB_HOST', 'localhost'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'charset' => 'utf8',
'prefix' => '',
'schema' => 'public',
],
'sqlsrv' => [
'driver' => 'sqlsrv',
'host' => env('DB_HOST', 'localhost'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'prefix' => '',
],
],
'migrations' => 'migrations',
],
];
Again, all migrations work. I can create, save and fetch objects in tinker without any problem. The only reference to homestead is in .env.example file.
Not sure what exactly was wrong here. The only place where I found 'homestead' in the app code was in .env.example. I deleted it an ran composer dump-autoload. After that it worked. Still surprised about laravel lurking into .example config without any reason.
Terminal show me this message:
my env:
my database.php:
'default' => env('DB_CONNECTION', 'mysql'),
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'laravelup'),
'username' => env('DB_USERNAME', 'root'),
'password' => env('DB_PASSWORD', '1'),
'unix_socket' => env('DB_SOCKET', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'strict' => true,
'engine' => null,
],
How can I solve this issue ?
Just change your .env file like this
DB_DATABASE=laravelup
DB_USERNAME=root
DB_PASSWORD= //blank here
And it will be working.
I maybe laravel configration cache problem.
If you type this command "php artisan config:clear" and try again, then it will be working.