MAMP / Symfony: MAMP overrides date.timezone setting from php.ini, Symfony fails - symfony

I'm trying to configure Symfony2 framework in MAMP.
In php.ini I have correctly set date.timezone, however, it appears that MAMP somehow overrides the setting and uses system time instead.
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!

Check if there are two php.ini files in your system. You may be adding the date.timezone line in one of them but MAMP is using the other.
If that doesn´t work for you try adding the following line at the beginning of your web/app.php and web/app_dev.php files, (as the error message suggests):
date_default_timezone_get('Europe/London');
Hope it helps.

I am still working on figuring out why and how MAMP overrides the php.ini date.timezone settings, however, I have found the quick fix solution within Symfony php files, which solved the problem, at least for now.
I added the following bit of code:
date_default_timezone_set ('America/New_York');
-- at the top of Symfony's config.php and app_dev.php files, immediately after the opening php tag, at the very top of the script. This removed the warning message and got Symfony working on MAMP.
I foresee having to add the same code to some other php files inside Symfony as I keep hacking at it, which shouldn't be a problem. Or I may figure out how to override MAMP's overriding.
Still, this is a workable solution.

copy
cp /etc/php.ini.default /etc/php.ini
change permisions
chmod -R 775 /etc/php.ini
edit
sudo vi /etc/php.ini
search for date.timezone and change it to (example):
date.timezone = "Europe/London"

Are you in command line? cause command line may get a different php.ini than MAMP.
To see which is your php.ini from command line, you can do:
$ php -i | grep 'Configuration File'
(reference: How to find the php.ini file used by the command line?)
Try to set "date.timezone" in "/etc/php.ini", or wherever it says is your php.ini file.
You can also change your php.ini file:
$ php -help | grep "php.ini"
-c <path>|<file> Look for php.ini file in this directory
Like...
$ php -c /Applications/MAMP/conf/php5.5.14/php.ini ...
For example:
$ php -c /Applications/MAMP/conf/php5.5.14/php.ini -i | grep 'Configuration File'

If your problem is how to make changes in php.ini file on MAMP PRO, try to edit the template.
File -> Edit Template
You can see in MAMP manual, page 24
More info is here

In MAMP 3.0.1 the php.ini file in the corresponding php folder version you are using has the value date.timezone declared after a semicolon which turns it into a comment rather than a command. In the php.ini in C:\MAMP\conf\php5.5.12 (or your php version) delete the semicolon in line 703 and define your local time according to guidelines http://php.net/manual/en/timezones.php.
Hope this works for you :)

Like Pedro Luz mentioned, you have to set the timezone in your mac's php.ini and not MAMP's.
Don't forget to restart your mac's apache:
sudo /usr/sbin/apachectl restart
This solution worked for me:
[OK]
Your system is ready to run Symfony2 projects

Related

I have a Windows hosting and I need to use Wordpress on it

I know that this hosting is not the best for Wordpress but unfortunately I can't change it anymore, whenever I try to install a plugin it shows the error "No working transports found" I researched how to fix it and everywhere it shows me to uncomment a php line. ini but I need to fix this on Windows, can anyone help me?
Yes, you will need to uncomment a line in php.ini
You need to:
(1) find the location of php.ini in your Windows server,
(2) open the php.ini file, search for ;extension=openssl and uncomment that line by removing the ;
Note: If you're running a PHP version older than 7.2.0, the extension's file name may be extension=php_openssl.dll instead of ;extension=openssl in the php.ini file.
(3) if you’re running PHP as an Apache module, restart the Apache server to make sure the changes are reflected.
How to Find the Location of php.ini in Your Windows Server:
To find the location of php.ini in your Windows installation, you will need to run the phpinfo() function.
Follow the steps below:
(1) Create an empty file called phpinfo.php and place it in your document root,
(2) Edit the file and place the following content in it:
<?php
phpinfo();
?>
(3) Save and close the file.
(4) Open the file in your browser and you will see the output of phpinfo().
(5) Search for Loaded Configuration File and you will find the location of your php.ini file.
Once you have found the php.ini file, you may then proceed to open it and uncomment ;extension=openssl.

