I have updated a Laravel 5.5-installation to 5.8 and am now attempting to update the MySQL-installation from 5.7 to 8.0.19. The Laravel-installation is on an EC2-instance and works great with the previous RDS MySQL/Aurora installation, but the version did not cut it.
We are running this on an nginx-server.
First I got an error-message stating
(2/2) PDOException
SQLSTATE[HY000] [2002] Connection refused
Tried to change the AWS uri and use the ip instead, and got a 504 instead.
I tried to access the database through MySQL Workbench and through new PDO('mysql:host=xx-rds-staging-mysql-8.xxxxxxxxxxxx.eu-west-1.rds.amazonaws.com;port=3306;dbname=database', 'username', 'password', [0, 2, 0, false, false, false]) and... they both work perfectly from the EC2-instance.
Env-file:
DB_CONNECTION="mysql"
DB_HOST_WRITE="xx-rds-staging-mysql-8.xxxxxxxxxxxx.eu-west-1.rds.amazonaws.com"
DB_HOST_READ="xx-rds-staging-mysql-8.xxxxxxxxxxxx.eu-west-1.rds.amazonaws.com"
DB_PORT_READ_AND_WRITE="3306"
DB_DATABASE="database"
DB_USERNAME="username"
DB_PASSWORD="password"
config/database.php
'mysql' => [
'read' => [
'host' => env('DB_HOST_READ', '127.0.0.1'),
],
'write' => [
'host' => env('DB_HOST_WRITE', '127.0.0.1'),
],
'port' => env('DB_PORT_READ_AND_WRITE', '3306'),
'driver' => 'mysql',
'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' => false,
'engine' => null,
'sticky' => true,
'version' => 8,
'modes' => [
#'ONLY_FULL_GROUP_BY',
'STRICT_TRANS_TABLES',
'NO_ZERO_IN_DATE',
'NO_ZERO_DATE',
'ERROR_FOR_DIVISION_BY_ZERO',
'NO_ENGINE_SUBSTITUTION',
],
'options' => [
PDO::MYSQL_ATTR_SSL_VERIFY_SERVER_CERT => false,
],
],
I have cleared the cache by all the artisan-commands and by deleting the cache-folder.
I am rubbish at asking for help here, not ever certain what information I need to share to make my case.
My first thought is that there ought to be some setting in Laravel which I could swap to make this work, but I have no idea what it could be.
The mysql-server does not run on the same machine as the laravel-application and AWS has not offered a public ip, just the uri.
What makes it even stranger is that I can enter php artisan tinker and run, for example, User::first(); and it will fetch the appropriate row from the database, without any issue.
No details informaton but you can review below points:
Verify your Laravel/php config or connection file didn't change and have same settings as before.
Did you set any zone specific resstriction in RDS? Does your testing environment complies it?
Related
I am working on a laravel project and we use 2 different servers to host the code( hosted: 127.15.255.64) and the database(hosted: 127.15.255.13).
I modified the .env file as:
DB_CONNECTION=pgsql
DB_HOST=127.15.255.13
DB_PORT=5432
DB_DATABASE=db
DB_USERNAME=postgres
DB_PASSWORD=postgres
Also Modified database.php file as:
'pgsql' => [
'driver' => 'pgsql',
'url' => env('DATABASE_URL'),
'host' => env('DB_HOST', '127.15.255.13'),
'port' => env('DB_PORT', '5432'),
'database' => env('DB_DATABASE', 'db'),
'username' => env('DB_USERNAME', 'postgres'),
'password' => env('DB_PASSWORD', 'postgres'),
'charset' => 'utf8',
'prefix' => '',
'prefix_indexes' => true,
'search_path' => 'public',
'sslmode' => 'prefer',
],
and my servers php.ini file does not have any pgsql extension to uncomment so i tried running the php artisan migrate to check if the db is connected but it just didn't do anything.
I am stuck and dont know what to do next i tried calling "DB::table('public.db')->get()" where 'public' is schema and 'db' is databse name, But it gave me an error which showed could not find driver, can anybody please help me with this situation. i dont know what top do next.
I'm currently using the spatie laravel-backup for backup my database.
But when I execute the command
php artisan backup:run
I get this error :
Backup failed because The dump process failed with exitcode 1 : General error : The system cannot find the path specified.
After my research, I tried to change my dump_binary_path to 'D:\xampp\mysql\backup\mysql' but it still not working. Therefore I'm thinking that I might have entered the wrong path .. is there a way to find the path?
Here is my code in config/database.php
'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,
'dump' => [
'dump_binary_path' => 'D:\xampp\mysql\bin',
'use_single_transaction',
'timeout' => 60 * 5, // 5 minute timeout
],
'options' => extension_loaded('pdo_mysql') ? array_filter([
PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
]) : [],
],
Any answer and suggestion are higher appreciated
I have same problem. But I solve it from this step. you can also try.
follow this step
https://spatie.be/docs/laravel-backup/v5/installation-and-setup#dumping-the-database
then add
'dump' => [
'dump_binary_path' => 'F:\xampp\mysql\bin',
],
Then click your comment link.
I'm an irregular Laravel user, and am trying to connect to a remote SQL database.
I've gotten the artisan commands working to create migrations and from the command line I can successfully connect to the database. But, when I try to load the application, the connection fails.
Could not connect to the database. Please check your configuration. error:PDOException: SQLSTATE[HY000] [1045] Access denied for user 'myuser'#'222.222.222.222' (using password: YES) in ... {file location}
What are artisan and the actual app framework doing differently that this connection would respond differently between the 2?
Here is the mysql connection in the database.php file:
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', '123.123.123.123'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'mydb'),
'username' => env('DB_USERNAME', 'myuser'),
'password' => env('DB_PASSWORD', 'mypass'),
'unix_socket' => env('DB_SOCKET', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '','strict' => true,
'engine' => null,
'sslmode' => 'require',
'options' => array(
PDO::MYSQL_ATTR_SSL_VERIFY_SERVER_CERT => false,
PDO::MYSQL_ATTR_SSL_KEY => 'certs/client-key.pem',
PDO::MYSQL_ATTR_SSL_CERT => 'certs/client-cert.pem',
PDO::MYSQL_ATTR_SSL_CA => 'certs/server-ca.pem',
),
And this is the local environment file:
DB_CONNECTION=mysql
DB_HOST=123.123.123.123
DB_PORT=3306
DB_DATABASE=mydb
DB_USERNAME=myuser
DB_PASSWORD=mypass
I am running the application locally, but the MySQl server is remote.
It turns out that the root cause was that PDO doesn't like the cert generated by Google Cloud SQL.
I have a project developed in Laravel and I want to upload the project to a Linux shared hosting.
In my project I have 2 connection to different database. First is mysql database that is in shared hosting and works well. Second is an sql server database that access to another server. So for that second database I use sqlsrv driver but I having problems to put this working at linux shared hosting, returns me this error:
SQLSTATE[HY000] Unable to connect: Adaptive Server is unavailable or does not exist (severity 9)
at PDO->__construct('dblib:host=IP:1433;dbname=DBNAME;charset=utf8', 'USER', 'PASSWORD', array(0, 2, 0, false))
I set the connection like this:
'DB2' => [
'driver' => 'sqlsrv',
'host' => env('DB_HOST', 'IP'),
'port' => env('DB_PORT', '1433'),
'database' => env('DB_DATABASE', 'DBNAME'),
'username' => env('DB_USERNAME', 'USER'),
'password' => env('DB_PASSWORD', 'PASSWORD'),
'charset' => 'utf8',
'prefix' => '',
],
Before this error I have a lot of another errors because this connection, so I have to add some extensions to php and update to 7.2 version. I also add some PHP pear packages .
The next image show you the extensions that I add:
In my local machine I can run the project without any problem and both connection working fine.
How can I solve that?
You should define DB_HOST and DB_PORT environment variables inside .env file for sqlsrv driver. Currently, it looks like the default values are used for the connection. (Default value - is the second parameter of env() function).
P.S. Please note, if you use two different connection - variable names should be different, for example:
.env content:
...
MYSQL_DB_HOST=0.0.0.0
MYSQL_DB_PORT=3939
SQLSRV_DB_HOST=0.0.0.0
SQLSRV_DB_PORT=1433
...
config/database.php content:
...
'DB' => [
'driver' => 'mysql',
'host' => env('MYSQL_DB_HOST', 'localhost'),
'port' => env('DB_PORT', '3939'),
'database' => env('DB_DATABASE', 'DBNAME'),
'username' => env('DB_USERNAME', 'USER'),
'password' => env('DB_PASSWORD', 'PASSWORD'),
'charset' => 'utf8',
'prefix' => '',
],
'DB2' => [
'driver' => 'sqlsrv',
'host' => env('DB_HOST', 'localhost'),
'port' => env('DB_PORT', '1433'),
'database' => env('DB_DATABASE', 'DBNAME'),
'username' => env('DB_USERNAME', 'USER'),
'password' => env('DB_PASSWORD', 'PASSWORD'),
'charset' => 'utf8',
'prefix' => '',
],
...
I think first of all check your hosting server php version and try to put correct PDO driver for PHP version.
if you use a PHP Version 7.1.7 for *86 Architecture then put that .dll file.
extension=php_pdo_sqlsrv_71_ts_*86.dll
and if you use another Version of PHP then try to put a correct .dll file and also declare into php.ini file.
and restart your service and run it...
I hope it would help you...
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.