I’m trying to deploy a laravel app to heroku. I’ve succesfully done so already with one of my apps, but here I get the following error when running the command heroku run php artisan migrate:
In Connection.php line 664:
SQLSTATE[HY000] [2002] Connection refused (SQL: select * from
information_schema.tables where table_schema = todolist and
table_name = migrations)
In Connector.php line 67:
SQLSTATE[HY000] [2002] Connection refused
I have checked that database.php and .env have matching configurations:
.env:
DB_CONNECTION=pgsql
DB_HOST=foo.amazonaws.com
DB_PORT=5432
DB_DATABASE=database
DB_USERNAME=user
DB_PASSWORD=password
database.php:
return [
'default' => env('DB_CONNECTION', 'pgsql'),
'connections' => [
'pgsql' => [
'driver' => 'pgsql',
'host' => env('DB_HOST', 'foo.amazonaws.com'),
'port' => env('DB_PORT', '5432'),
'database' => env('DB_DATABASE', 'database'),
'username' => env('DB_USERNAME', 'user'),
'password' => env('DB_PASSWORD', 'password'),
'charset' => 'utf8',
'prefix' => '',
'schema' => 'public',
'sslmode' => 'prefer',
]
]
I have read some similar posts and tried changing DB_HOST from 127.0.0.1 to localhost but it didn’t work.
The database values were given by heroku after I used postgres for my database. Am I missing anything here? All advice is welcome.
The .env file is ignored by git, so that won’t be pushed to Heroku. To solve your problem, the credentials should be in the database.php file the same way you have them:
'pgsql' => [
'driver' => 'pgsql',
'host' => env('DB_HOST', 'ec2-12-34-56-789.compute-1.amazonaws.com'),
'port' => env('DB_PORT', '5432'),
'database' => env('DB_DATABASE', 'dbXXXXXXXXXXXX'),
'username' => env('DB_USERNAME', 'XXXXXXXXXXXXXX'),
'password' => env('DB_PASSWORD', 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'),
'charset' => 'utf8',
'prefix' => '',
'schema' => 'public',
'sslmode' => 'prefer',
]
The password should be 64 characters long, so I would say maybe double check the values and then push the changes again. After a successful push, run:
$ heroku run php artisan migrate
Related
I have an aplication that works with angularjs and its backend is on Laravel. I'm working on Fedora 37.
The back is in a docker container, and I have a local database with mysql.
When I try to query anithing to the database, it brings the next error:
SQLSTATE[HY000] [2002] No such file or directory (SQL: select * from
usuarios where email = admin#test and usuarios.deleted_at is
null limit 1)
The .env file:
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=wymaq
DB_USERNAME=root
DB_PASSWORD=
Frontend is located in localhost:9001, and its linked in config.app.js to back (localhost:8080) like this:
.constant('API_CONFIG', {
'url': 'http://127.0.0.1:8080/', etc...
My database.php file is configured 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', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'unix_socket' => '/var/lib/mysql/mysql.sock',
'strict' => true,
'engine' => null,
'modes' => [
'ONLY_FULL_GROUP_BY',
'STRICT_TRANS_TABLES',
'NO_ZERO_IN_DATE',
'NO_ZERO_DATE',
'ERROR_FOR_DIVISION_BY_ZERO',
'NO_ENGINE_SUBSTITUTION',
],
],
In windows, there is no problem. I have the database in another container and it works. I tried it here in fedora but its the same error.
I get my mysql socket and its: '/var/lib/mysql/mysql.sock'
When i type php -i | grep pdo in the back container i get this:
pdo_mysql.default_socket => no value => no value
Anytime I do local dev w/ docker, and a SQL database (running on the host), the host name for the database that works for me is: host.docker.internal
I installed laravel and setup username and database in mysql.
Then I entered the credentials in database.php file in Laravel project.
'mysql' => [
'driver' => 'mysql',
'url' => env('DATABASE_URL'),
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'msn_test1'),
'username' => env('DB_USERNAME', 'msn_user' ),
'password' => env('DB_PASSWORD', 'Passw0rd!'),
'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'),
]) : [],
],
But when I run:
php artisan migrate
I get this error:
SQLSTATE[HY000] [1698] Access denied for user 'root'#'localhost' (SQL: select * from information_schema.tables where table_schema = laravel and table_name = migrations and table_type = 'BASE TABLE')
I am new to Laravel. Could someone help me with the setup.
The second parameter is the fallback value env('the_env_property_name', 'fallback_variable'), it will fallback if it is not present in the .env file.
You should put these variables in the .env file, create your .env file by copying the .env.example to .env. Set the variables as done below, they are probably already there.
DB_CONNECTION=mysql
DB_USERNAME=msn_user
DB_PASSWORD=Passw0rd!
The .env file is hidden in the project home folder. I found while creating a new one.
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 been trying to run migration since yesterday but database connection is preventing it
Note: I can access the database very well from other projects. This only happens with laravel on homestead. Here is the output of the php artisan migrate command:
SQLSTATE[HY000] [1045] Access denied for user
'abdellah'#'192.168.10.10' (using password: YES) (SQL: select * from
information_schema.tables where table_schema = furbook and table_name
= migrations and table_type = 'BASE TABLE')
This is my .env database config
DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=furbook
DB_USERNAME=abdellah
DB_PASSWORD=bonjour1
And this is the database.php file
'mysql' => [
'driver' => 'mysql',
'url' => env('DATABASE_URL'),
'host' => env('DB_HOST', 'localhost'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'furbook'),
'username' => env('DB_USERNAME', 'abdellah'),
'password' => env('DB_PASSWORD', 'bonjour1'),
'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'),
]) : [],
],
I am running on Homestead environment.
Thanks.
Have you made sure everything is spelled correctly?
The only other thing I can think of is adding an extra 0 at the end of the port (DB_PORT=33060).
It's weird but I had a fresh Laravel project using homestead and the only way I could access the DB artisan commands in the terminal was to add a 0 on the port but then I had to take it off again once accessing it through HTTP.
I was able to run the migration successfully by setting the DB username to homestead and DB password to secret.
DB_USERNAME=homestead
DB_PASSWORD=secret
I am configuring my postgresql driver in Laravel 5.4 for deployment to Heroku. Here is my config/database.php, the default is already set to pgsql
'pgsql' => [
'driver' => 'pgsql',
'host' => parse_url(getenv("DATABASE_URL"))['host'],
'database' => substr(parse_url(getenv("DATABASE_URL"))['path'], 1),
'username' => parse_url(getenv("DATABASE_URL")['username']),
'password' => parse_url(getenv("DATABASE_URL")['password']),
'charset' => 'utf8',
'prefix' => '',
'schema' => 'public',
],
When I commit I see this warning
PHP Warning: Illegal string offset 'username' in app/config/database.php on line 62
When run heroku run php artisan serveI am getting an error
[Symfony\Component\Debug\Exception\FatalThrowableError]
Type error: PDO::__construct() expects parameter 2 to be string, array given
Here is my .env
DB_CONNECTION=pgsql
DB_HOST=127.0.0.1
DB_PORT=5432
DB_DATABASE=forge
DB_USERNAME=postgres
DB_PASSWORD=
Your configuration array should look like the following if you want to get correct data from the .env provided.
'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',
]
I found the answer in this site. It caters also mysql, and sqlite, please read
https://mattstauffer.co/blog/installing-a-laravel-app-on-heroku