P粉6836651062023-08-24 11:50:35
If you are running SELinux, you may have to grant httpd permissions to read data from the /home directory:
sudo setsebool httpd_read_user_content=1
P粉7275312372023-08-24 09:24:51
This is not actually an Apache related issue. Not even PHP related. To understand this error, you must differentiate between paths on the Virtual Server and paths in the Filesystem.
require
Operators apply to files. But such a path
/common/configs/config_templates.inc.php
Only exists on the virtual HTTP server, and the path does not exist in the file system. The correct file system path is
/home/viapics1/public_html/common/configs/config_templates.inc.php
where
/home/viapics1/public_htmlThe
part is called the Document Root, which connects the virtual world with the real world. Fortunately, web servers usually place 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 can be run from any file in any directory!
Update: Finally I wrote an article explaining the difference between relative and absolute paths in files on systems and web servers, explaining the problem in detail and including some practical solutions plan. Like, such a convenient variable doesn't exist when you run the script from the command line. In this case, a technique called "single entry point" can solve the problem. You can also refer to the above article for details.