Yii On Osx & Xampp Or Mamp

So here’s the issues I ran into (since I seem to be on the same book and on a Mac as well), I’m using XAMPP but I tried MAMP and had the same issue. I thought I would share what I had done to resolve my issue to hopefully

I had 3 main issues.

Note, I am on a MacBook Pro 15" w/ Retina Display on OSX 10.8.4

Issue One: PHP/HTML Output when trying to run yiic shell

Resolution: This has to do with the yiic shell having to make sure your php.ini time zone is set right, unfortunately, systems like MAMP and even XAMPP have a habit of wanting to enforce your time zone based on system settings (and using Mac nomenclatur), this does not always match up to the date.timezone’s function syntax that PHP offers, in order to resolve this, add the following to the top of the main.php file below the opening PHP line

// Fix for server incompatibilities


You can always edit it based on your time zone, but I would just recommend keeping UTC and handling proper time zones later.

Issue Two: Can not find file issue when attempting to run Yii::app()->db->connectionString;

Resolution: For some reason yii and PHP want to look for the mysql.sock in places it is not, you have to enforce it to look where it needs to look.

Also, sometimes “localhost” doesn’t work properly, so you should use your “home” IP, most commonly (even if on a network, unless you’ve manually set it otherwise). This will make your connection string look something like the following.

'connectionString' => 'mysql:host=;dbname=DBNAME;unix_socket=/Applications/XAMPP/xamppfiles/var/mysql/mysql.sock',

Your mysql.sock may be in a different location, check a phpinfo(); page to find out, both XAMPP and MAMP have a control panel with a phpinfo() link page on them.

Issue Three: Access denied for user * on * (where * can be anything)

Resolution:This one is the most silly of them all, as I set up my user in MySQL I set the user to accept all incoming locations (a.k.a. %). Note that I really should not have done this anyway as it is a security risk, but I was being lazy.

It seems access denied is an inevitability on both MAMP and XAMPP with this.

Remove % access (possibly even remove your user), and make sure they are only set to "local" or "localhost". It will then be able to connect.

I hope this helps some other Yii mac developers! (It took me some time to get it all sorted out, including looking through complete threads and answers), I figured I’d make a post about it specifically.