MAMP php.ini date.timezone setting

November 8th, 2013

Running a recent local install of MAMP on my OSX 10.8.4, I ran into the following problem when running some PHP functions using the date method:

WARNING: [2] date(): It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'America/Los_Angeles' for 'PST/-8.0/no DST' instead in /xxxx/xxxxx/xxxx.php on line # 562

Depending on how your php error handling is setup, this can either give a warning or if your error handling is strict, give you a fatal exception error.  In either case, here is how you can fix it:

1.  As mentioned in the error message, you can manually set the timezone via a php method called date_default_timezone_set().  You can google to see how this is used, and depending on your framework (or not) where you should place it.  

2.  I use the "America/Los_Angeles" time zone in this example, change it to match yours:  Add date.timezone = "America/Los_Angeles" to your php.ini file.  For MAMP, use the php_info() method on any page to display the php settings and location for the php.ini being used.   Using your favorite editor, go to that file and find the line containing  "date.timezone = "XXXXX/XXXXX" -- All you do is replace the XXXX/XXXX with your own timezone.   

Now this is the tricky part: You will notice that it says "; Will be changed by MAMP to system timezone" on the line right above.  Well for some reason, MAMP decides to ignore this setting in this php file and use whatever is being set in the default php.ini instead, which has nothing to do with MAMP and more to do with the local php installation on MAC OSX.   

So now go and edit the default php.ini for the system.  

1. Go to the "/private/etc/" folder.   
2. Now look for php.ini.
3. If php.ini is not there, then copy the php.ini.default which should be there (cp php.ini.default php.ini)
4. Now edit your php.ini (sudo vi php.ini)
5. Find the line containing "; 
6. Remove the commenter ; in front and add your timezone.  In my case it was -- date.timezone = "America/Los_Angeles"
7. Save and exit.
8. Restart MAMP (Stop and Start).

You should no longer be receiving the error message.  

Hope that helps!