Symfony2 on MAMP: date.timezone warning

Discuss installing Symfony 2 here

Moderators: tiagojsag, dcobalt

Symfony2 on MAMP: date.timezone warning

Postby Dimitri Vorontzov » Wed Nov 28, 2012 11:21 pm

I'm trying to configure Symfony2 framework in MAMP.

In the (correctly chosen) php.ini I have correctly set date.timezone value as America/New_York, however, it appears that MAMP somehow overrides the setting and uses system time instead, based on what's written in the php.ini file:

[Date]
; Defines the default timezone used by the date functions
; Will be changed by MAMP to system timezone
date.timezone = "America/New_York"

As a result, Symphony's config.php page sends this warning:

Warning: date_default_timezone_get() [function.date-default-timezone-get]: 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/htdocs/Symfony/app/SymfonyRequirements.php on line 434

Symfony fails to show start page until this has been fixed. What would be the solution?

Thank you!
Dimitri Vorontzov
Junior Member
 
Posts: 10
Joined: Wed Nov 28, 2012 11:17 pm

Re: Symfony2 on MAMP: date.timezone warning

Postby tiagojsag » Thu Nov 29, 2012 11:20 am

Hi,

Sorry I can't help you, I don't use mac for dev. If you haven't yet, maybe you should also take a look at the MAMP foruns and support page, see if anyone else got the same problem

cheers
Tiago Garcia
@tiagojsag

Core Web Developer @ Shopware
http://www.shopware.de
User avatar
tiagojsag
Faithful Member
 
Posts: 885
Joined: Wed Aug 10, 2011 4:58 pm

Re: Symfony2 on MAMP: date.timezone warning

Postby dreipunktnull » Sat Dec 01, 2012 9:01 am

Is it MAMP or MAMP pro?
User avatar
dreipunktnull
Faithful Member
 
Posts: 1244
Joined: Fri Jun 17, 2011 10:03 am
Location: Germany

Re: Symfony2 on MAMP: date.timezone warning

Postby Dimitri Vorontzov » Sun Dec 02, 2012 5:17 am

It's MAMP regular, not pro.

Would be grateful for your help!
Dimitri Vorontzov
Junior Member
 
Posts: 10
Joined: Wed Nov 28, 2012 11:17 pm

Re: Symfony2 on MAMP: date.timezone warning

Postby dreipunktnull » Sun Dec 02, 2012 5:05 pm

If it was Pro I'd have an idea but in this case unfortunately not. Are you 100% sure it is the correct php.ini? What does
Code: Select all
php --ini
reveal?
User avatar
dreipunktnull
Faithful Member
 
Posts: 1244
Joined: Fri Jun 17, 2011 10:03 am
Location: Germany

Re: Symfony2 on MAMP: date.timezone warning

Postby Dimitri Vorontzov » Mon Dec 03, 2012 5:30 am

Sorry, could you expand on this a bit:

CODE: SELECT ALL
php --ini

How do I run this command in Terminal? It throws an error when I simply paste it in Terminal, ditto with ; .
Dimitri Vorontzov
Junior Member
 
Posts: 10
Joined: Wed Nov 28, 2012 11:17 pm

Re: Symfony2 on MAMP: date.timezone warning

Postby dreipunktnull » Mon Dec 03, 2012 11:06 am

So php is not in your path obviously. How do you use Symfony's console then?

BTW: For serious coding I always recommend Liip's PHP stack for OSX which creates a perfect dev environment. MAMP is OK but it installs in the Applications folder which makes all paths kind of unusable. In combination with homebrew (to install MySQL and the like) you'll get a very powerful and puristic environment.
User avatar
dreipunktnull
Faithful Member
 
Posts: 1244
Joined: Fri Jun 17, 2011 10:03 am
Location: Germany

Re: Symfony2 on MAMP: date.timezone warning

Postby Dimitri Vorontzov » Tue Dec 04, 2012 3:57 am

I don't use Symfony console: I still can't get it to work – it's not working until I fix the issue I'm describing here. once I figure out how to fix the issue, I will be using it. That's kinda why I'm here. :-)

Forgive me for asking this again, but I'm still not certain how to use this bit of code that you're suggested:

CODE: SELECT ALL
php --ini

Could you elaborate on it please?

