I'm setting up my project after restoring my macOS Mojave and getting an error. I install MySQL with homebrew.
I tried to change localhost to 127.0.0.1 but it didn't help me
This is my .env
DB_CONNECTION = mysql,
DB_HOST = localhost
DB_PORT = 3306
DB_DATABASE= example
DB_USERNAME=root
DB_PASSWORD=
This is an error message
1 Doctrine\DBAL\Driver\PDOException::("SQLSTATE[HY000] [2002] No
such file or directory")
/Documents/cleaning/example/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php:31
2 PDOException::("SQLSTATE[HY000] [2002] No such file or
directory")
/Documents/cleaning/example/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php:27
If not exist .env file ,create one from .env-example and in set declare database configs and run command
If you not callin key:generate
php artisan key:generate
If you have been all,exec below command
php artisan config:cache
And try
php artisan migrate
If your still get error try localhost or http://127.0.0.1 ,edit it
And again run below command
php artisan config:cache
Import
-2002 error given error when user and password wrong to host
Try 127.0.0.1 instead of localhost in your .env file.
Run php artisan cache:clear
php artisan migrate --env=production
Above steps works for me.
Related
This question already has answers here:
MySQL connection not working: 2002 No such file or directory
(23 answers)
Closed 1 year ago.
i moved my laravel project from windows to ubuntu, i did everything required ( installing php, composer ...) then when i run php artisan migrate to create my database tables, it says:
In Connection.php line 664:
SQLSTATE[HY000] [2002] No such file or directory (SQL: select * from informa
tion_schema.tables where table_schema = blog and table_name = migrations)
In Connector.php line 68:
SQLSTATE[HY000] [2002] No such file or directory
PS: i was using WAMP server for my database in Windows.
my .env DB config:
DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=blog
DB_USERNAME=blog
DB_PASSWORD=
Your database seems to be missing the migrations table. You can create it by running
php artisan migrate:install
After that you will be able to run your migrations.
you are getting that error because php artisan migrate is trying to check the migration table from your database for the migration details, so it doesn't migrate old migrations files again, but since you want to create the tables afresh,
run this
php artisan migrate:fresh
this would clear the database and create all table afresh
or run
php artisan migrate:install
this would create the migration table ,
then run php artisan migrate to create all other tables
Use 127.0.0.1 for DB_HOST
Run php artisan config:clear
I keep this while running php artisan migrate
SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: nodename nor servname provided, or not known
My Environment
Laravel Framework version 5.1.20 (LTS)
Laravel Installer version 1.2.0
PHP 5.6.14 (cli) (built: Oct 2 2015 08:55:56)
mysql Ver 14.14 Distrib 5.6.24, for osx10.10 (x86_64)
.env file
APP_ENV=local
APP_URL=http://localhost/
APP_DEBUG=true
APP_KEY=****
DB_HOST=http://localhost/
DB_DATABASE=name-local
DB_USERNAME=root
DB_PASSWORD=
UNIX_SOCKET = /tmp/mysql.sock
That data-base name-local is exist in my local database.
Any hints / suggestions will be a huge help for me.
Check your DB_HOST on your .env file
DB_HOST=http://localhost/ --> DB_HOST=localhost
Result:
I can migrate peacefully now.
php artisan migrate
Migration table created successfully.
Migrated: 2014_10_12_000000_create_users_table
Set DB_HOST=localhost and run the following artisan command
php artisan config:clear it will help you, clear cached config
I finally figured out what was causing this error for me. I'm using docker but I wasn't running php artisan migrate from the shell in the container. I was just running it in Terminal after navigating to the laravel project folder.
Go to your docker dashboard and launch the CLI for the laravel container in the image for your project. Then run the migrate command.
You might also get this error if you are using sail, and you run
php artisan migrate
instead of:
sail artisan migrate
I had the same problem while running Laravel from DDEV.
Solution: run "php artisan migrate" within your DDEV container.
user#ddev-project: ddev ssh
user#ddev-project:/var/www/html$ php artisan migrate
That should solve the issue.
Had the same issue on laravel 8.x after a fresh install. Setting DB_HOST=0.0.0.0 fixed it for me.
Remember to run php artisan config:clear afterwards.
if you are using docker first find your docker container with docker ps command and then execute php artisan migrate command form your container with this command
docker exec -it {containerId}
bash
You can change the SESSION_DRIVER to file. Worked for me.
I'm using Laravel 7, when I launch from terminal php artisan migrate, I get this error
zsh: illegal hardware instruction php artisan migrate
All other artisan commands works fine like php artisan make:model or php artisan make:migration
System requirements:
PHP 7.4.5 (cli)
Zend Engine v3.4.0
MacBook Pro Catalina 10.15.4
Thank you
Just resolved yet.
I'm using MAMP PRO for the virtual server
The problem was in the db configuration, I added in the .env file
DB_SOCKET=/Applications/MAMP/tmp/mysql/mysql.sock
The default configuration in the .env file didn't work for me, this configuration will work
DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=8889
DB_DATABASE=dbname
DB_USERNAME=root
DB_PASSWORD=root
DB_SOCKET=/Applications/MAMP/tmp/mysql/mysql.sock
I am working in a Client's Laravel project which version is 5.7.28. But I am not getting anything in storage/logs/ folder. I copied the .env.example to .env. I run composer install and php artisan key:generate. Some of my .env files configuration is like below
APP_NAME=Laravel
APP_ENV=local
APP_KEY=base64:8ovbzfpWGsGTDyDIRWDO8VKObeXGyWqnMVw5KjTVJTc=
APP_DEBUG=true
APP_URL=http://127.0.0.1:8000
BASE_URL=http://127.0.0.1:8000
I set permission 777 for all folders.
But I am getting 500 error. How can I solve the error.
try change to prod mode: APP_ENV=production then back to dev mode
don't forget to run: php artisan config:clear -> php artisan env
Run
php artisan optimize
Before production
i have a error when i running php artisan migrate. It shows could not find driver in connection.php and connector.php , any idea to fix it ?error php artisan migrate
Try checking with 127.0.0.1 and check if you have correct db configuration.