MAMP / PHP.INI: "date.timezone" setting in phpinfo() shows "no value" even though the value is set in php.ini
Asked Answered
B

7

9

Greetings to StackOverflow gurus!

Here's the issue I'm struggling with.

I run phpinfo() in MAMP, and the resulting table shows "no value" in both columns of the date.timezone row.

Additionally, the page displays the following:

Warning: phpinfo() [function.phpinfo]: 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/New_York' for 'EST/-5.0/no DST' instead in /Applications/MAMP/bin/mamp/phpinfo.php

In thr php.ini file, however, the setting is as follows:

date.timezone = America/New_York

I foresee the recommendation to check that the path to php.ini is correct - I've already done that, and the path is indeed correct: /Applications/MAMP/conf/php5.3/php.ini - that IS the file that has the value set.

How can I remedy the issue? What am I missing?

Would be grateful for help from a knowledgeable person.

Berg answered 10/12, 2012 at 4:36 Comment(4)
If you have recently set the timezone in the ini file, have you restarted the server as well? This is necessary for the changes to take effect.Eleaseeleatic
Have you made sure that you're using the right php.i--- oh. Damn. You're sure? That's usually the culprit. Did you change the value, or was it like that to begin with? If you changed it, did you restart the service?Extrabold
@fireeyedboy Yes, turned the servers off before making the change, turned them on after saving php.ini.Berg
@Extrabold Correct php.ini, changed the values a few times just to see if anything changes, restart the servers every time. Still, "no value" and the warning.Berg
S
6

If the timezone is set correctly in the pertinent php.ini file and you are still getting this message, you can try setting your TZ environment variable. Edit your .profile to add the following line (sub in your own timezone string):

export TZ="America/New_York"

Not sure why (a) MAMP overrides your php.ini setting, (b) PHP doesn't throw a notice/warning when using the TZ env variable even though it says it will, but this solution worked for me using MAMP 2.0.5 with PHP 5.3.6.

Stilbestrol answered 31/1, 2013 at 4:32 Comment(1)
Make sure you are editing the correct php.ini file, depending on your setup there could be more than one! Use "php -i | grep php.ini" to know for sureSanskritic
G
11

I know I might be a little late in answering this but I see on a few sites that you are asking about setting the correct timezone in MAMP.

It should be noted that there are two locations for a php.ini file for the version of php you are using. MAMP could be loading it from a different path then the one you are editing.

For example, lets say we are using php 5.3. Here are two locations of a php.ini file that could confuse someone on which one to edit.

/Applications/MAMP/bin/php/php5.3/conf/php.ini

You seem to be editing it at this location below:

/Applications/MAMP/conf/php5.3/php.ini

Editing the timezone in the second path did not work for me but editing the one in the first one did. It could be that you are editing the wrong file even though it looks the same. I have tested this on my version. Running <?php phpinfo(); ?> in a php file and checking the path of the php.ini file will always show the correct path.

Also just to point out, using double quotes around the value of date.timezone will work. For example in my php.ini file the following works.

date.timezone = "America/Vancouver"

Also the default value was encapsulated in double quotes as well.

I was also using MAMP version 2.1.1 when testing this out.

Grooms answered 18/8, 2013 at 19:26 Comment(0)
S
6

If the timezone is set correctly in the pertinent php.ini file and you are still getting this message, you can try setting your TZ environment variable. Edit your .profile to add the following line (sub in your own timezone string):

export TZ="America/New_York"

Not sure why (a) MAMP overrides your php.ini setting, (b) PHP doesn't throw a notice/warning when using the TZ env variable even though it says it will, but this solution worked for me using MAMP 2.0.5 with PHP 5.3.6.

Stilbestrol answered 31/1, 2013 at 4:32 Comment(1)
Make sure you are editing the correct php.ini file, depending on your setup there could be more than one! Use "php -i | grep php.ini" to know for sureSanskritic
M
3

Note that there are different versions of PHP in the /Applications/MAMP/conf. You should check which version you are using into the MAMP -> Preferences -> Tab "PHP"

If set to 5.4.4, you must access /Applications/MAMP/conf/php5.4.4/php.ini

@edit

Run in Terminal this:

sed -i '$ a\date.timezone = "America/New_York"' /Application/MAMP/conf/php{5.4.4,5.2.17,5.3.13,5.3.14,5.3.5,5.4.3}/php.ini

