Setting Up Laravel on a MAC PHP Artisan Migrate Error: No Such File or Directory

Setting up Laravel on a Mac php artisan migrate error: No such file or directory

If you are using MAMP be sure to add the unix_socket key with a value of the path that the mysql.sock resides in MAMP.

'mysql' => array(
'driver' => 'mysql',
'host' => 'localhost',
'unix_socket' => '/Applications/MAMP/tmp/mysql/mysql.sock',
'database' => 'database',
'username' => 'root',
'password' => 'root',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
),

Laravel 8 Migrate Error Using XAMPP Database on MAC

I would strongly recommend using Homebrew to set up MySQL instead.

Visit https://brew.sh/

Open your terminal and run the command on the brew website to install it.

Then install mysql using

brew install mysql

Start MySQL by running

brew services start mysql

Create your database by running

mysql -u root -p
CREATE DATABASE atamana_db;

Since PHP doesn't yet understand caching_sha2_password, try mysql_native_password use This Command:

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';

Then hit Control + C to exit MySQL

Try running your migration again.

Php artisan migrate no such file or directory

1) Run command:

composer dump-autoload

2) rollback command:

php artisan migrate:rollback

Then create your migration:

php artisan make:migration create_users_table

SQLSTATE[HY000] [2002] No such file or directory when i try to php artisan migrate

I can see from the screenshot that your phpMyAdmin is connecting to the database at 8889 port, your env has DB_PORT=3306, change to DB_PORT=8889.

Summary of the comment section:

Dan is using MAMP, so the config for mysql connection should contain (for default MAMP settings):

DB_HOST=localhost
DB_PORT=8889
DB_USERNAME=root
DB_PASSWORD=root

PHP Artisan Migrate Error in Lamp Environment

Update - XAMPP VM solution

My bad, previously described solution worked for me in a different XAMPP installation. Since the one you're using is XAMPP-VM, it actually creates a Debian VM, having different default settings for MySQL (probably MariaDB the one that comes with the VM out of the box). So access from your local machine would be forbidden, also for PhpMyAdmin by default should be restricted and must be configured in order to be accessible from outside the VM.

When XAMPP VM starts it assigns an IP for the VM (like the picture below):

Sample Image

That is the IP that should be used in the .env database config (my case DB_HOST=192.168.64.2). But in order to be able to connect to MariaDB in the VM, would be required to open the terminal from XAMPPs VM window. Once you're in, type mysql to enter MariaDB, and type the following:

  • CREATE USER 'admin'@'%' IDENTIFIED BY 'admin';
  • GRANT ALL PRIVILEGES ON . TO 'admin'@'%' WITH GRANT OPTION;
  • FLUSH PRIVILEGES;

That will allow you to access MySQL from your Laravel's application using an admin user with all privileges from outside the VM.
The .env file should look like:

DB_CONNECTION=mysql
DB_HOST=192.168.64.2
DB_PORT=3306
DB_DATABASE=demo // this schema would have to be created first
DB_USERNAME=admin
DB_PASSWORD=admin

Should be good for you to migrate now.

Reference:

  • https://www.apachefriends.org/faq_osx.html

No such file or directory or No such host is known when running migrations

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.



Related Topics



Leave a reply



Submit