我试图创建目录/home/freestyle/test
像这样
$location = "/home/freestyle/test";
$uold = umask(0);
mkdir($location,0777,true);
umask($uold);
但我得到了错误
Warning: mkdir(): Permission denied in /opt/lampp/htdocs/test/test.php on line 6
我不想
chmod
通过终端许可,我想直接在 PHP 中进行。怎么做?
编辑
ps aux | grep httpd
显示root 10868 0.0 0.3 351528 14288 ? Ss 09:41 0:00 /opt/lampp/bin/httpd -k start -E /opt/lampp/logs/error_log -DSSL -DPHP
daemon 11263 0.0 0.1 347600 5500 ? S 09:41 0:00 /opt/lampp/bin/httpd -k start -E /opt/lampp/logs/error_log -DSSL -DPHP
daemon 11266 0.0 0.3 352036 11864 ? S 09:41 0:00 /opt/lampp/bin/httpd -k start -E /opt/lampp/logs/error_log -DSSL -DPHP
daemon 11267 0.0 0.3 352852 12864 ? S 09:41 0:00 /opt/lampp/bin/httpd -k start -E /opt/lampp/logs/error_log -DSSL -DPHP
daemon 11268 0.0 0.3 352036 11868 ? S 09:41 0:00 /opt/lampp/bin/httpd -k start -E /opt/lampp/logs/error_log -DSSL -DPHP
daemon 11269 0.0 0.3 352128 12308 ? S 09:41 0:00 /opt/lampp/bin/httpd -k start -E /opt/lampp/logs/error_log -DSSL -DPHP
daemon 11270 0.0 0.3 351944 11848 ? S 09:41 0:00 /opt/lampp/bin/httpd -k start -E /opt/lampp/logs/error_log -DSSL -DPHP
daemon 11329 0.0 0.3 352088 12088 ? S 09:42 0:00 /opt/lampp/bin/httpd -k start -E /opt/lampp/logs/error_log -DSSL -DPHP
daemon 11444 0.0 0.3 351900 11348 ? S 09:44 0:00 /opt/lampp/bin/httpd -k start -E /opt/lampp/logs/error_log -DSSL -DPHP
daemon 11922 0.0 0.2 351528 10572 ? S 10:09 0:00 /opt/lampp/bin/httpd -k start -E /opt/lampp/logs/error_log -DSSL -DPHP
daemon 11946 0.0 0.2 351528 10984 ? S 10:10 0:00 /opt/lampp/bin/httpd -k start -E /opt/lampp/logs/error_log -DSSL -DPHP
daemon 11953 0.0 0.2 351528 10120 ? S 10:11 0:00 /opt/lampp/bin/httpd -k start -E /opt/lampp/logs/error_log -DSSL -DPHP
freestyle 12516 0.0 0.0 15124 984 pts/5 S+ 10:42 0:00 grep --color=auto httpd
最佳答案
您首先需要确保您拥有 /home/freestyle/
的正确权限
运行 ls -l /home/freestyle/
从您的终端
比运行(*取决于您的 apache 配置,在我的情况下是 www-data)
chown "www-data:www-data" /home/freestyle/
和
ls -l /home/freestyle/
再次查看权限是否更改更新*
从您提供的输出看来,您的 apache 在
daemon
下运行.授予/home/freestyle/运行权限:
chown "daemon:daemon" /home/freestyle/
更新 2*
要更改 apache 所有权用户和组,请在 apache 配置中更改/添加以下内容
export APACHE_RUN_USER=www-data
export APACHE_RUN_GROUP=www-data
关于php - 在 PHP 中使用 mkdir 的权限被拒绝,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22277862/