0

I am on MAC, my XAMPP is of XAMPP-VM,and creates a folder with lampp.

In my XAMPP, my server is:localhost:8080

I have an error, which says

Illuminate\Database\QueryException] SQLSTATE[HY000] [2002] No such file or directory (SQL: select * from information_schema.tables where table_schema = laravel and table_name = migrations)

I have tried out many solutions,but none worked for me.

I am not sure about the 'DB_SOCKET' like what it is and where the path for the file exist in the XAMPP.

.env

    APP_NAME=Laravel
    APP_ENV=local
    APP_KEY=base64:zS3EUWDenTnhNu0CpN1TQdVSM0ArEgtFI1zpIwes1qQ=
    APP_DEBUG=true
    APP_URL=http://localhost

    LOG_CHANNEL=stack

    DB_CONNECTION=mysql
    DB_HOST=localhost
    DB_PORT=3306
    DB_DATABASE=demo
    DB_USERNAME=root
    DB_PASSWORD=
    DB_SOCKET=/Applications/lampp/tmp/mysql/mysql.sock

    BROADCAST_DRIVER=log
    CACHE_DRIVER=file
    QUEUE_CONNECTION=sync
    SESSION_DRIVER=file
    SESSION_LIFETIME=120
    REDIS_HOST=127.0.0.1
    REDIS_PASSWORD=null
    REDIS_PORT=6379

    MAIL_MAILER=smtp
    MAIL_HOST=smtp.mailtrap.io
    MAIL_PORT=2525
    MAIL_USERNAME=null
    MAIL_PASSWORD=null
    MAIL_ENCRYPTION=null
    MAIL_FROM_ADDRESS=null
    MAIL_FROM_NAME="${APP_NAME}"

    AWS_ACCESS_KEY_ID=
    AWS_SECRET_ACCESS_KEY=
    AWS_DEFAULT_REGION=us-east-1
    AWS_BUCKET=

    PUSHER_APP_ID=
    PUSHER_APP_KEY=
    PUSHER_APP_SECRET=
    PUSHER_APP_CLUSTER=mt1

    MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
    MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"

database.php

'mysql' => [
            'driver' => 'mysql',
            'url' => env('DATABASE_URL'),
            'host' => env('DB_HOST', '127.0.0.1'),
            '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' => '',
            'prefix_indexes' => true,
            'strict' => false,
            'engine' => null,
            'options' => extension_loaded('pdo_mysql') ? array_filter([
                PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
            ]) : [],
        ],
brombeer
  • 8,716
  • 5
  • 21
  • 27

2 Answers2

0

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):

enter image description here

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:

hmg
  • 186
  • 1
  • 7
0

if you are using mac

in terminal write

composer global require "laravel/installer"(enter)

nano .bash_profile(enter)

press i button so you will able to write

export PATH="$PATH:$HOME/.composer/vender/bin"

press alt+command and enter press x button to exit

then open you XAMPP

click general

click open terminal

click terminal

pwd (enter)

cd space .. (enter)

cd opt/

cd lampp (even if you are using xampp)

cd htdocs

cd ur laravel folder name

php artisan migrate

https://www.youtube.com/watch?v=BUFyKk-GrvI&t=18s

i hope will work

ali
  • 1
  • 1