2

I cloned a project which is built on laravel 4.2. Currently my Xampp has a version 7.0.13.1 and has php version of 7.1.

When i type php artisan migrate, it gives an error [PDOException] SQLSTATE[HY000] [2002] No such file or directory which means my artisan is not connected to my mysql running on the Xampp.

In the terminal, i tried which php and i get /usr/local/php5/bin/php .

Could this be the cause of my problem? That the path doesn't point to my Xampp version 7.0.13.1?

PS: After cloning, i followed the steps on the github page

composer install

$ php artisan migrate

$ php artisan db:seed

$ php artisan serve

Please help?

XamarinDevil
  • 873
  • 5
  • 17
  • 38
  • Check out this answer https://stackoverflow.com/questions/20723803/pdoexception-sqlstatehy000-2002-no-such-file-or-directory – Phil Mar 03 '18 at 19:14
  • @Phil, i am able to migrate using `php artisan migrate --env=production` but i can't run the application. When i run the command `php artisan serve` and reload the browser, i get [PDOException] SQLSTATE[HY000] [2002] No such file or directory – XamarinDevil Mar 03 '18 at 19:16
  • What you did after getting clone also share all steps ? – Niklesh Raut Mar 03 '18 at 19:17
  • @C2486, i don't get your statement. But you mean my steps after cloning? check my update – XamarinDevil Mar 03 '18 at 19:19
  • Are you using the Xamp's MySQL socket? To do so you should use the Xamp's version of PHP, not the one you've installed globally on your system. – Anthony Mar 03 '18 at 19:55
  • @AnthonyB, okay i will have to include the socket into the mysql configuration in the database.php file but how do i get the socket ? – XamarinDevil Mar 03 '18 at 19:59

2 Answers2

3

Tools like XAMP, MAMP or WAMP have their own PHP and MySQL binaries and do not use a potential globally installed version.
I guess you are using MySQL installed with XAMP, so the socket is not the default one that you could search in your system but the one in XAMP.

You have two options:

  1. Update your global PHP's php.ini to set the pdo_mysql.default_socket or mysqli.default_socket to the MySQL socket in your XAMP installation in order to your global PHP binary will be able to connect the your XAMP's MySQL version.
  2. Use the XAMP's PHP binary (recommanded).

The recommanded option is the second one, because the XAMP's PHP binary is already configured to use the right MySQL socket and does not need to update any configuration file.

I explain below how to find the MySQL socket and how to locate the PHP binary directory.

Find the MySQL socket path:

  • Write the following code in you Web server directory (usually www/, htdocs/ or public_html/)

    <?php
    //phpinfo.php
    phpinfo();
    
  • Open the URL http://localhost/phpinfo.php in your Web browser (adapt the host name if required).

  • According to the PHP extension you use to connect to the datase search for either pdo_mysql.default_socket or mysqli.default_socket and you'll find the path to the socket file.

See phpinfo().

Find the PHP binary directory:

  • Write the following code in your Web server directory

    <?php
    //bindir.php
    echo PHP_BINDIR;
    
  • Open the URL http://localhost/bindir.php in your Web browser.

  • The path to the directory hosting the PHP binary is written.

Thanks to this answer for the information.
See the documentation about pre-defined constants.

In your case the directory hosting PHP is /Applications/XAMPP/bin/ so you should run the command:

/Applications/XAMPP/bin/php artisan migrate
Anthony
  • 2,014
  • 2
  • 19
  • 29
0

Did you have a .env file with an existant database and an authorised user and password for that database?

Jacobo
  • 1,259
  • 2
  • 19
  • 43