2

I'm setting up a new Centos 7 server to run some legacy sites on PHP 5.6.40 through PHP-FPM with Nginx.

However, I'm running into a problem that all files are appearing to be read only.

PHP is running under the nginx user, the site directory is owned by nginx, and I've tried verious file permissions through chown, including "777".

I created a simple program to illustrate:

<?php
$fileList = glob('*');

//Loop through the array that glob returned.
foreach($fileList as $filename){
   //Simply print them out onto the screen.
   echo $filename;
   if (is_writable($filename))
      echo ' - Yes!';
   else
      echo ' - No.';
   echo '<br>';
}

This will output the files in the site directory, with "No" next to each filename.

Any tips on what might be causing this, or how I might be able to debug would be greatly appreciated.

0
2

SELinux does not allow nginx or php-fpm to write to random directories. You need to tell SELinux which directories should be writable by setting their default context to httpd_sys_rw_content_t and then setting the context of any existing files. For example:

semanage fcontext -a -t httpd_sys_rw_content_t "/srv/www/my/uploads(/.*)?"
restorecon -rv /srv/www/my/uploads
1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.