简体   繁体   中英

Create folder in www directory using PHP on UBUNTU

Im trying to create a folder (inside www directory) using php script. I did some configurations on UBUNTU, but still not working.

Ubuntu configuration: (user: admin - group: 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:

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:

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. The apache's user needs access to create the directory. 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.

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