I'm working on a shared hosting environment. I'd like to run a CRON job outside of my public_html folder. What I did was added a folder to the root of my shared account with the CRON script I want to run.
In order for my CRON script to run properly it needs to include a file that is located in the public_html folder.
this is the general file structure on my server:
Cron script file located on the root level:
/shared/root/cronJobs/my-script.php
required file located in the public_html folder:
/shared/root/public_html/sub-folder/required-file.php
in my-script.php
i'm using the following script to try and access my required file:
require_once("../public_html/sub-folder/required-file.php");
The above code returns the following error:
Warning: require_once(../public_html/sub-folder/required-file.php): failed to open stream: No such file or directory in /shared/root/cronJobs/my-script.php on line 2
I've also tried:
require_once($_SERVER["DOCUMENT_ROOT"]."/sub-folder/required-file.php");
The above code results in the following error:
Warning: require_once(/sub-folder/required-file.php): failed to open stream: No such file or directory in /shared/root/cronJobs/my-script.php on line 2
When I attempt to access my required file from inside my public_html file I don't receive any errors at all. This is the first time I've attempted store a script away from the public folder and attempt to include a file located in the public folder.
my-script.php
has the permissions set to 755
I just wondering if I'm doing something wrong or is what I'm attempting to do not allowed in the server environment?