Home > OS >  How can I mount /var/www to /www using linux mount --bind command?
How can I mount /var/www to /www using linux mount --bind command?

Time:09-11

I'm developing a php application and I would like to mount /var/www to /www. I have ran chown -hR www-data:www-data /var/www.

What I want to achieve is to be able to create new files and directories with www-data as the owner and www-data as the group using my local account without issues.

So I have decided to mount /var/www to /www using sudo mount --bind /var/www /www so that all local accounts can modify it also files and directories will be created as www-data:www-data but i can't get it to work.

CodePudding user response:

I think what you're looking for here is the setfacl command, which sets the default permissions for a specified directory. After you mount the directory, try the following:

sudo setfacl -d -m u:www-data:rwx /www

If you want to change the existing permissions as well, add the -R flag:

sudo setfacl -R -d -m u:www-data:rwx /www

CodePudding user response:

I was able to resolve the issue by taking these steps.

  1. Installed the package bindfs sudo apt install bindfs
  2. Added myself to www-data group sudo usermod -a -G www-data "$LOGNAME"
  3. Mounted /var/www/shared/user to /home/user/Projects/www-data in /etc/fstab using

/var/www/shared/user /home/user/Projects/www-data fuse.bindfs create-for-user=www-data,create-for-group=www-data,mirror=@www-data 0 0

Files created under /home/user/Projects/www-data looks like they are owned by user but are created as www-data:www-data

Output from ls -l /home/user/Projects/www-data:

drwxrwxr-x  2 user www-data 4096 Sep 11 08:40 project_1

Output from ls -l /var/www/shared/user:

drwxrwxr-x  2 www-data www-data 4096 Sep 11 08:40 project_1
  • Related