0

In my server, my root directory is: home

And all public files (www directory) is in: home/public_html

Ok, i want to put some files in others directories out of the www directory, example: home/configs, or home/php_classes

And i want to include the files on those directories from some files in www directory.

basically, i want to home/public_html/index.php to include files that are in home/configs and home/php_classes

I've tried:

include("../configs/site_config.php");
include("../php_classes/mailer.php");

AND

include("/home/configs/site_config.php");
include("/home/php_classes/mailer.php");

But it doesn't work, i keep receiving the include warning "No such file or directory"

leoap
  • 1,684
  • 3
  • 24
  • 32

1 Answers1

1

Both of your PHP code snippets should work, so first double check that the file really does exist.

If you're sure there are no typos, it's almost certainly a permissions issue. PHP executes under Apache, so you'd need to give access to the folder to the user Apache runs as. The easiest way to do this depends on operating system, here is an answer which dives into deeper detail: How do I give PHP write access to a directory?.

To test if this is the issue you could temporarily recursively set permissions on the directories you're trying to access to world readable/executable (eg 755). Something like chmod -R 755 /home/configs. If PHP still doesn't find it then your issues lie elsewhere. Make sure to narrow down the permissions once you've identified the issue, as you don't want to leave your directories world readable or executable unless you have a good reason to do so.

Community
  • 1
  • 1
Alex Ross
  • 3,729
  • 3
  • 26
  • 26