CakePHP 1.2: config for the console

I hope readers will forgive yet another fleeting entry from me. My Internet connection has been unusually unreliable for about six weeks and since Monday it has been disconnecting around ten times a day. Eugh.

In other news, I’ve been using CakePHP recently. So far I’m finding it pretty good. It’s all starting to come together, but the somewhat distributed documentation makes Google my best friend for development right now! I’m finding some useful little bits as I go, so I thought I’d share things as I discover them.

Setting up the new console in CakePHP 1.2

I found it easy enough to set up the console. One of the first things I did was watch some of the screencasts, including one on setting up the terminal to run console shells from the command line. No problem. But…

Problems connecting to the datasource

I hit a bit of a problem when I wanted to play with the Access Control List (ACL) component. The console couldn’t access the database when I tried to set up the database tables:

cake acl initdb

It had the correct details from the database config file, but it just wouldn’t connect. Specifically, I was getting this

Can't connect to local MySQL server through socket '/etc/mysql.sock'

Grr. The website connected to the database fine when browsing. Hmmm. MySQL seemed to be behaving. Double hmmm. I began thinking it must be a permissions issue somewhere.

Nope, it turns out that localhost hadn’t been resolving to my local IP address. Putting in the IP (127.0.0.1) as the database host fixed everything. I’m guessing that command line PHP, or at least my installation of it, doesn’t do name lookups.

Huge thanks to the lovely and wonderful lornajane for helping me track down the problem. This saved me for some additional pain on what has already been a painful week! If this little nugget helps you too, feel free to comment and say thanks to Lorna with me!