Reputation: 712
I'm trying to get a crontab working for Cakephp (running on my shared Dreamhost server for now).
I have a shell set up as per the book, which works fine via either a cron run or manually executing (both via a shell file, e.g:
cron.sh
#########
cd /pathToApp/app/Console
/usr/local/bin/php cake.php updater list_reports
where updater is my shell and list_reports a method thereof.
The problem occurs when I try to access the database in the shell ("Using models in your shell", same link).
Error Message:
Error: Database connection "SQLSTATE[HY000] [2002] Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)" is missing, or could not be created.
My DB Set-up (site works fine for http, do I need to add unix_socket
or something?
array(
'datasource' => 'Database/Mysql',
'persistent' => false,
'host' => 'mysql.mydomain.net',
'port' => '3306',
'login' => '*******',
'password' => '*******',
'database' => '*******',
'prefix' => '',
);
Thing I've tried:
/var/run/mysqld/mysqld.sock
- permission deniedUpvotes: 1
Views: 1986
Reputation: 712
It's official! I'm a db!
I can confirm this problem was not caused by either Cakephp or Mysql, but rather for something I'd done myself and forgot about....
I had a little switch in database.php to automatically detect whether I was in the dev, test, staging environment etc. I had the default set to local, and since the bash script didn't pick up $_SERVER['SERVER_NAME'] which I was using for the switch, it defaulted to my local db.
Thanks to ifunk for spotting the clue which enabled me to unravel this and get back on track!
:)
Upvotes: 3