How to Install ‘bindfs’ on Ubuntu 18.04

What is ‘bindfs’?

A FUSE filesystem for mirroring the contents of a directory to another directory. Additionally, one can change the permissions of files in the mirrored directory.

Simple Usage of ‘bindfs’

Upload your files to your home directory [/home/gatekeeper/www/html] on your server with your account user name [gatekeeper], and ‘bindfs’ will copy your files to your Apache server root directory [/var/www/html] with your Apache user name [www-data]. While copying files, your file ownership changes to your Apache user name automatically.   

The Installation

I am assuming your server root folder address is [/var/www/html] in this installation guide. If your server root folder location is different, you need to replace it with yours. In addition, you need to replace ‘gatekeeper’ with your server account user name.

root@talkerland $ apt update
root@talkerland $ apt -y install bindfs
root@talkerland $ mkdir -p /home/gatekeeper/www/html
root@talkerland $ chown -Rf gatekeeper:gatekeeper /home/gatekeeper/www
root@talkerland $ chmod -Rf 770 /home/gatekeeper/www
root@talkerland $ nano /etc/fstab

Add the following sentence and save the ‘fstab’ file. It is used to set File Permission to 644  and Folder Permission to 755. Make sure to add it in one line. Do not wrap it.

bindfs#/var/www/html /home/gatekeeper/www/html fuse force-user=gatekeeper,force-group=gatekeeper,create-for-user=www-data,create-for-group=www-data,create-with-perms=god=rx:ud=rwx:gof=r:uf=rw,chgrp-ignore,chown-ignore,chmod-ignore 0 0

Mount the folder now.

root@talkerland $ mount /home/gatekeeper/www/html

That’s it!