Composer installation error - file is not within the allowed path

I am trying to install composer on windows (symfony 2 project). The problem is that I always get some strage errors - that a couple of files are not in the allowed path.
I've tried a couple of methods to install compsoer:
Downloading raw composer.phar file, throwing it into the symfony2 root folder and running composer installation command. It gives me an error that usr/.../composer/.htaccess is not within the allowed path
php -r "path" gives similar results as above, but with more "not in the allowed path" errors
Windows installer - it throws an error that the installer couldn't execute php.exe file, no idea why.
What's wrong?
Adjust open_basedir in your php.ini to include the path to your project and the other paths that composer tries to load from/write to. The variable accepts multiple paths separated by : (unix) or ; (windows).
open_basedir = "/home/sites/yoursites/:/tmp/:/"
... or remove the restriction completely from php.ini.
; remove open_basedir completely ...
; <nothing here>
; ... comment it out like this ...
; open_basedir = "..."
; ... or set it to an empty value like this ...
open_basedir =
You can find the location of the correct php.ini for the CLI sapi with:
php --ini
First, you should make sure that the path of php.exe is in your ENV (Environment variable);
Second, if composer's windows installer can't install, just try to use "Run With Administrator Permission", and if it also does not work, just comment me your error.

Exec with PHP-FPM on nginx (under chroot) returns nothing