I am copying and pasting it in the Terminal, and getting the following error:

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'CODE: SELECT ALL
php --ini' at line 1


Clearly, I'm doing something wrong. Your suggestions would be appreciated, as always!

P.S. Thanks for the recommendation of PHP stack for OSX. If I fail to learn what makes Symfony act up in MAMP, I will try the PHP stack you've suggested! Thank you again for this.
Dimitri Vorontzov
Junior Member
 
Posts: 10
Joined: Wed Nov 28, 2012 11:17 pm

Re: Symfony2 on MAMP: date.timezone warning

Postby dreipunktnull » Tue Dec 04, 2012 10:24 am

Hm. Simply open the terminal, type "php --ini" (without the quotes of course) and hit enter. To check if the php executable is in your path type "which php" and hit enter.
User avatar
dreipunktnull
Faithful Member
 
Posts: 1244
Joined: Fri Jun 17, 2011 10:03 am
Location: Germany

Re: Symfony2 on MAMP: date.timezone warning

Postby Dimitri Vorontzov » Tue Dec 04, 2012 7:22 pm

Thank you for clearing this up, 3.0!

So, following your instructions, I opened the Terminal, and typed this:

php --ini;


Hit the Return, got this in reply:

Configuration File (php.ini) Path: /etc
Loaded Configuration File: (none)
Scan for additional .ini files in: (none)
Additional .ini files parsed: (none)


And yet, I've been using PHP on that computer for the last couple of months, with MAMP. What gives?
Dimitri Vorontzov
Junior Member
 
Posts: 10
Joined: Wed Nov 28, 2012 11:17 pm

Re: Symfony2 on MAMP: date.timezone warning

Postby dreipunktnull » Tue Dec 04, 2012 8:09 pm

That's what I expected to see ;) There are at least two different php executables and php.ini files on your system. The one that is shipped with OSX and MAMP's. I suggest you symlink MAMP's php executable to /usr/bin:

Code: Select all
sudo mv /usr/bin/php /usr/bin/php.bak
sudo ln -s /Applications/MAMP/bin/php/php5.x.x/bin/php /usr/bin/php

Adjust the path to MAMP to the correct version (5.x.x). This should do the trick. Or better use Liip's PHP stack to avoid this very problem :D
User avatar
dreipunktnull
Faithful Member
 
Posts: 1244
Joined: Fri Jun 17, 2011 10:03 am
Location: Germany

Re: Symfony2 on MAMP: date.timezone warning

Postby Dimitri Vorontzov » Tue Dec 04, 2012 8:20 pm

Do I understand you correctly that executing this code would switch MAMP to work with PHP provided with the operating system?

If yes, would I really want that? The computer is about 6 years old...
Dimitri Vorontzov
Junior Member
 
Posts: 10
Joined: Wed Nov 28, 2012 11:17 pm

Re: Symfony2 on MAMP: date.timezone warning

Postby dreipunktnull » Tue Dec 04, 2012 9:53 pm

No, it's the other way round. MAMP's php would become the default. BTW: How is that related to the machine's age?
User avatar
dreipunktnull
Faithful Member
 
Posts: 1244
Joined: Fri Jun 17, 2011 10:03 am
Location: Germany

Re: Symfony2 on MAMP: date.timezone warning

Postby Dimitri Vorontzov » Tue Dec 04, 2012 10:10 pm

Aha, great!

Well, if the machine's OS is six years old, so is its PHP, no?
Dimitri Vorontzov
Junior Member
 
Posts: 10
Joined: Wed Nov 28, 2012 11:17 pm

Re: Symfony2 on MAMP: date.timezone warning

Postby Dimitri Vorontzov » Wed Dec 05, 2012 4:02 am

Ran the two commands, no luck: getting the same error message, Symfony refuses to work.

Any other suggestions on how to get it to work with MAMP?
Dimitri Vorontzov
Junior Member
 
Posts: 10
Joined: Wed Nov 28, 2012 11:17 pm

Re: Symfony2 on MAMP: date.timezone warning

Postby dreipunktnull » Thu Dec 06, 2012 1:03 pm

You can tell php which ini to use with the --php-ini option. If you don't want to add this everytime you can create an alias including the option:
Code: Select all
alias php="php --php-ini /path/to/php.ini"

