I am trying to run a laravel project on OS X. I installed MySql with homebrew. I tried googling around for why I'm getting this error:
SQLSTATE[HY000] [2002] No such file or directory
when I try to do
php artisan migrate
And most of the answers I see say php and MySql cannot communicate to each other. I've been trying to see where I went wrong since I think I followed previous posts about it, and it still doesn't work. I created a page that just does this:
<?php phpinfo(); ?>
And I see these types of things: In the Configure area, I see:
'--with-mysql-sock=/tmp/mysql.sock' '--with-mysqli=mysqlnd' '--with-mysql=mysqlnd' '--with-pdo-mysql=mysqlnd' '--enable-pcntl' '--enable-zend-signals' '--enable-dtrace'
loaded configuration file:
/usr/local/etc/php/5.4/php.ini
If I ls /tmp
, I do see mysql.sock.
In that php.ini file, I set these lines: pdo_mysql.default_socket=/tmp/mysql.sock mysql.default_socket = /tmp/mysql.sock mysqli.default_socket = /tmp/mysql.sock
And then in /usr/local/Cellar/mysql/5.6.16/my.cnf, I added the following line:
socket = /tmp/mysql.sock
I DID restart apache, as well as check mysql is running. I haven't seen any other advice besides the php and mysql connection. I think there are two versions of php on my system because when I installed mcrypt or something else I can't remember, it installed another php version. But when I do look at the output of phpinfo, I'm editing the appropriate php.ini file. I didn't know if there is another piece I am missing. Any thoughts? Thanks
I had a similar error. I am using MAMP and what solved my issue was:
For users which are looking for a solution on XAMPP (Tested and worked on Mac OS X),
Open terminal and create a symbolic link :
sudo mkdir /var/mysql cd /var/mysql sudo ln -s /Applications/XAMPP/xamppfiles/var/mysql/mysql.sock
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With