PHP page can't write file to /web folder

Discussion in 'General' started by jnewman67, Dec 28, 2021.

  1. jnewman67

    jnewman67 Member HowtoForge Supporter

    Perfect Server CentOS 8, ISPConfig 3.2.6, fully updated, using Mod-PHP setting
    I have a website defined and working - PHP files that access a MySql database, no issues.
    wanted to have a PHP file generate some output and store it into a file saved within the same folder as the PHP file, using
    Code:
    file_put_contents($path . $filename, $content);
    where $path is a valid path created using the $_SERVER["DOCUMENT_ROOT"] variable with a hardcoded folder name added to it. I've copy/pasted the resulting path into the command line with a CD command, and it works - it's valid.
    The permissions on the folder have been set to web15.client11 using "chown -R web15.client11" on the folder - the results match all the other folders in the web directory. this folder is also in the root /web of the website - no parent folders that should be a problem.
    However, the PHP file gets a permissions error when trying to save the contents to the desired path/file when called from a browser:
    Code:
     PHP Warning:  file_put_contents(/var/www/mydomain.com/web/myfolder/myfile.txt): failed to open stream: Permission denied in /var/www/clients/client11/web15/web/myfolder/myphpfile.php on line 76
    where line 76 is the file_put_contents command above.
    When I run "php myphpfile.php" from the command line within that folder, it works and creates the desired file with the desired content in it, though I am logged in as root.

    I was just about to submit this question, when I realized I never searched the ISPConfig forum for the file_put_contents command. Doing so, I found a post that referenced the following:
    As stated above, I was using Mod-PHP - switched it to Fast-CGI, and it's working (already had suExec checked)

    Thanks for the forum and the answers!
     
  2. till

    till Super Moderator Staff Member ISPConfig Developer

    And that's the reason for your issue. Do not use mod_php anymore today and never use mod_php for cms systems that like to write files to the web folder. Today you should always use the most modern PHP to web server binding which is PHP-FPM. Suexec is not working with mod_php anyway.
     
    ahrasis likes this.

Share This Page