Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting PHP CLI timezone

Tags:

nitrousio

I have added my timezone to date.timezone in ~/.parts/etc/php5/php.ini but my PHP script that I execute on the console keep saying

We selected the timezone 'UTC' for now, 
but please set date.timezone to select your timezone.

Is there any solution for this?

UPDATES:

  1. I found out that PHP on Apache recognize my setting in php.ini but PHP command line is not.
  2. Somehow now it's working. I accept @carousel answer because I think it is informative for others.
like image 468
William Notowidagdo Avatar asked May 03 '26 04:05

William Notowidagdo


2 Answers

Try with:

date_default_timezone_set 

method, which is used by all date/time functions.

UPDATE:

With PHP date/time settings you have to be very explicit, and don't rely on some predefined settings.

like image 155
Miroslav Trninic Avatar answered May 07 '26 10:05

Miroslav Trninic


You can use the -c option when using php cli to specify a php.ini file to use.

For my Nitrous box, I use:

php -c /home/action/.parts/etc/php5/php.ini yourcommandshere
like image 33
C. Lee Avatar answered May 07 '26 10:05

C. Lee



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!