[SOLVED] PHP DOM XML file save Permission Denied??
I am getting a permission denied warning every time i try to save an XML file generated with the PHP DOM $dom->save('file_name.xml') regardless of the permission level set on the folder
This process is run via CRON. I have tried a few different combinations as follows
PHP Warning: DOMDocument::save(sitemap-cron-test.xml): failed to open stream: Permission denied in /var/www/vhosts/domain.com/httpdocs/admin/office/cron-test/xml-sitemap-users.php on line 125
- directory permissions at 777
- directory owner = CRON process user
- CRON process user = member of group
- directory owned by apache & 750 permissions
All to no avail. Each time failing with a permission denied error. I don't see how permission can be denied when set at 777...???
Also, the main goal is to have the generated XML file output and saved to the document root (httpdocs) but i'm having some trouble figuring out secure permissions and ownership for that directory.
The XML generation script works 100% on the localhost (windows/xampp/apache) setup. The XML file is generated and saved where ever i need it to be. So i know the script works 100%.
Can anyone help me get this process running?
Solved: Please read, this may help any PHP developers working with CRON
CRON job notes
For anyone who is running (or about to run) a CRON job, REMEMBER that all actions are run from / releated to the Server Root and not the document root. This is where my issues where coming from.
I needed to save the file with the full server root file path and NOT from the document root. This means that:
i hope this helps someone out!
$dom->save($_SERVER['DOCUMENT_ROOT'].'my-schnazzy-xml-file.xml'); // will NOT work
$dom->save('/var/www/vhosts/domain.com/httpdocs/my-schnazzy-xml-file.xml'); // works perfectly
2 thumbs up to Media Temple for helping me out once again - even though it was outside the range of support!