php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #21783 php-{SAPI}.ini and php.ini : when/where/what php looks for and why.
Submitted: 2003-01-20 17:29 UTC Modified: 2005-04-27 14:55 UTC
Votes:1
Avg. Score:2.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: danielc at analysisandsolutions dot com Assigned: nlopess (profile)
Status: Closed Package: Documentation problem
PHP Version: 4.3.0 OS: Any
Private report: No CVE-ID: None
 [2003-01-20 17:29 UTC] danielc at analysisandsolutions dot com
Hi:

Please pardon the initial background if it's irrelevant, but I figured it may come into play somehow...

Been using PHP for years, just fine.  It's installed in f:\progra~1\php.  That dir is in my Path, so I keep the php.ini and various dll's there to make upgrading easy.

Installed latest version, 4.3.0, by moving old version to backup directory and unzipping binaries into f:\progra~1\php.

Edited php.ini to my tastes.

After running into problems with CLI not finding my php.ini file, I ran some tests.  The test script contains:

   echo 'include_path...  ' . ini_get('include_path') . "\n";
   echo 'cfg_file_path... ' . get_cfg_var('cfg_file_path') . "\n";

Now I open up command line window and execute:
   > cd progra~1\php
   > php ./script

Has the right output:
   include_path...  .;f:\progra~1\pear
   cfg_file_path... F:\PROGRA~1\php\php.ini

But, running the CLI does not:
   > cli\php ./script

   include_path...  .;c:\php4\pear
   cfg_file_path...

If I copy php.ini to the cli directory, the expected results are obtained.

One assumes the CLI version would be smart enough to look up one directory level or in the Path for the php.ini.

Of course, I can specify the config file via the -c flag, but that's awkward for general use and is counter-intuitive.

I hope the behavior of the CLI executable will be changed accordingly, please.

Thanks,

--Dan

Patches

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-01-20 19:05 UTC] edink@php.net
This is how cli is designed to work (not to look for php.ini in the current working directory) and it won't change.

You can achieve the desired behaviour by issuing:

set PHPRC=.

on the command line, or setting this environmental variable elsewhere in the system.
 [2003-01-20 19:44 UTC] danielc at analysisandsolutions dot com
Okay.  Then, can you please change this into a documentation bug?  The features.commandline.php pages should really explain this.

For the clarity of other people reading this, the simple, long-term solution is creating an environment variable named PHPRC and setting it to the path of where your php.ini file resides.  For example, "c:\progra~1\php"

Thanks,

--Dan
 [2003-01-20 19:51 UTC] edink@php.net
PHPRC environmental variable (and other ways of finding it) are documented at:

http://www.php.net/manual/en/configuration.php#configuration.file
 [2003-01-20 20:46 UTC] danielc at analysisandsolutions dot com
Thank you for that link.  None the less, people reading the features.commandline.php won't necessarily read the configuration.php page.

Gee, take me for example! :)  I spent a significant amount of time trying to figure out what was going on.  Checked the command line page in the manual, all of the user comments, the newsgroup archives and the bug database.  All of which turned up nothing, hence my bug report.

So, a simple mention of the situation and a cross reference link to configuration.php would be helpful.

Heck, I'm fairly PHP literate and a good sleuth, but wound up using your time anyway.  This minor documentation tweak will save everyone grief in the long run.

Of course, I could add a user comment, but that doesn't have the same impact.

Thanks for your consideration,

--Dan
 [2003-01-20 20:52 UTC] edink@php.net
Point taken :)

A cross reference to the info about the location of php.ini file (/manual/en/configuration.php#configuration.file) should be inserted on features.commandline page.
 [2003-01-20 21:05 UTC] philip@php.net
On a related note, I heard rumors that as of 4.3.0 ini files such as php-cli.ini and php-cgi.ini are looked for first, is this true?  If not found, php.ini is looked for.
 [2003-01-20 21:25 UTC] danielc at analysisandsolutions dot com
The text I'd suggest is something along these lines.  I don't know the complete inner workings of PHP, so tweak it to reflect reality.

On Unix systems, PHP uses the php.ini file specified when PHP was compiled. On Windows systems, PHP uses the php.ini from the same directory as the php.exe file you execute. This behavior can be modified by using the -c switch or by setting the PHPRC environment variable. See the <a href="configuration.php">Configuration</a> page for more information.

Thanks,

--Dan
 [2003-02-02 06:44 UTC] philip@php.net
Information found in bug #22001 should be included when this bug report is dealt with:

    http://bugs.php.net/22001

Pretty interesting stuff.
 [2003-07-15 08:11 UTC] phyre at rogers dot com
I note that there are different files (php-cli.ini) which isn't documented as far as I can tell.  That's for that pointer folks.

  However, I believe that different directories are also quite important.  Apache php.ini goes with apache config.  CLI should go in /etc.  Thoughts?
 [2004-07-27 18:54 UTC] vrana@php.net
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation better.

"If php-SAPI.ini exists (where SAPI is used SAPI, so the filename is e.g. php-cli.ini or php-apache.ini), it's used instead of &php.ini;."

I added also cross-reference to features.commandline.
 [2004-07-27 20:19 UTC] philip@php.net
IMHO this should be closed when:

1) Every possible php-{SAPI}.ini name is listed
2) Where PHP looks for these, and in what order
3) Document every possible way to change this location,
   including at compile time.

Not sure why #22001 was closed but we'll leave it and focus on this one as it's a smaller number :)

#3 may want to be a faq but it's important and a topic that PHP users have wondered about for years.  In Apache 2 there is a PHPINIDir setting that can be used, does anything similar exist in Apache 1?  In Windows show how (or link to how) to set environment variables such as PHPRC, PHPRC as a variable is currently documented.  Not sure about IIS... --with-config-file-path should be mentioned on this list as well.  There could be more settings, the above are what come to mind.
 [2005-04-27 10:48 UTC] vrana@php.net
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation better.


 [2005-04-27 14:46 UTC] nlopess@php.net
look at Philip's notes. 1) and 2) aren't document. the php-{sapi}.ini should be documented.
 [2005-04-27 14:55 UTC] vrana@php.net
Everything is already documented.

1) All SAPIs are not listed (it's hardly possible as there are PECL SAPIs) but there are examples and it's mentioned how to get a SAPI name which should be sufficient.

2) is documented exactly according to source.

Check my last two commits cornening this bug.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Aug 15 19:01:28 2024 UTC