PHP setup set_include_path

I had a problem with set_include_path, I read a lot of posts about this problem, but no one works for me. I am on Debian and my root directory will be installed in / home / project /

So, I tried these 4 different things:

ini_set("include_path", '/home/project'); ini_set("include_path", '.:/home/project'); set_include_path('.:/home/project'); set_include_path('/home/project'); set_include_path(get_include_path().PATH_SEPARATOR.'/home/project'); 

But nobody works ... when I do echo get_include_path (); it seems good every time.

But the fourth method works fine with WAMP on my computer.

Error message for ALL of them:

 Warning: include(/config/config.php) [function.include]: failed to open stream: No such file or directory in /home/project/web/www.project.com/index.php on line 3 Warning: include() [function.include]: Failed opening '/config/config.php' for inclusion (include_path='.:/usr/share/php:/usr/share/pear:/home/project') in /home/project/web/www.project.com/index.php on line 3 
+4
source share
3 answers

Try using the constant PATH_SEPARATOR , as done in the documentation.

 set_include_path(get_include_path() . PATH_SEPARATOR . $path); 

Perhaps this depends on the system your application is deployed to.

UPDATE : The inclusion path seems fine, but the problem is different.

You should not include:

 require '/config/config.php' 

but

 require 'config/config.php' 

So, omit the leading slash, and it should work.

+6
source

Use this to set: set_include_path(get_include_path().PATH_SEPARATOR.'/path/'); , this does not remove the existing include_path set by other scripts, and adds a default path separator.

+1
source

The path separator may vary.

 set_include_path(implode(PATH_SEPARATOR, array( '.', '/home/project', get_include_path() )); 

With this, you get the current include path added to the ones you added yourself and the correct path separator for each system.

+1
source

Source: https://habr.com/ru/post/1385883/


All Articles