Besides that I recommend to ask in the proper MAMP forum (or switch to a better solution as posted before) because this is not really Symfony related TBH.
User avatar
dreipunktnull
Faithful Member
 
Posts: 1244
Joined: Fri Jun 17, 2011 10:03 am
Location: Germany

Re: Symfony2 on MAMP: date.timezone warning

Postby Dimitri Vorontzov » Thu Dec 06, 2012 7:02 pm

Thank you very much for trying to help. The issue I'm struggling with (getting Symfony to run on MAMP) hadn't been resolved, unfortunately, but you've been most helpful in suggesting the alternative, and I appreciate that. – Dimitri Vorontzov
Dimitri Vorontzov
Junior Member
 
Posts: 10
Joined: Wed Nov 28, 2012 11:17 pm

Re: Symfony2 on MAMP: date.timezone warning

Postby Dimitri Vorontzov » Mon Dec 10, 2012 11:28 pm

Found the solution. As it almost always happens, simple "duct tape" solutions tend to be the most workable.

Here's what I did to fix the issue:

1. Opened the config.php inside the 'web' directory in Symfony, and added at the top of the script, right after the opening php tag, the following bit of code:

// Set the default timezone:
date_default_timezone_set ('America/New_York');


2. Opened the app_dev.php inside the 'web' directory in Symfony, and added the same bit of code, also at the top of the script immediately after the opening php tag.

After I saved both files and ran them in the browser, the warning message disappeared and I was able to use Symfony. I assume, I may have to add the date.timezone manually to a few more scripts inside Symfony whenever the warning message pops up. The better solution would have been to figure out why MAMP overrides the default setting, which is something I'm still trying to do, but at least using this Symfony-specific solution I could get the work started.
Dimitri Vorontzov
Junior Member
 
Posts: 10
Joined: Wed Nov 28, 2012 11:17 pm

Re: Symfony2 on MAMP: date.timezone warning

Postby Luco » Wed Jan 30, 2013 1:27 pm

tried that, didn't work. I still can't get past Symfony's "welcome" page. thing is, I'm in a shared host and I can't set the timezone using php.ini.

I mean, why on Earth does Symfony need this changed there? is that meant to exclude shared host users on purpose? wouldn't it be better to address that gaping security hole with the cache folder permissions, since shared host users are a majority anyway?

sorry for my tone, but I've been trying to get this framework going for the past three days with no success. I'm tearing my hair out. all I can find is how to set up Symfony using localhost and I'm tired of it.

I set up CakePHP in the blink of an eye, and suspect Zend will be just as easy. I have to report back to my boss with alternatives to Drupal (which I'd much rather not leave behind, but it's not my call).

so anyway... if anyone knows a workaround to this annoying timezone requirement, please let me know. I'd really appreciate it.
Luco
Junior Member
 
Posts: 3
Joined: Tue Jan 29, 2013 3:51 pm

Re: Symfony2 on MAMP: date.timezone warning

Postby dreipunktnull » Wed Jan 30, 2013 7:14 pm

Depending on your shared host it is also possible to set it with

Code: Select all
php_value date.timezone "Europe/Berlin"

in a .htaccess file.

Luco wrote:I mean, why on Earth does Symfony need this changed there? is that meant to exclude shared host users on purpose? wouldn't it be better to address that gaping security hole with the cache folder permissions, since shared host users are a majority anyway?
It's not a security hole but a E_WARNING message from php under the hood. Depending on the error_reporting settings you will see this warning with each and every framework out there unless not set. I don't understand though why the previous posted fix doesn't work for you as it is has to.
User avatar
dreipunktnull
Faithful Member
 
Posts: 1244
Joined: Fri Jun 17, 2011 10:03 am
Location: Germany

Re: Symfony2 on MAMP: date.timezone warning

Postby Luco » Thu Jan 31, 2013 1:59 am

thanks for the support.

I tried the solution you provided, but the server returned a 500 Internal Server Error message.

I've been alerted that my webhost - Hostgator - won't allow me to change server time, no matter what.
Luco
Junior Member
 
Posts: 3
Joined: Tue Jan 29, 2013 3:51 pm


Return to Installation and setup

Who is online

Users browsing this forum: Google [Bot] and 1 guest