简体   繁体   中英

Make Directory Permission denied, but permissions are set correctly

I am trying to create a simple php script that creates a directory in /var/www/html. The code is:

$dir = '/var/www/html/testdir';

 if ( !file_exists($dir) ) {
     $oldmask = umask(0);  // helpful when used in linux server
mkdir($dir, 0777, true) || chmod($dir, 0777);
     mkdir ($dir, 0744);
 }

The problem is, I get a permission error when this is executed. But the permissions for the html directory is:

drwxrwxrwx. 7 apache apache 4096 Jun 18 11:46 html

Here is the error:

Warning: mkdir(): Permission denied in /var/www/html/createdir.php on line 6

Also, <?php echo exec('whoami'); ?> <?php echo exec('whoami'); ?> tells me php is running as apache.

Ok I found the problem. Linux was blocking Apache from creating directories.

Fix:

chcon -R -t httpd_sys_content_t /path/to/www
chcon -R -t httpd_sys_content_rw_t /path/to/www/dir/for/rw

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