Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Wooyoung's avatar

Laravel 5 php artisan migrate does not work

Im using Mac os x Yosemite 10.10. I installed the lastest laravel version 5.1. I set up Homestead and it has been running great. However, when I try to make a MySQL connection in my Laravel app, and am now experiencing errors when running php artisan migrate on my development machine. Following is the statement that I see when I run php artisan migrate.

[PDOException] SQLSTATE[HY000] [2002] No such file or directory

How can I solve this problem? When I get into VM, mysql works fine. But I do not know how I can use php artisan migrate. Thank you in advance.

Best

0 likes
15 replies
jakeharris's avatar

Sounds like your database doesn't exist. Have you created the database in MySQL or created the SQLite file?

2 likes
Wooyoung's avatar

Hi. I have made the database that has the same name(users) with my create_users_table.php file. And I also have SQLite file named database.sqlite in storage folder... :(

Wooyoung's avatar

How can I edit .evn file? and What do I need to do with .evn file???

jakeharris's avatar

As mentioned above, you might need to configure your .env file. To do this, you can simply copy/rename the .env.example to .env and set the appropriate values there.

1 like
RachidLaasri's avatar

If you just installed laravel you will see a .env file, rename it to .env and edit these values :

DB_HOST=localhost
DB_DATABASE=database_name
DB_USERNAME=database_username
DB_PASSWORD=database_password
1 like
Wooyoung's avatar

Thank you for the advices. I do appreciate that. But since I'm a beginnier, I can't figure out where .env file is :(

anon12822's avatar

.env - It's in your project root.

Once you've done that it may still fail to work.

The error could be that since you are running Homestead as your development environment, you might not have installed MySQL on your actual system..

Try going into your box and trying it.

homestead ssh
cd your/project
php artisan migrate
2 likes
Wooyoung's avatar

I can't find .env file unfortunately.. I'm using Laravel 5.1. Has it been changed? I'm stuck with configuration :( ahhhhhhh

anon12822's avatar

Create a file called .env and edit it to suit your needs.

APP_ENV=local
APP_DEBUG=true
APP_KEY=SomeRandomString

DB_HOST=localhost
DB_DATABASE=homestead
DB_USERNAME=homestead
DB_PASSWORD=secret

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
1 like
luceos's avatar

.env is not available by default there is a .env.example that you can copy (or rename) with the defaults

1 like
Wooyoung's avatar

Thank for the advices!! I have created .env file as you guys have mentioned. But I still see the same error..

[PDOException]
SQLSTATE[HY000] [2002] No such file or directory

What do I need to do ?????? ahhhh Why does it not work??

jonnyhocks's avatar

Seen as you have only now edited your .env file; I'm assuming that you edited the database credentials manually in the database config file. Check to see if you need to revert back to the original env variables.

1 like
Wooyoung's avatar
Wooyoung
OP
Best Answer
Level 1

I have solved my problem by editing databse.php in config folder

'mysql' => [ // ... 'host' => env('DB_HOST', 'localhost') . ('homestead' == gethostname() ? null : ':33060'), // ... ],

This was what I needed. Thank you all. I do appreciate that!

1 like

Please or to participate in this conversation.