简体   繁体   English

在UBUNTU上使用PHP在www目录中创建文件夹

[英]Create folder in www directory using PHP on UBUNTU

Im trying to create a folder (inside www directory) using php script. 我试图使用PHP脚本创建一个文件夹(在www目录内)。 I did some configurations on UBUNTU, but still not working. 我在UBUNTU上进行了一些配置,但仍然无法正常工作。

Ubuntu configuration: (user: admin - group: www-data) Ubuntu配置:(用户:admin-组:www-data)

sudo adduser admin www-data
sudo chown -R www-data:www-data /var/www
sudo chmod -R g+rw /var/www

PHP code: PHP代码:

function makeDir($dir)
{
$ret = @mkdir($dir, 0700);
return $ret === true || is_dir($dir);
}

Error: Don't create directory. 错误: 不创建目录。

Reading some other posts, i found this UBUNTu configuration, but still not works: 阅读其他文章,我发现此UBUNTu配置有效,但仍然无法正常工作:

sudo chmod 777 /var/www
sudo ls -l /var | grep www
sudo usermod -G www-data admin
sudo chmod 770 /var/www
sudo ls -l /var | grep www

尝试这个:

shell_exec("md $dir");

It usually depends on what user & group the httpd is running with, and if using cgi or apache mod method. 通常取决于运行httpd的用户和组,以及是否使用cgi或apache mod方法。 The apache's user needs access to create the directory. apache的用户需要访问权限才能创建目录。 My solution - usually - is to allow write access to the group. 通常,我的解决方案是允许对该组进行写访问。 eg running with nobody (the last line sets file access rights) 例如,没有人运行(最后一行设置文件访问权限)

chown -R :nobody *
chmod -R 770 *
find . -type f -print0 | xargs -0 chmod 640

After this you can simply create directories & files from within php, but you probably need/want to change their rights so you can 'manually' access them when needed via the hosting account. 之后,您可以简单地从php中创建目录和文件,但是您可能需要/想要更改它们的权限,以便可以在需要时通过托管帐户“手动”访问它们。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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