Find the answer to your Linux question:
Results 1 to 2 of 2
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 ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Jul 2010
    Location
    Myrtle Beach, SC
    Posts
    3

    [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

    Code:
    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
    This process is run via CRON. I have tried a few different combinations as follows

    1. directory permissions at 777
    2. directory owner = CRON process user
    3. CRON process user = member of group
    4. 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?

  2. #2
    Just Joined!
    Join Date
    Jul 2010
    Location
    Myrtle Beach, SC
    Posts
    3

    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:
    PHP Code:
    $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 
    i hope this helps someone out!

    2 thumbs up to Media Temple for helping me out once again - even though it was outside the range of support!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •