How to set include path of file when running script from cmd How to set include path of file when running script from cmd php php

How to set include path of file when running script from cmd


Your setup may have different php.ini option files for cmdline and web use,you can either add the right include_path to the cmdline ini file (/etc/php5/cli/php.ini in my case), or pass it as a command line parameter:

php -d include_path=... script.php


I like doing:

require dirname(__FILE__) . '/../include/file.php';

That way all includes and requires are relative to the local file.

Also, require, etc are not functions. You should not use parenthesis.


You can also change directory ("cd") in the cmd window to the directory of the file you are running before you run it. Then it should get the correct paths.