Database Laravel php artisan migrate connection refused - laravel

When I use 'php artisan migrate' I get the following error message:
[Illuminate\Database\QueryException]
SQLSTATE[HY000] [2002] Connection refused (SQL: select * from information_schema.tables where table_schema = homestead and table_name = migrations)
[PDOException]
SQLSTATE[HY000] [2002] Connection refused
I've installed Laravel on a mac with XAMPP and have the following settings:
database.php
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', 'localhost'),
'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,
],
.env
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=homestead
DB_USERNAME=homestead
DB_PASSWORD=secret
I've tried several solutions I could find online, but none have worked so far.

This is really anoying, but changing DB_HOST=127.0.0.1 to DB_HOST=localhost solves the problem. Give it a try (obviously your file permission must be the right one)

The solution for me was different than anywhere else I found online.
I was unknowingly using the VM (virtual machine) version of XAMPP on Mac, which functions differently than the normal version. VM XAMPP interface looks like this.
If you are using the VM XAMPP, uninstall it and install the correct XAMPP version here.
Once I installed the new version php artisan migrate worked.

If someone is experiencing this when using Docker, I had a multi-stage build with first container running the dependency installation and the second one just being the runtime. What I didn't realise is that the installation with Laravel scripts generate a cached config (bootstrap/cache/config.php) which is used instead of the config/database.php file.
Adding the following to the Dockerfile as the last step did the trick:
RUN php artisan config:clear

First create your database. Read more about it here: http://www.complete-concrete-concise.com/web-tools/creating-a-mysql-database-using-xampp
Let's say your new database is named: my_db.
Use this in your .env:
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=my_db
DB_USERNAME=root
DB_PASSWORD=""

I was using a Vagrant machine to run the whole thing, but I was mistakenly running command on my own machine.Thought this might help someone.

Hi you don't have DB_SOCKET= /path/to/socket in env.file while you have unix_socket => env('DB_SOCKET', '') in database.php file.
You could get the /path/to/socket by $ mysql_config --socket

if you are using MAMP then in your .env file :
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=homestead
DB_USERNAME=root
DB_PASSWORD=root

I had a similar problem. Only it was using "ddev". It turned out that mysql responds to a completely different IP instead of 127.0.0.1 or locahost.
console: ddev ssh // If using ddev.
Login to mysql: mysql -y USERNAME -p
Runs this "SELECT SUBSTRING_INDEX(USER(), '#', -1) AS ip, ##hostname as hostname, ##port as port, DATABASE() as current_database;" It displays a table with data. The IP may not be the one to connect to. Must take is hostname.
ping "hostname" from the previous table. And then try to put the obtained IP in the .env file. Or "hostname". It also fits.
Now connection works.

This is coming late but it might help someone. I had the same error, it turned out it was a typo in my .env file. Instead of DB_HOST, it was B_HOST. In your case it might be some other env key. Just look closer and you will discover the you have a malformed env file.

Related

Laravel xampp migrate missing driver windowns 10

Windows 10, using xampp v3.2.4, Laravel 8.12. Whenever running php artisan migrate I get could not find driver (SQL: select * from information_schema.tables where table_schema = public and table_name = migrations and table_type = 'BASE TABLE').
I've tried just about every 'solution' on stack. I've updated the C:\xampp\php\php.ini file, by uncommenting extension=pdo_mysql and extension=mysqli plus setting extension_dir="C:/xampp/php/ext" with no luck.
I had no problems creating the database by logging into MySQL on the command line with mysql -u root and creating the database.
In the env file, `
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=testme
DB_USERNAME=root
DB_PASSWORD=
anddatabase.phpit's set to'default' => env('DB_CONNECTION', 'mysql'),` I'm out of solutions. Any help is much appreciated. The database shows on the PHPMyAdmin Dashboard.
After uninstalling Laravel, then reinstalling the migrate command is now working. Although I have no idea what caused it to now work correctly.

(AWS SES / Laravel) - Connection could not be established with host smtp.mailtrap.io

I've been trying to setup mailing in Laravel 7 with AWS SES and have setup all my credentials properly and set my drivers to SES.
I get the following error when attempting to send an email verification with the default built in functionality.
Connection could not be established with host smtp.mailtrap.io :stream_socket_client(): unable to connect to tcp://smtp.mailtrap.io:2465 (Operation timed out)
.env
MAIL_DRIVER=ses
MAIL_FROM_ADDRESS=no-reply#taxsion.com
MAIL_FROM_NAME="${APP_NAME}"
AWS_ACCESS_KEY_ID=HIDDEN
AWS_SECRET_ACCESS_KEY=HIDDEN
AWS_DEFAULT_REGION=us-east-1
I have ensured that the AWS key and secret have full access to SES, in my config/services.php I am setting it to use these credentials.
'ses' => [
'key' => env('AWS_ACCESS_KEY_ID'),
'secret' => env('AWS_SECRET_ACCESS_KEY'),
'region' => env('AWS_DEFAULT_REGION', 'us-east-1'),
]
I have searched through numerous "solutions" and have tried creating a separate user for SES only with no luck.
Any help would be great, thanks!
Laravel 7 has introduced Multiple Mail Drivers which has changed how the mail config works.
If you look at your config/mail.php you'll notice that you have a MAIL_MAILER value instead of MAIL_DRIVER. You should be able to simply change the MAIL_DRIVER to MAIL_MAILER in your .env file:
MAIL_MAILER=ses
You may also need to clear the config cache after you've made the change:
php artisan config:clear
The issue was that my .env was not being loaded due to caching.
Simply running php artisan config:clear cleared the cached config and updated it with my new parameters.
My .env contains the following:
MAIL_MAILER=ses
MAIL_FROM_ADDRESS=no-reply#domain.com
MAIL_FROM_NAME="${APP_NAME}"

How to deploy laravel 5.4 to the production server?

I generate one laravel project . Now i need to move the project to the production server. In the local system, I use php artisan serve to run the project and run http://127.0.0.1:8000/ .
while moving to the production server, I changed the .env file
APP_ENV=production
APP_DEBUG=false
APP_LOG_LEVEL=debug
APP_URL=http://myserverip
My config/app.php
'env' => env('APP_ENV', 'production'),
'debug' => env('APP_DEBUG', false),
'url' => env('APP_URL', 'http://my ip'),
I run the project (ip/projectfolder) in live it displays dirctory files listing in the browser.
Is there is any thing extra I need to configure ?

php artisan migrate - SQLSTATE[HY000] [2002] No such file or directory

I went through the laravel to-do app and am stuck at the php artisan migrate part. I know this question has been posted many times here already but I feel like I've tried many suggestions that just aren't working--changing the host to localhost and 127.0.0.1, generating the key for the .env file, adding in a socket, forcing the migration, etc. Below is a screenshot of my .env and database files for your reference. Any assistance is greatly appreciated!
screenshot here
So because you're using MAMP, there's a few caveats which are probably not clear, such as MAMP not using a normal UNIX Socket.
But to fix your problem, you'll need to do the following in your database config file, replace unix_socket with this:
'unix_socket' => '/Applications/MAMP/tmp/mysql/mysql.sock',
You may also have to run:
php artisan cache:clear
Incase your config files have been cached previously.
Had this same issue since I am using MAMP. I am on laravel 5.5 so my database.php has this line under the mysql directive:
'unix_socket' => env('DB_SOCKET', ''),
The solution was to add the DB_SOCKET option which was missing on the environment file:
DB_SOCKET=/Applications/MAMP/tmp/mysql/mysql.sock
I experienced the same problem using Laravel 5.7.3 with XAMPP for OS X (not XAMPP-VM) and managed to solve this by referring to Kyo's solution in this post.
I updated line 49 in config/database.php:
'unix_socket' => env('DB_SOCKET', ''),
with
'unix_socket' => env('DB_SOCKET', '/Applications/XAMPP/xamppfiles/var/mysql/mysql.sock'),
I also tried TechyTimo's solution above and this worked for me as well. I assume it would be better to use this solution since all configurations are kept in one file.

Laravel Queue error when using database driver

I'm getting the following error when pushing a job to a laravel 5.2 Queue, using the database driver.
exception 'InvalidArgumentException' with message 'No connector for
[]' in
/var/www/krsa/vendor/laravel/framework/src/Illuminate/Queue/QueueManager.php:150
The queue is running with supervisor and the following setup
[program:krsa-worker]
process_name=%(program_name)s_%(process_num)02d
command=php /var/www/krsa/artisan queue:work —tries=3 --daemon
autostart=true
autorestart=true
user=root
redirect_stderr=true
stdout_logfile=/var/www/krsa/supervisor/worker.log
.env file points to the database driver
QUEUE_DRIVER=database
config/queue.php file has correct settings:
'database' => [
'driver' => 'database',
'table' => 'jobs',
'queue' => 'default',
'expire' => 60,
],
table jobs exists and has the correct columns.
The same settings work on another project on a different server.
I've made composer update and made sure all dependencies are installed, unless there are extra dependencies I am not aware of for the database driver.
Can't figure out why Laravel is not picking up the connector/driver. Any help would be greatly appreciated.
UPDATE
When I run php artisan queue:work the queue processes all jobs correctly.
I've just run into this too. It'll likely be because tries doesn't have two hyphens before it, only one in your case

Resources