MAMP / PHP.INI: “date.timezone” setting in phpinfo() shows “no value” even though the value is set in php.ini

可紊 提交于 2019-12-05 02:58:20

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.

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.

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
Nick Matantsev

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!

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!!!

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.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!