or

sed -i 's/date.timezone = "Europe/Berlin"/date.timezone = "America/New_York"/g' /Application/MAMP/conf/php{5.4.4,5.2.17,5.3.13,5.3.14,5.3.5,5.4.3}/php.ini
Mildew answered 10/12, 2012 at 4:48 Comment(9)
Thank you Bruno. Yes, there are different versions, and yes, as I've written in the body of my question, I've triple-checked the path to php.ini, and it's correct. Moreover, the path is indicated in the phpinfo() table, as follwos: Configuration File (php.ini) Path /Applications/MAMP/conf/php5.3 Loaded Configuration File /Applications/MAMP/conf/php5.3/php.iniBerg
you're suggesting a bt of code to run in the Terminal - what would that code do?Berg
Sorry by my error, I'm correcting. Can you run the phpinfo() function in a page and search for the php.ini loaded files? Don't run it in the Terminal, the PHP version is different of Web ServerMildew
Could you rephrase, please? What do you mean by "in a page"?Berg
<?php phpinfo(); ?> Search for php.ini (Ctrl+F)Mildew
Oh, I see. Created test_php.php page containing <?php phpinfo(); ?> code. Not surprisingly, it resulted in the exact copy of the phpinfo table I saw before, including the warning, the missing values, and the already mentioned correct paths to php.ini: Configuration File (php.ini) Path /Applications/MAMP/conf/php5.3 Loaded Configuration File /Applications/MAMP/conf/php5.3/php.iniBerg
Appended th bit of code you've suggested. Restarted the servers. Same warning, same missing values. Would appreciate more ideas!Berg
Oh... Can you update your PHP to 5.4.4? I will post my php.ini. gist.github.com/1b3cad95851046cc0a05 Sorry, I don't have no more idea ):Mildew
Or I can just retire, go someplace warm and never touch a computer again. Alas, neither is the option. It has to be MAMP.Berg
J
3

If this error shows up in the terminal CLI usage of PHP, it might be an issue with native vs MAMP PHP collision.

MacOS X comes with its own PHP version pre-installed and that's what runs in the shell when you type php. MAMP's PHP config is separate from pre-installed PHP config: changing MAMP PHP timezone setting does not affect what you see in CLI - hence the timezone error persists. A quick way to check is to run which php - if you do not see a path starting with /Applications/MAMP/... you need to adjust your environment.

To do that, edit a .profile (or bash RC file) text file and add this line to it:

export PATH="/Applications/MAMP/bin/php5.5.3/bin:$PATH"

Adjust the above path to point to your desired MAMP PHP install. Then run:

. ~/.profile
hash -r

That will apply the PATH change immediately (otherwise you'd need to open a new terminal window to apply changes). The second command is just a bash CLI cache clearing command.

As a final check, run which php to verify which PHP install path is being used. Hope this helps!

Jesseniajessey answered 4/12, 2013 at 21:49 Comment(0)
M
1

In Ubuntu 13.10 using php 5.5.3 open your terminal and do

cd /

sudo find -name php.ini

it shows two files php.ini for me it results:

 ./etc/php5/apache2/php.ini
    ./etc/php5/cli/php.ini

open both files using sudo, I use nano

sudo nano /etc/php5/apache2/php.ini

find and edit this line:

;date.timezone =

and change to:

date.timezone = America/Caracas

Save and close this file and edit another

sudo nano /etc/php5/cli/php.ini

find and edit this line:

;date.timezone =

and change to:

date.timezone = America/Caracas

Save and close and restart apache with

sudo service apache2 restart

It works for me!!!

Moretta answered 2/4, 2015 at 8:45 Comment(0)
C
0

grep -lr "Berlin" * | xargs sed -i .backup -e 's#Europe/Berlin#America/New_York#g'

The command above needed some finesse in my case. This will create backup files as well.

Chime answered 16/8, 2013 at 20:33 Comment(0)
E
0

If use MAMP. Just go to MAMP > bin > php > php[folder_of_used_version] > conf > php.ini. Make tha change as known, for example: date.timezone = "America/Lima". Then, RESTART the mac. You should see the changes after restarting.

Exurbia answered 4/8, 2023 at 9:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.