I am trying to run Laravel app on Heroku
I've pushed the app and configured it. But when I am trying to migrate database via using command heroku run php artisan serve it is giving following error.
In Connection.php line 664:
SQLSTATE[HY000] [2002] Connection refused (SQL: select * from information_s
chema.tables where table_schema = forge and table_name = migrations)
In Connector.php line 68:
SQLSTATE[HY000] [2002] Connection refused
I've made changes in .env file too for DB credentials and host.
You need to set the environment variables in Heroku's web admin panel
Go to your app in Heroku -> settings -> Reveal Config Vars
Then set your environment variable
Take for example
DB_DATABASE = your-database-name
DB_HOST = your-database-host-name
DB_PASSWORD = your-db-password
DB_PORT = your-db-port
DB_USERNAME = your-db-username
Related
when i run any php artisan commands make,key its throwing an error saying
In Connection.php line 664:
SQLSTATE[HY000] [2002] No connection could be made because the
target machine actively refused it. (SQL: select * from system
where key = woocommerce_version limit 1)
In Connector.php line 70:
SQLSTATE[HY000] [2002] No connection could be made because the
target machine actively refused it.
why it tries to connect to mysql database it has nothing to do with it
my server is iis i don't know if its mis-configured, but the same laravel application in localhost shows no error
I deleted the migrations table from a Laravel 5.4 database named laravel. When I run php artisan migrate:install, I get this error:
[Illuminate\Database\QueryException]
SQLSTATE[HY000] [2002] No such file or directory
(SQL: select * from information_schema.tables where table_schema = laravel
and table_name = migrations)
I deleted and recreated the database. I also ran composer update. No luck. I can run the command in phpMyAdmin and create the table manually.
This problem sometimes also manifests itself with similar 2002 errors:
[Illuminate\Database\QueryException]
SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: No such host is known.
(SQL: select * from information_schema.tables where table_schema = laravel
and table_name = migrations and table_type = 'BASE TABLE')
[Illuminate\Database\QueryException]
SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: Name or service not known
(SQL: select * from information_schema.tables where table_schema = laravel
and table_name = migrations and table_type = 'BASE TABLE')
If you are using localhost as your DATABASE_HOST in the .env file, change it to 127.0.0.1, then run php artisan config:clear and now try php artisan migrate:install again.
Here's what I recommend for .env file:
DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306
Then in Database.php add folder location:
'unix_socket' => env('DB_SOCKET', '/Applications/MAMP/tmp/mysql/mysql.sock'),
Finally, try:
php artisan config:clear
php artisan migrate:install
I fixed this issue by setting environment variables in .env file:
DB_CONNECTION=mysql
DB_HOST=mysql
DB_PORT=3306
Actually I just changed from DB_HOST=127.0.0.1 to DB_HOST=mysql.
If you are using MAMP Pro (not always necessary for the free version of MAMP) then the best thing to do is add this to your .env file:
DB_SOCKET=/Applications/MAMP/tmp/mysql/mysql.sock
This assumes your MAMP installation is at /Applications/MAMP of course (the default).
Credit: A comment in this question by #Uncoke
I am using MAMP on macOS and after editing localhost to 127.0.0.1 and port to 8888 this problem fixed by adding the following
'unix_socket' => env('DB_SOCKET', '/Applications/MAMP/tmp/mysql/mysql.sock'),
to config/database.php file.
For mac users, add this to your .env file
DB_SOCKET=/Applications/MAMP/tmp/mysql/mysql.sock
In some cases this may happen because mysql server is not running. It happened to me using Laravel 5.7 and restarting mysql server solved it. For ubuntu check the status of mysql server service mysql status. You can restart mysql server using command service mysql restart
Posting a resolution to my own question:
I deleted the folder and recreated the code base, making sure to point my environment to the correct database server. This time it worked. I don't know exactly what had gone missing to cause the original error.
I have a centos EC2 with Laravel application. I also have MySQL installed on the same EC2 instance. It was working fine.
Now I decieded to move MYSQL to AWS RDS (MySQL Aurora). I can connect to AWS RDS through Heidi and query with no problem.
However in Laravel it throws exceptions.
I changed the .env file credentials for DB_HOST, DB_DATABASE, DB_USERNAME, DB_PASSWORD.
See below for the exceptions:
1/3 PDOException in PDOConnection.php line 43:
SQLSTATE[HY000] [2002] Permission denied
1. in PDOConnection.php line 43
2. at PDO->__construct('mysql:host=correct_host;port=3306;dbname=correct_db', 'correct_username', 'correct_password', array('0', '2', '0', false, false)) in PDOConnection.php line 43
1/2 PDOException in PDOConnection.php line 47:
SQLSTATE[HY000] [2002] Permission denied
1/3 QueryException in Connection.php line 770:
SQLSTATE[HY000] [2002] Permission denied (SQL: select * from `users` where `users`.`id` = 1 limit 1)
Update
I just reverted the database credentials in .env to my old MySQL (installed on the same EC2 instance as the Laravel application).
It works with with DB_HOST=localhost but if I use the actual ip instead, DB_HOST=127.0.0.1, it will throw the same exceptions.
If you are running SELinux on your centos EC2, try switching off SELinux and test your application again. If it's SELinux that's causing this problem, it might well be because of the policy for external connection to database. You should switch SELinux back ON and enable the policy with this command.
sudo setsebool -P httpd_can_network_connect_db=1
Edit your /etc/my.cnt like this:
bind-address = 0.0.0.0 # will accept requests from all IPs
Then in your mysql add a user and give him the proper permissions
grant all privileges on db_name.* to 'username'#'%' identified by 'password';
This enables the user to connect to the database from any IP
grant all privileges on db_name.* to 'username'#'your_ip' identified by 'password';
This enables the user to connect to the database from only one IP. This is the best practice, you don't want to allow connections from any IP, this is a bad security practice.
This will enable you to connect to the database from your external IP
Why your RDB instance is not working is not totaly clear, have you enabled remote connections?
I have uploaded my Laravel 5.5 project to the centOS7 server. Now I am facing the following error when I am running "php artisan migrate" for the first time to load database table.
Error message screenshot
Here is my .env db section
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=event
DB_USERNAME=root
DB_PASSWORD=testpass
I have created the DB in the MySQL.
[root#li129-226 event_management]# php artisan migrate
In Connection.php line 664:
SQLSTATE[HY000] [2054] The server requested authentication method unknown to the client (SQL: select * from information_schema.tables where table_schema = event and table_name = migrations)
In Connector.php line 67:
SQLSTATE[HY000] [2054] The server requested authentication method unknown to the client
In Connector.php line 67:
PDO::__construct(): The server requested authentication method unknown to the client [caching_sha2_password]
What I did that worked really well was to just alter the root user to have a password. Log in to mysql on the terminal then do this command:
ALTER USER 'user'#'address' IDENTIFIED WITH mysql_native_password BY 'yourpassword'
for the user, I used 'root'#'localhost' You may want to use a different user.
Then, replace DB_PASSWORD=yourpassword with the password you chose in the command above and save the file.
That allowed me to run php artisan migrate and everything worked great!
I'm using Laravel 5 on Windows 10, VB, homestead and I am still new, I've just started learning Laravel.
When I run my project in Chrome using DB_HOST=127.0.0.1 in .env file I get this error message:
PDOException in Connector.php line 55:
SQLSTATE[HY000] [2002] Connection refused
and when I change DB_HOST to localhost everything is fine except when I am using tinker (php artisan tinker). I get this message:
PDOException with message 'SQLSTATE[HY000] [2002] No such file or directory'
Database works with DB_HOST=localhost and tinker DB_HOST=127.0.0.1
So, I can't use both at the same time, everytime I must change DB_HOST in .env file from localhost to 127.0.0.1
What can I do to fix this issue?
If you're using Homestead, your DB_HOST should be set to localhost.
The reason why in such case artisan (migrate) cannot connect to database is because you are not executing the commands inside your virtual machine.
To do it the right way connect to your vm using:
vagrant ssh
and once logged in, continue as you'd normally.
Hope that helps!