Ubuntu – Trying to connect to thesql via php command line through XAMPP (ubuntu/cakephp)

cakephpcommand-line-interfaceMySQLPHPUbuntu

I am trying to run the cake shell through xampp and I am running into some issues.

What works

  • I can connect PHP to Mysql while running through apache (in web
    browser)
  • I can run the PHP CLI in bash by typing php, I set up the
    bin folder under xampp as an environment variable
  • I can run cake, I
    set up the cake/console directory as an environment variable
  • I can run my shell scripts for cake without any models attached

What doesn't work

Running shell scripts when models are attached. I get the following error: PHP Warning: mysql_connect(): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) in /opt/lampp/htdocs/cakephp/cake/libs/model/datasources/dbo/dbo_mysql.php on line 561

What I tried

Originally, the cli was reporting that it couldn't find mysql_connect. So I installed php5-mysql despite my better judgement (I thought XAMPP would have already made the neccesary relationships). After I installed it, it was looking for mysql.sock. I tried changing the location under /etc/php5/cli/php.ini. Perhaps that is not the right location, or maybe I didn't change the correct variable.

Questions

Where can I change where the mysql.sock is located?
Or, I am doing this incorrectly, is there a better way?

Best Answer

You should find where a my.cnf file is located for your setup, I guess it's somewhere under /opt/lampp/etc or something like this. This file has a [mysqld] section with socket=/path/to/mysql.sock parameter. You can use find /opt/lampp -name my.cnf to find the config file.