php - 在 PHP 中使用 mkdir 的权限被拒绝

标签 php ubuntu

我试图创建目录/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/

相关文章:

ubuntu - 为 Nimrod 安装 Babel 时遇到问题

linux - vmWare Server 可以安装在 X-less 主机上吗?

javascript - 如何使用ajax从php while循环发布数据

php - windows VC9 ffmpeg 和魔法棒

c - 在 Raspberry Pi 上构建源代码

ubuntu - 如何在 Ubuntu 10.4 中安装 webkit?

php - DVWA 无法访问

php - 仅更改 css 文件的 Smarty 分隔符标记?

php - Laravel 调度程序未按预期工作

google-chrome - Chrome 中的 "monospace"是什么?