I have set up PHP 5.3.10 on a RHEL 4 server.
When I ran php -i | grep "Loaded" it returned
Loaded Configuration File => (none)
It's OK with that setup. PHP is working the way we needed it to. I just need to know, if no php.ini is being used, where does PHP get all its settings? Thanks.
Update: I realized this after I hit submit. Sorry, how do I move this to Stack Overflow? -_-
Update 2: Result of php --ini:
Configuration File (php.ini) Path: /usr/local/lib
Loaded Configuration File: (none)
Scan for additional .ini files in: (none)
Additional .ini files parsed: (none)
If there is no php configuration file loaded it just takes the default values. Please check the documentation to have the list of the default values :
http://php.net/manual/en/ini.core.php
It may depend on your server setup.
It could be (depending on PHP version) that the PHP configuration is controlled from within the Apache configuration files:
How to change configuration settings
You can use the phpinfo() function to view your PHP configuration settings (including the config file directory). Create a file called info.php (for example in the folder that is the "DocumentRoot"), and edit the file to contain the following code:
<? phpinfo(); ?>
So, if your domain is:
http://example.com
And your "DocumentRoot" is:
".../www" or ".../public_html"
Place the file in that folder and then using a browser, go to:
http://example.com/info.php
This should show you all the settings.
First of all you got to understand that command line PHP uses another php.ini. And Apache (or NGINX etc.) module uses another php.ini.
You may try use more reliable command: php --ini rather than php -i to make sure it's not loading any configs.
Usually it loads php.ini from /etc/php5
If the command is not showing you anything, so you may try to add that file (/etc/php5/cli/php.ini) manually and check.
In RedHat it may be directly on /etc/ directory.
Related
This is for a Mac OS X. I need to put a line in the php.ini file for PHP 5.6 - however, I have found out from this:
php -r "php_ini_loaded_file();"
That PHP is not using an ini file!
OK, so that was a surprise... How do I either tell PHP to use an ini file, or add the line I would have added in that ini file?
Using php --ini gives me the same thing:
Configuration File (php.ini) Path: /etc
Loaded Configuration File: (none)
Scan for additional .ini files in: (none)
Additional .ini files parsed: (none)
The following worked for me. I typed
php --ini
which also told me that there was no config file, but it DID tell me the default directory was /etc.
So I did a sudo nano /etc/php.ini
and added a comment (starting with a ;) and did php --ini again - and it showed the file was present! Just to be sure, I added some illegal characters, and went back to php --ini which told me there was a parse error.
So it appears you can always add a php.ini file - even if it starts out blank.
You can find the command-line switches in the manual or with the help switch:
php -h
I believe you want one of these:
-c <path>|<file> Look for php.ini file in this directory
-d foo[=bar] Define INI entry foo with value 'bar'
Otherwise, PHP will search for the php.ini file according to the documented rules. I understand that CLI interface makes use of the PHPRC environment variable if it exists.
I'm currently working on a website. I used the host's control panel to activate several php modules. Now when I try to use them it returns
Fatal error: Class '...' not found
I checked phpinfo() and the classes appear there, but when I do php -m, they are missing. The server uses Nginx.
What can be the problem and how can I fix it?
Your PHP web installation and your PHP cli installation can be two completely seperate things, and hence they usually have their own ini configuration files.
As per your comment, this is the output you get from your CLI phpinfo:
Loaded Configuration File: (none)
Scan for additional .ini files in: /usr/opt/php56/etc/php
Additional .ini files parsed: (none)
As you can see there's no "Loaded Configuration File". As per this post you can specify what ini file to load when running cli scripts.
Since your regular web installation says:
Loaded Configuration File /home/a2869511/etc/php.ini
Then you can automatically have your CLI program execute with the same ini file:
php --with-config-file-path=/home/a2869511/etc/php.ini script.php
That said, I would recommend that you take a copy of the ini file and place it where your cli application is looking for ini files, which is in /usr/opt/php56/etc/php ("Scan for additional .ini files in").
So the short solution would be to do the following copy:
cp /home/a2869511/etc/php.ini /usr/opt/php56/etc/php/php.ini
I installed MAMP for windows
I have this error since several hours...
[Symfony\Component\Debug\Exception\ContextErrorException]
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 me
thods and you are still getting this warning, you most likely misspelled th
e timezone identifier. We selected the timezone 'UTC' for now, but please s
et date.timezone to select your timezone.
In the php.ini concerned (C:/MAMP/conf/php5.5.19/php.ini), I changed the line DATE like this:
[Date]
; Defines the default timezone used by the date functions
date.timezone = "Europe/Paris"
And in my phpinfo(), the path loaded is :
Loaded Configuration File C:\MAMP\conf\php5.5.19\php.ini
When I do in the consol the command php --ini I have this :
C:\Users\Thomas>php --ini
Configuration File (php.ini) Path: C:\Windows
Loaded Configuration File: (none)
Scan for additional .ini files in: (none)
Additional .ini files parsed: (none)
Why Configuration File (php.ini) Path: is "C:\Windows" and not C:\MAMP\conf\php5.5.19\. Can I change this Path ?
I don't know what to do now...
thanks !
I had the same error. I had no clue where it was coming from, but with some trial and error I figured out it had something to do with the special character in my htdocs folder:
htdocs/Exámple
By changing that character to a normal character (thus changing to htdocs/Example), I no longer got the error and the site would load normally.
The problem is that your xAMP server and cli access uses different php configuration.
One is C:\Windows\php.ini for CLI
Second is C:\MAMP\conf\php5.5.19\php.ini for web server
Make sure you have updated both files.
Secondly do not forget to restart xAMP server, as apache do not reload libapache2-mod-php5 configs automatically.
When you set configuration in MAMP it only affects PHP which is loaded in Apache module handler mode (mapped as module inside Apache process). If you want to set PHP CLI you need to set this separately from web server configuration.
Open command prompt from Windows (cmd.exe from Start button)
enter ECHO %PATH%
this command will list your current PATH variable with all paths. For example, something like this:
C:>echo %PATH%
C:\Program Files (x86)\EasyPHP-DevServer-14.1VC9\binaries\php\php_runningversion
;C:\ProgramData\Oracle\Java\javapath;C:\Perl\site\bin;C:\Perl\bin
...
now enter following command
SET PATH=%PATH%;c:\mamp\bin\php\php5.6.0\;
This will going to add path to php5.6.0 version from MAMP folder.
you can now test your PHP CLI by entering following command :
php -v
then try to initialize configuration from MAMP for version PHP5.6.0 file:
C:>php -c "c:\mamp\conf\php5.6.0\php.ini" --ini
Configuration File (php.ini) Path: C:\WINDOWS
Loaded Configuration File: C:\MAMP\conf\php5.6.0\php.ini
Scan for additional .ini files in: (none)
Additional .ini files parsed: (none)
You can use command -c from PHP CLI to set path to configuration file; and "c:\mamp\conf\php5.6.0\php.ini" is path to PHP ini file for version 5.6.0.
If you do not want to always add path to configuration file with -c command, just copy php.ini file from C:\MAMP\conf\php5.6.0\ to C:\MAMP\bin\php\php5.6.0\
Off course, this will going to set PHP CLI only in currently opened command prompt. To add this path permanently, you need to modify System Environment variable, or to use MAMP PRO as it already have this feature on PHP options page.
TL:DR - Make sure to edit both the ..\MAMPPRO\conf\php[version].ini and the ..\MAMP\bin\php\php[version]\php.ini with your correct/approved php timezone.
So while I was going through my setup, I had the same issue.
I was taking a look at my phpinfo() and it was giving me a path to my "Loaded Configuration File" that was located in my ..\MAMPPRO\conf\php[version].ini so I was editing that file with approved timezone from http://php.net/manual/en/timezones.php making sure to avoid any from http://php.net/manual/en/timezones.others.php.
After a few restarts and no success I started to dig a little further into where MAMP Pro was pulling that ini.
I found the solution in ..\MAMP\bin\php\php[version]\php.ini. If I edited this file IN ADDITION TO editing the MAMP Pro ini everything worked properly.
Hopefully this can help you out!
At the beggining of your web/app_dev.php and web/app.php you can add:
date_default_timezone_set('Europe/Paris');
I have done this before so I'm not sure why it's not working, but I am trying to create a custom php.ini file and I have placed this within a specific directory.
For example, the default php.ini is located at:
C:\xampp\php\php.ini
My custom one is located at:
D:\Codebase\Somedir\123\php.ini
I placed a PHP file inside the above directory and did output with phpinfo() and it still reports it as using C:\xampp\php\php.ini.
I have restarted Apache as well.
What am I doing wrong here!?
You can see which php.ini file is loaded running php.exe --ini. On my computer it output:
Configuration File (php.ini) Path: C:\WINDOWS
Loaded Configuration File: C:\tools\php\php.ini
Scan for additional .ini files in: (none)
Additional .ini files parsed: (none)
If it is the wrong php.ini there, have a look to http://php.net/configuration.file
If you're using XAMPP you can change the configuration file it loads PHP with by opening the properties.ini file in the
C:\xamp
directory and editing the php_configuration_directory field to
D:\Codebase\Somedir\123\
Then restart apache for the changes to take effect.
If PHP is running as an apache module you could also edit httpd.conf on your apache setup and add this variable:
PHPIniDir "D:\Codebase\Somedir\123\"
In phpInfo, MAMP's Loaded Configuration File is different to the one output when running php --ini:
Loaded Configuration File: /Library/Application Support/appsolute/MAMP PRO/conf/php.ini
Even though, directly above it states the same .ini file as output in the command line:
Configuration File (php.ini) Path: /Applications/MAMP/bin/php/php5.5.10/conf
Is there a way to get MAMP to load the configuration file listed in the row Configuration File (php.ini) Path which is also output with php --ini? Or do I just have to edit the one that MAMP is using?
which php outputs that it is using MAMP's php system:
/Applications/MAMP/bin/php/php5.5.10/bin/php
One php.ini for CLI (command line) and one for web server.
Keep them separated.
If you want to change the way php behave do it depending of the context.
For cli, change the php.ini you find doing php --ini -> Loaded Configuration File
For web server change the file found when doing a phpinfo() from your browser.