简体   繁体   中英

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?

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 .

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.

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/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM