Skip to content
Advertisement

PHP is_writable() function always returns false for a writable directory

I’m trying to install a PHP-based software package in a Red Hat 7 Amazon EC2 instance (ami-8cff51fb) that has had Apache 2.4.6 and PHP 5.4.16 installed on it using yum. The installation fails because it says a particular directory needs to be writable by the webserver with 0755 or 0775 permissions.

The directory in question has 0775 permissions with root:apache ownership. I have verified that the httpd process is being run by the apache user and that the apache user is a member of the apache group.

If I edit /etc/passwd to temporarily give the apache user a login shell and then su to that account, I am able to manually create files as the apache user within the directory using the touch command.

I took a look at the source code of the installer script and identified that it’s failing because PHP’s is_writable() function is returning false for the directory in question. I created a separate test PHP script to isolate and verify the behaviour I’m seeing:

JavaScript

This outputs the NOT writable message. If I change $dir above to be /tmp then it correctly outputs that /tmp is writable.

If I change the directory permissions to 0777 and/or change the ownership to apache:apache then PHP still reports that the directory isn’t writable. I even tried creating a /test directory set up with the same permissions and ownership and my test script still reports it as not writable.

I’m really at a loss as to explain this behaviour, so any ideas would be welcome!

Thanks in advance.


The directory listing for /var/www/html/limesurvey is given below. The tmp and upload directories have 0775 permissions as per Lime Survey’s installation instructions. test.php is my test script mentioned above.

JavaScript

Running namei -l /var/www/html/limesurvey/tmp gives:

JavaScript

Advertisement

Answer

After much head-scratching, it transpired that SELinux was preventing the directory from being written to. I found a good tutorial that explains what’s going on. I was able to fix it by running this command:

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement