I've recently installed PHPUnit on a Mac (10.8.3) (running PHP 5.4.7). When I attempt to a run a test phpunit testfile.php for example, I receive:
Warning: require_once(File/Iterator/Autoload.php): failed to open stream: No such file or
directory in /Users/myusername/pear/share/pear/PHPUnit/Autoload.php on line 64
Fatal error: require_once(): Failed opening required 'File/Iterator/Autoload.php'
(include_path='.:') in /Users/myusername/pear/share/pear/PHPUnit/Autoload.php on line 64
The file, /Users/myusername/pear/share/pear/File/Iterator/Autoload.php exists.
php.ini correctly lists the pear directories in the include path:
.:/php/includes:/usr/local/apache/lib/php:/Users/myusername/pear/share/pear/
Yet when I var_dump(get_include_path()); inside of the PHPUnit/Autoload.php file, it prints .: as if it's empty.
Dumping the value of php_ini_loaded_file instead, simply returns false.
Using php -i |grep php\.ini and php --ini only show one php.ini being used/loaded:
Configuration File (php.ini) Path => /usr/local/apache/lib
Loaded Configuration File => /usr/local/apache/lib/php.ini
I repeated the var_dumps of the include_path and the loaded_ini_file from a simple test.php file I ran from the command line and they print out the correct info. So something involved with phpunit is not loading the right/any php.ini.
I'm not using any configurations that are different than default - phpunit was just installed on this machine today.
Make sure the php.ini file you are using is the one loaded for cli php. At least on my install of PHP on Linux, I have two php.ini files, one at /etc/php/cgi-php5.4/php.ini, and the other at /etc/php/cli-php5.4/php.ini. If you change the cgi version, it won't by default affect the cli version, and would cause the include path to be empty.
Another place to check is the phpunit.xml file. It has a section to specify the include path. See here for options available. I'm not sure why phpunit would reset the path but this might be a way to solve the issue.
The solution was:
After running
`pear config-get php_bin` -i | grep -E Configuration\ File\|include_path
It showed that Pear was using a different ini path than php-cli was:
Configuration File (php.ini) Path => /etc
Loaded Configuration File => (none)
include_path => .: => .:
Turns out, Pear had been configured by the original/default Mac OS copy of PHP, not by the custom version I had installed later on.
A quick fix that may not be best long-term was to symlink the ini file it was trying to find:
sudo ln -s /usr/local/apache/lib/php.ini /etc/php.ini
Afterwards, phpunit FakeTest commands are work, and the tests run.
Eventually I need to re-install/re-configure Pear to work with the version of php I've loaded.
Related
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.
I cannot create a bundle. I'm getting "Checking that the bundle is autoloaded: FAILED" which never used to happen before until now. Steps below always worked until today.
Any solutions?
To setup Symfony2:
I downloaded: Symfony_Standard_Vendors_2.4.5.zip
I unzipped under: /var/www/html/local/three. three is the main folder.
I set the permissions:
desktop#ubuntu:/var/www/html/local/three$ sudo chown desktop -R app/logs
desktop#ubuntu:/var/www/html/local/three$ sudo chown desktop -R app/cache
desktop#ubuntu:/var/www/html/local/three$ sudo chmod 777 -R app/cache
desktop#ubuntu:/var/www/html/local/three$ sudo chmod 777 -R app/logs
This URL works fine: http://localhost/local/three/web/app_dev.php
To create my bundle:
desktop#ubuntu:/var/www/html/local/three$ php app/console generate:bundle --namespace=Myblog/PublicBundle
Welcome to the Symfony2 bundle generator
In your code, a bundle is often referenced by its name. It can be the
concatenation of all namespace parts but it's really up to you to come
up with a unique name (a good practice is to start with the vendor name).
Based on the namespace, we suggest MyblogPublicBundle.
Bundle name [MyblogPublicBundle]:
The bundle can be generated anywhere. The suggested default directory uses
the standard conventions.
Target directory [/var/www/html/local/three/app/cache/dev/../src]:
Determine the format to use for the generated configuration.
Configuration format (yml, xml, php, or annotation): yml
To help you get started faster, the command can generate some
code snippets for you.
Do you want to generate the whole directory structure [no]? yes
Summary before generation
You are going to generate a "Myblog\PublicBundle\MyblogPublicBundle" bundle
in "/var/www/html/local/three/app/cache/dev/../src/" using the "yml" format.
Do you confirm generation [yes]? yes
Bundle generation
Generating the bundle code: OK
Checking that the bundle is autoloaded: FAILED
Confirm automatic update of your Kernel [yes]? yes
Enabling the bundle inside the Kernel: OK
Confirm automatic update of the Routing [yes]? yes
Importing the bundle routing resource: OK
The command was not able to configure everything automatically.
You must do the following changes manually.
- Edit the composer.json file and register the bundle
namespace in the "autoload" section:
Solved:
Problem is to do with line:
Target directory [/var/www/html/local/three/app/cache/dev/../src]:
I don't understand why it is suggesting cache path. Old days it was always automatically suggesting src directory instead. I've checked my logs that's why I know. Anyway change it to:
/var/www/html/local/three/src
Done!
This is a known issue now, I guess it will be fixed on the next version
https://github.com/symfony/symfony/issues/10972
https://github.com/symfony/symfony/pull/10999
https://github.com/symfony/symfony-standard/issues/659
for now when the generate:bundle displays this:
The bundle can be generated anywhere. The suggested default directory
uses the standard conventions.
Target directory:
-- /type/your/directory/src here
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
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
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