Viewed   210 times
  1. Pulled a perfectly working laravel project from a git into a mac running MAMP. Project ran perfectly on a linux machine.
  2. composer install
  3. php artisan migrate, got the following error:

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

NB: php -v is 5.5 and mysql -v is 5.5 from the terminal Here is part of my config/database.php

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

I tried replacing localhost with 127.0.0.1 with no avail. Kindly help..

Edit: I added these three lines in my 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

I also added this symlink:

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

But that didnt solve. I also pulled a fresh new laravel project from git and ran into the same error after composer install then php artisan migrate

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

The mac version is 10.7.4

 Answers

2

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'    => '',
    ),
Friday, November 4, 2022
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
Friday, August 5, 2022
 
wds
 
wds
5

You have to understand the difference between a filesystem and an HTTP daemon.
Although they have somewhat similar appearance, it is absolutely different matters.

To use opendir, you have to open *a directory, not HTTP resource.

opendir('../uploads');

should work

opendir($_SERVER['DOCUMENT_ROOT'].'/uploads');

would be better as it will always point to the uploads directory, no matter from where you called it.

Wednesday, October 12, 2022
 
bart_s.
 
2

Since you're referencing an id you need to make the foreign key column unsigned. As ids are by default unsigned (non-negative).

So do this for all your foreign keys:

$table->integer('product_id')->unsigned();
Friday, September 30, 2022
 
dreme
 
5

If you are on rails 3 then the command is:

rails generate scaffold newtest name:string

Or the slightly shorter:

rails g scaffold newtest name:string

Notice rails not ruby.

Tuesday, September 13, 2022
 
Only authorized users can answer the search term. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :
 
Share