Aliaksei Plashchanski
Aliaksei Plashchanski

Reputation: 643

Directory is not writable CentOS7, Apache 2.4.6, PHP 5.4.16

I have Linux user, let say admin. Apache process is running under admin user. I have the next simple script for testing permissions:

<?php
$flag=is_writable("/var/www/html/admin/protected/runtime");
if($flag)
  print "Is writable\n";
else
  print "Is not writable\n";

echo 'Current user: ' . exec('whoami');
?>

When I run this script in the console it says:

Is writable
Current user: admin

When I open page in the Firefox it says:

Is not writable Current user: admin

I'm confused, how it can be that directory is writable and is not writable simultaneously under the same user?

Upvotes: 2

Views: 6025

Answers (3)

Charly
Charly

Reputation: 1139

See https://techblog.jeppson.org/2016/10/install-wordpress-centos-7/ which answered a lot of my SELinux issues.

Basically you can leave setenforce to 1 and run

sudo semanage fcontext -a -t httpd_sys_content_t /var/www/html/
sudo restorecon -v /var/www/html/

to grant specific permissions to your wordpress directory.

==== EDIT ====

In practice, it worked to solve the top wordpress root directory issue but lower levels have an issue. I ended up with:

chcon -R -t httpd_sys_rw_content_t /var/www/html/

Upvotes: 2

Aliaksei Plashchanski
Aliaksei Plashchanski

Reputation: 643

Problem is in selinux. Permissive mode setenforce 0 - solves problem. But it is not good solution, better one is configure selinux. More about selinux available here https://wiki.centos.org/HowTos/SELinux.

Upvotes: 2

user3795412
user3795412

Reputation: 1

Im sure that centos is viewing your browser as a non group user, therefore if your permissions for that directory are anything but 777, Firefoxe probably won't be able to do it.

you could change ownership of the directory to apache with sudo chown -R www-data:www-data /path-to-directory

or you could try making the file permissions 777 just to see if that is the problem.

In general, it is best to save files to your database for security reasons.

Upvotes: 0

Related Questions