P粉6628028822023-08-21 16:05:34
If you are running SELinux, you may need to give httpd permission to read the /home directory, use the following command:
sudo setsebool httpd_read_user_content=1
P粉2519031632023-08-21 13:14:41
This is not actually an Apache related question, or even a PHP related question. To understand this error, you must distinguish between paths on the Virtual Server and paths in the Filesystem.
Therequire
operator is used for files. But a path like this
/common/configs/config_templates.inc.php
Only exists on the virtual HTTP server, and there is no such path in the file system. The correct file system path should be
/home/viapics1/public_html/common/configs/config_templates.inc.php
in
/home/viapics1/public_htmlThe
section is called the document root, which connects the virtual world to the real world. Fortunately, web servers usually have the document root in a configuration variable shared with PHP. So if you change your code to something like this
require_once $_SERVER['DOCUMENT_ROOT'].'/common/configs/config_templates.inc.php';
It will work in any file in any directory!
UPDATE: Finally I wrote an article explaining the difference between relative and absolute paths on file systems and web servers that explains the problem in detail and includes some practical solutions . For example, when you run the script from the command line, such a convenient variable does not exist. In this case, it can be solved using a technique called "single entry". You can also refer to the above article for more details.