I am trying to deploy my laravel project to 000webhost. The problem is I can not connect to my database.
When I set my DB_HOST to 127.0.0.1 I get an "SQLSTATE[HY000] [2002]" error mentioned. When I change DB_HOST to localhost I get an error saying "wrong com stmt prepare response size received 7".
This is my .env file:
APP_ENV=local
APP_DEBUG=true
APP_KEY=base64:fuFWdq2OAIZbxiiouYdTfbPnkeEOL8h/hDJjvb7XT+c=
APP_URL=http://localhost
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=id1619178_kule
DB_USERNAME=************
DB_PASSWORD=************
CACHE_DRIVER=file
SESSION_DRIVER=file
QUEUE_DRIVER=sync
REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379
MAIL_DRIVER=mail
MAIL_HOST=mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=tls
MAIL_TO=
000webhost not execute command from .env file so you have to manually specifies that five variables in /config/database.php file
'mysql' => [
'driver' => 'mysql',
'host' => 'localhost',
'port' => '3306',
'database' => 'your_database_name',
'username' => 'your_database_username',
'password' => 'yourpassword',
'unix_socket' => env('DB_SOCKET', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'prefix_indexes' => true,
'strict' => true,
'engine' => null,
],
If you have a free plan in 000webhost, you can't do a remote connection. Only from your site.
Hostname for your given web host varies from server to server!
You can retrieve hostname from the control panel and add changes to your file else you'll get permission denied.
Not all shared hosting provide MySQL on the same localhost as the HTTP server. You should check your cpanel for the address of the MySQL server:
From your hosting provider's documentation:
What is MySQL hostname?
You have go to our members' area, enter the control panel and click on the 'MySQL' icon. Your MySQL hostname will be listed there.
Important! Never use 'localhost' as your MySQL hostname here or you will get access denied errors!
Your specific provider states clearly that your should, "Never use localhost".
Related
So I have a site on Heroku, which loads fine as long I don't go to a page that requires a database connection. What happens when I do land on one of those pages, is I get this error:
PDOException in Connector.php line 55: SQLSTATE[HY000] [2002] Connection refused
I'm using db4free.net to try to access a MySQL database. This is my database.php file. The ****** masking the actual values.
'default' => env('DB_CONNECTION', 'mysql-production'),
'mysql-production' => [
'driver' => 'mysql',
'host' => env('DB_HOST', 'db4free.net'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'en*******'),
'username' => env('DB_USERNAME', '*******'),
'password' => env('DB_PASSWORD', '*******'),
'unix_socket' => env('DB_SOCKET', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'strict' => true,
'engine' => null,
],
This my env file:
APP_ENV=local
APP_DEBUG=true
APP_KEY=base64:tUWa6AteuAOfEAh/IKx3c13tJEzSmS4La8QdKlEgByQ=
APP_URL=http://localhost
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=enviro-2
DB_USERNAME=root
DB_PASSWORD=
CACHE_DRIVER=file
SESSION_DRIVER=file
QUEUE_DRIVER=sync
REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379
MAIL_DRIVER=smtp
MAIL_HOST=mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
The env file is ignored by git.
Prior to trying db4free.net I tried following the steps in this article
https://mattstauffer.com/blog/laravel-on-heroku-using-a-postgresql-database/ but I still have the exact same problem. I also set the APP_KEY in the Heroku config variables to match the one in my env file.
Anyone have any ideas on why I get this error?
your connection details in .env file in incorrect.
you should write your credentials details in .env file as well as database.php file
So I have been trying to get an connection my database with homestead, but everytime I make a DB select statement I get an SQLSTATE[HY000] [2002] Connection refused. It seems like my problem is not the same as the others with the same title. I am using homestead with virtual box
Here is my select statement:
<?php
echo DB::select('select * from bruger where id = 1')
?>;
This is simply to check if I can get any info out.
I have tried various things in both my .env file and and database.php
This is what they are looking like currently:
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', 'localhost'),
'port' => env('DB_PORT', 'localhost'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'strict' => false,
'engine' => null,
],
and
APP_ENV=local
APP_DEBUG=true
APP_KEY=randomKey
APP_URL=http://localhost
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=33060
DB_DATABASE=phpDatabase
DB_USERNAME=homestead
DB_PASSWORD=secret
CACHE_DRIVER=file
SESSION_DRIVER=file
QUEUE_DRIVER=sync
REDIS_HOST=127.0.0.1
REDIS_PASSWORD=secret
REDIS_PORT=33060
MAIL_DRIVER=smtp
MAIL_HOST=mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
For DB_HOST and DB_PORT try using the IP and port as set in the Homestead.yaml file.
Default:
DB_HOST=192.168.10.10
DB_PORT=3306
The port should be 3306, since you are accessing from within the homestead machine, if I understood correctly.
In fact, check the documentation
You will use the default 3306 and 5432 ports in your Laravel database configuration file since Laravel is running within the virtual machine.
When I try to connect to my database i get this error
[PDOException]
SQLSTATE[HY000] [1045] Access denied for user 'loom'#'localhost' (using password: YES)
all my credentials are correct and when i change things up i get this error :
[PDOException]
SQLSTATE[HY000] [1049] Unknown database 'loomcoding'
Can anyone help me sort this out please
my .env file
APP_ENV=local
APP_DEBUG=true
APP_KEY=xxxx
DB_HOST=localhost
DB_DATABASE=cl20-loom
DB_USERNAME=loom
DB_PASSWORD=xxxx
CACHE_DRIVER=file
SESSION_DRIVER=file
QUEUE_DRIVER=sync
MAIL_DRIVER=smtp
MAIL_HOST=mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
my database.php file :
'mysql' => [
'driver' => 'mysql',
'host' => 'localhost',
'database' => 'cl-loom',
'username' => 'loom',
'password' => '••••',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'strict' => false,
],
I got this error last time create a database on phpmyadmin and change only the .env file to match with you phpmyadmin details and it will work.
It can be because the mysql service is not running or it isn't on the port 3306, in the last case you may specify the port where the mysql service is running as a attribute port of the mysql object in database.php file
If you are using mysql you have to create the database manually in phpMyAdmin or whatever software you are using for mysql.
And no need to change the whole database.php if you configure the .env file. Just change this line 'default' => env('DB_CONNECTION', 'mysql'), in database.php
Below code is not tested
Instead, you can add DB_CONNECTION=mysql this line in .env
hey guys im trying to learn laravel and im following the tutorail but i cant seem to connect to my database via VM running LAMP. I've looked thru every single post and nothing is still working
when i go run the command php artisan migrate i get the following error
[PDOException]
SQLSTATE[HY000] [2003] Can't connect to MySQL server on '10.0.1.22' (111)
i even followed this post and got the following error
[PDOException]
SQLSTATE[HY000] [2002] Can't connect to local MySQL server through socket '/opt/lampp/var/mysql/mysql.sock' (2)
my laravel app is running on port 8000 but my phpmyadmin is at 10.0.1.22/phpmyadmin im not sure if that could be the issue, im still a beginner so my debugging solutions are limited.
Here are my database.php file and my .envi file
database.php
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', '10.0.1.22'),
'database' => env('DB_DATABASE', 'task'),
'username' => env('DB_USERNAME', 'root'),
'password' => env('DB_PASSWORD', 'test'),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'strict' => false,
],
and my .envi file
APP_ENV=local
APP_DEBUG=true
APP_KEY=HBzhX830sIrNbZ2hdB23DGAuGa4mj4IL
DB_HOST=10.0.1.22
DB_DATABASE=task
DB_USERNAME=root
DB_PASSWORD=test
CACHE_DRIVER=file
SESSION_DRIVER=file
QUEUE_DRIVER=sync
MAIL_DRIVER=smtp
MAIL_HOST=mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
thanks for all the help
Change the DB_HOST to 127.0.0.1
10.0.1.22 is the external address to your VM machine from your computer.
Since Apache/PHP and MySQL are running on the same machine, there's no reason connect them with the external address but rather with the internal (127.0.0.1).
When you create a user in MySQL you can set what IP'addresses it should accept connections from and as default, in most cases, the root user is usually set to only listen to internal calls (127.0.0.1).
Change your
DB_HOST=10.0.1.22
to
DB_HOST = 127.0.0.1
Because Loaclhost define on this port. Simply it means 127.0.0.1 == localhost
$cfg['Servers'][$i]['host']
I am new to laravel and while trying to connect to database in localhost using xammp iam getting an error that
SQLSTATE[HY000] [1045] Access denied for user 'homestead'#'localhost' (using password: YES)
my connection code is that
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', 'localhost'),
'database' => env('DB_DATABASE', 'hindutemples'),
'username' => env('DB_USERNAME', 'root'),
'password' => env('DB_PASSWORD', ''),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'strict' => false,
],
but 'hindutemples' database exists i dnt know why it is trying to connect with homestead
Any help appreciated.
rename .env.example to .env. Then set appropriate values in .env files. It should work.
UPDATE
Laravel 5 stores settings in .env file. Laravel 5 comes with default .env.example file in a root folder. If you can not find it in project root it may have been hidden.
You need to rename .env.example or create new .env file inside project root and put app settings in it like given below,
APP_ENV=local
APP_DEBUG=true
APP_KEY=0SewSBZ47SfA4vRV6o8BeW74PMFwPpoX
DB_HOST=localhost
DB_DATABASE=hindutemples
DB_USERNAME=root
DB_PASSWORD=
CACHE_DRIVER=file
SESSION_DRIVER=file
QUEUE_DRIVER=sync
MAIL_DRIVER=smtp
MAIL_HOST=mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
env() returns values from .env files. if it could not find setting in .env file it returns false or if supplied default e.g. env('DB_USERNAME', 'homestead') it will return default value. in your case it can not find .env setting so it is returning homestead as a username and hence error.
Read More