I've created a nginx server in a chroot at /srv/http with php-fpm. Both services use the http user and it works fine. The problem comes when I try to run an exec command such as
echo shell_exec('/usr/bin/ls');
There is no output at all on the web page or in the errors. I've also tried
error_log(shell_exec('/usr/bin/ls');
and still nothing.
Things I've Tried or Know:
safe mode off
exec enabled
user is http (using phpinfo())
display_errors = on
error_reporting = E_ALL
sudo /usr/bin/chroot --userspec=http:http /srv/http ls works fine
Can create file and read from it using file_puts_content and fopen/fread
tried shell_exec,exec,system, and passthrough - nothing worked
tried appending 2>&1 to the end of the command and nothing
I've copied all the executables and libraries necessary over
all libraries, binaries, and everything under /srv/http/www (where the webpages are) have executable and read permissions
doc_root is www
As far as I know, everything works in the chroot, except shell commands through php-fpm. Anyone have any idea where I went wrong and how to fix it?
This may sound stupid but you must just copy /bin/sh (not /bin/bash!) to you chroot.
For example see this question: How do I change the shell for php's exec()
If you chroot to some directory, then this directory becomes the root for all your PHP scripts. That means, that if you execute /usr/bin/ls from within PHP, it will try to exectue /srv/http/usr/bin/ls instead.
You can copy the executable to that directory - but be aware of the security implications. If you copy critical system executables into the chrooted directory you basically bypass the positive effects of chroot.
I get no output for
echo shell_exec('/usr/bin/ls');
either. Presumably because ls isn't a file but a built-in command. Running:
echo shell_exec('ls');
outputs:
css demos favicon.ico images js path.php robots.txt routing.php test
which is the list of files in my root directory for the site.

date_default_timezone_get(): It is not safe to rely on the system's timezone settings

Can anyone tell me why am I getting this error when running app/console in a brand new formatted macbook with the latest MAMP installed ?
Warning: 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 'Europe/Helsinki' for 'EEST/3.0/DST' instead in /../Logger.php line 112
I have checked the path of php.ini and marked out the date.timezone = "Europe/Athens"
Also restarted MAMP/apache several times.
At AppKernel.php write:
public function init() {
date_default_timezone_set( 'Europe/Lisbon' );
parent::init();
}
Since init() is deprecated (and will be remove in Symfony2 3.0) it is recommended to move the code in the constructor as in the following exemple:
public function __construct($environment, $debug) {
parent::__construct($environment, $debug);
// get rid of Warning: date_default_timezone_get(): It is not safe to rely on the system's timezone
date_default_timezone_set( 'Europe/Paris' );
}
Default php.ini in OS X is located at:
/private/etc/php.ini
Anyway, you'll can either tell CLI php to load MAMP settings, or use an alias of MAMP command itself.
You don't edit the good php.ini file
You can get a full phpinfo() using :
php -i
And, in there, there is the php.ini file used :
$ php -i | grep 'Configuration File'
Configuration File (php.ini) Path => /etc
Loaded Configuration File => /etc/php.ini
I had the same problem, and it's true there is a command line, and MAMP/Native Mac PHP service running on Yosemite, and while I was trying to follow the directions on this page non of them seemed to work for me.
When I ran php command:
$ php -i | grep 'Configuration File'
Configuration File (php.ini) Path => /etc
Loaded Configuration File => <em>(Blank)</em>
I realized that the php.ini that the CLI was using, was actually php.ini.default file.
I created a symbolic link to that file as the php.ini and everything worked.
My-MacPro:/etc/$ ln -s php.ini.default php.ini
I did follow your answers, but in my case none of them worked. I decided to go change the
date_default_timezone_get()
in the logger.php file.
I replaced with my timezone setting ("Europe/Berlin"), and all went well !
Old school solution but still a solution.
I had the exact same problem with my SF2 installation.
To fix this just go into your php.ini file at /etc/php.ini and change your file to look like this (adjust your timezone to suit your local timezone):
;;;;;;;;;;;;;;;;;;; ; Module Settings ; ;;;;;;;;;;;;;;;;;;;
[Date]
; Defines the default timezone used by the date functions
; http://www.php.net/manual/en/datetime.configuration.php#ini.date.timezone
date.timezone = Europe/London
Your default php.in in Mac OSX is located at /etc/php.ini which is exactly the same than the /private/etc/php.ini file.
You should know that you have the possibility of using two php version running in parallel. I had this issue 'cause I was using the native mac osx php, however I had to install a php package through homebrew, then I got the other version of php through homebrew. though I had the time zone already configured in my php.ini file at /etc/php.ini, I still had the same problem, so I run:
php -i | grep 'Configuration File'
in order to configure the correct file, so I got:
Configuration File (php.ini) Path => /usr/local/etc/php/5.3
Loaded Configuration File => /usr/local/etc/php/5.3/php.ini
PHP Warning: Unknown: 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/Buenos_Aires' for 'ART/-3.0/no DST' instead in Unknown on line 0
Then I knew I had to edit the /usr/local/etc/php/5.3/php.ini file.
After that, It all went right. I had not that issue any more.
I hope it helps you to solve that.
Usually, there are separate php.ini files for CLI and Apache. Make sure you've edited the needed one.
By default Mac uses in the console the PHP located at:
/private/etc/php.ini
You should use this one because MAMP always unset the timezone variable and you would always get that error.
I had a similar problem on OS X 10.9.
The problem in my case was the absence of a php.ini file in /etc.
I solved the problem by creating that php.ini file with the contents:
date.timezone = Europe/Athens

can't find php.ini in the etc folder?

I have root access to my dedicated server, and when I run phpinfo() it says my php.ini file is in the etc/ directory, using ssh i can't seem to find it there, i don't know where i can find it thanks :))
This may not be a question for SO, but here's a couple potential solutions, all depending on your distro of course:
locate php.ini
Should give you the directory that php.ini resides in (You may need to do updatedb first)
Otherwise, there's always find.
find / -name "php.ini"
As described in the PEAR installation manual, you can discover the ini files that PHP uses by running
$ php --ini
Configuration File (php.ini) Path: /etc/php/cli-php5
Loaded Configuration File: /etc/php/cli-php5/php.ini
Scan for additional .ini files in: /etc/php/cli-php5/ext-active
Additional .ini files parsed: /etc/php/cli-php5/ext-active/php_gtk2.ini,
/etc/php/cli-php5/ext-active/xdebug.ini
a quick command to see which php.ini file you're using via command line / terminal
php -i | grep /php.ini
or
php --ini | grep /php.ini

Resources