我在CentOS上运行Apache,在我的/etc/httpd/conf/httpd.conf文件中,用户和组都是my-username
$ cat /etc/httpd/conf/httpd.conf|grep '^User'
User my-username
$ cat /etc/httpd/conf/httpd.conf|grep '^Group'
Group my-username
当我在命令行上以my-username
运行时,我可以创建一个目录,但不是通过调用Web服务器。
$ cat test.php
<?php
mkdir(dirname(__FILE__) . '/made-by-the-webserver', 0755);
$err = error_get_last();
$user = exec('whoami');
echo 'Whie attempting to create a directory, we got ' . $err['message'] . ' running as ' . $user;
$ curl mysite.local/test.php
Whie attempting to create a directory, we got mkdir(): Permission denied running as my-username
$ whoami
my-username
$ mkdir made-on-the-command-line
$ ls -lah|grep made
drwxrwxr-x. 2 my-username my-username 4.0K Dec 16 14:51 made-on-the-command-line
$ php test.php
Whie attempting to create a directory, we got running as my-username
$ ls -lah|grep made
drwxr-xr-x. 2 my-username my-username 4.0K Dec 16 14:52 made-by-the-webserver
drwxrwxr-x. 2 my-username my-username 4.0K Dec 16 14:51 made-on-the-command-line
我希望,因为Apache正在运行用户my-username
,并且允许my-username
在命令行上创建目录,所以也允许在调用Apache期间创建目录。
任何有关调试的帮助都非常感谢,谢谢!
阿尔伯特。
答案 0 :(得分:0)
几乎可以肯定是由于SELinux。也许需要父目录上的httpd_sys_script_rw_t属性?