简体   繁体   中英

Different include_path when run php script from command line?

I'm getting a fatal error on my require_once('directory/file.php') , "failed opening required...". I know the required file is in my php includes folder at c:\\PHP_Includes\\directory\\file.php . When I look at phpinfo() I see the correct include_path: ".;c:\\PHP_Includes"

But in the command line error it says include_path='.;C:\\php\\pear;C\\Projects\\project1\\classes'

Any idea why the path seems to be different when running command line script?

The problem is related to the fact that WampServer has a multitude of php ini files. Make sure to keep them all in sync with the correct settings to avoid problems when one is used instead of the other.

Very useful info from http://forum.wampserver.com/read.php?2,72804 :

There is actually 3 php.ini files in WampServer

This is how they are used...

  1. C:\\Wamp\\bin\\php\\phpX.XX\\php.ini This is only used by wampserver and php cli exe. WampServer's menu is built using php and this is the config file that is used. It is also used if you are using php through the command line interface. You generally never need to edit this file.

  2. C:\\Wamp\\bin\\php\\phpX.XX\\phpforapache.ini This is a copy of the php.ini file used for your websites. When this version of php is being used this file is copied into the apache bin folder. If you change version of php the apache\\bin\\php.ini is then emptied and the phpforapache.ini of the new version of php is loaded into whichever version of apache is loaded.

  3. C:\\Wamp\\bin\\apache\\apacheX.XX\\bin\\php.ini This is the actual php.ini that is loaded for your websites. provided that this is the version of apache being used. This is copied from the relevant active php folder( phpforapache.ini).

This may seem a little confusing but it is nessecary for WampServer's ability to change version of apache and php easily. The best thing to remember is..

If you want to manually edit your php.ini file for websites then always use the wampserver menu to open it . >> left click the WampServer icon > php > php.ini

If you want to manually edit your php.ini file for command line then open php.ini in the current php folder.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM