Configuración de Laravel en un Mac php artisan migrate error: No hay tal archivo o directorio [duplicar]


Esta pregunta ya tiene una respuesta aquí:

  1. Sacó un proyecto de laravel que funciona perfectamente desde un git a un mac que ejecuta MAMP. El proyecto se ejecutó perfectamente en una máquina linux.
  2. composer install
  3. Php artisan migrar, consiguió el siguiente error:

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

NB: php-v es 5.5 y mysql - v es 5.5 desde el terminal Aquí está parte de mi configuración/base de datos.php

    'mysql' => array(
        'driver'    => 'mysql',
        'host'      => 'localhost',
        'database'  => 'essays',
        'username'  => 'root',
        'password'  => 'root',
        'charset'   => 'utf8',
        'collation' => 'utf8_unicode_ci',
        'prefix'    => '',
    ),

Traté de reemplazar localhost con 127.0.0.1 sin éxito. Amablemente ayuda..

Editar: He añadido estas tres líneas en mi php.ini

mysql.default_socket = /var/run/mysqld/mysqld.sock

mysqli.default_socket = /var/run/mysqld/mysqld.sock

pdo_mysql.default_socket = /var/run/mysqld/mysqld.sock

También agregué este enlace simbólico:

sudo mkdir /var/mysql
cd /var/mysql && sudo ln -s /Applications/XAMPP/xamppfiles/var/mysql/mysql.sock

Pero eso no resolvió. También saqué un nuevo proyecto laravel desde git y me encontré con el mismo error después de composer install entonces php artisan migrate

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

La versión para mac es 10.7.4

Author: ForguesR, 2013-10-20

8 answers

Si está utilizando MAMP, asegúrese de agregar la clave unix_socket con un valor de la ruta que el mysql.sock reside en 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'    => '',
    ),
 168
Author: keithics,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-01-01 19:09:38

No asumas que tu unix_socket sería diferente de uno a otro, trata de encontrarlo.

En primer lugar, obtenga su ubicación unix_socket.

$ mysql -uroot -p

Introduzca su contraseña mysql e inicie sesión en su servidor mysql desde la línea de comandos.

mysql> show variables like '%sock%';
+---------------+---------------------------------------+
| Variable_name | Value                                 |
+---------------+---------------------------------------+
| socket        | /opt/local/var/run/mysql5/mysqld.sock |
+---------------+---------------------------------------+

Su unix_soket podría ser diferente.

Entonces tienes 2 solución para resolver tu problema:

(1) Cambie su config/database.php

    'mysql' => array(
    'driver'    => 'mysql',
    'host'      => 'localhost',
    'database'  => 'essays',
    'username'  => 'root',
    'password'  => 'root',
    'unix_socket'   => '/opt/local/var/run/mysql5/mysqld.sock', //Your sock got from above
    'charset'   => 'utf8',
    'collation' => 'utf8_unicode_ci',
    'prefix'    => '',
),

(2) Cambia tu php.ini, encuentra tu archivo php.ini desde

<? phpinfo();

Usted tal vez instalar muchos php con diferentes versiones, así que por favor no asuma su php.ubicación del archivo ini, obtenerlo de su 'phpinfo';

Cambie su php.ini:

mysql.default_socket = /opt/local/var/run/mysql5/mysqld.sock

mysqli.default_socket = /opt/local/var/run/mysql5/mysqld.sock

pdo_mysql.default_socket = /opt/local/var/run/mysql5/mysqld.sock

Luego reinicie su apache o php-fpm.

 19
Author: lijinma,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-09-03 17:03:24

Tenía el mismo problema, pero ahora está funcionando para mí.

Si alguien sigue teniendo problemas, pruebe esto:

  • Asegúrese de que su bootstrap/start.php contiene su nombre de host real, no el nombre de su host virtual. Introduzca hostname en la terminal para obtener su nombre de host. Como es una matriz, creo que puede ingresar tanto su nombre de host como el nombre de su(s) host(s) virtual (es).
  • Sustitúyase "localhost" por "127.0.0.1".
 17
Author: Nick,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-11-08 08:44:21

Si está utilizando XAMPP, la solución es:

'mysql' => array(
        'driver'      => 'mysql',
        'unix_socket' => '/Applications/XAMPP/xamppfiles/var/mysql/mysql.sock',
        'host'        => 'localhost'
)
 12
Author: cristianojeda,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-08-12 16:14:00

Esto funciona para mí en Laravel 5.0, cambie el DB_HOST=127.0.0.1:33060 in .archivo env.

Otras respuestas no funcionan...

 9
Author: Igor Trindade,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-08-02 23:17:11

Para Laravel 5.0+ cambiar localhost a 127.0.0.1 en su .env archivo, así antes de ir a jugar con Sockets Unix, etc-esto funcionó para mí.

Noobs cuidado: Para cualquiera que use Laravel 5 y use material de aprendizaje antiguo, tenga en cuenta que hubo un cambio bastante marcado en la estructura de carpetas de las versiones anteriores, aunque esto parece ser para mejor - echa un vistazo a este artículo https://mattstauffer.co/blog/laravel-5.0-directory-structure-and-namespace

 5
Author: brianjlennon,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-07-03 10:33:59

Otra solución es agregar el número de puerto en la clave de host. En este caso MAMP utiliza el 8889 por defecto:

'mysql' => array(
    'driver'    => 'mysql',
    'host'      => 'localhost:8889',
    'database'  => 'essays',
    'username'  => 'root',
    'password'  => 'root',
    'charset'   => 'utf8',
    'collation' => 'utf8_unicode_ci',
    'prefix'    => '',
),
 3
Author: sveggiani,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-11-25 02:14:29

Si está utilizando Laravle 5.1.11 versión + MAC + MAMPP

Debe agregar "Unix_socket" en el archivo "yourapp"/app/config/database.php

'mysql' => [
    'driver'    => 'mysql',
    'host'      => env('DB_HOST', 'localhost'),
    'unix_socket'   => '/Applications/MAMP/tmp/mysql/mysql.sock',
    'database'  => env('DB_DATABASE', 'forge'),
    'username'  => env('DB_USERNAME', 'forge'),
    'password'  => env('DB_PASSWORD', ''),
    'charset'   => 'utf8',
    'collation' => 'utf8_unicode_ci',
    'prefix'    => '',
    'strict'    => false,
],

Unix_socket param se agregó a la unidad de configuración de mysql anterior.

 2
Author: jai,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-12-27 12:27:13