Looking for a best practice to work in /var/www/html by using git

I am developing html code on my local desktop machine (Fed 40 Workstation) in /var/www/html. I use git for version management. I push my local changes to my git server and then pull it to my html directories on the test and production server.

To work properly on my desktop machine all my files and directories in /var/www/html needs to be owned by apache user and group.

But to work properly with git all the files and directories needs to owned by root or to my own user.

So I need always to switch back and force between apache and root with chown -R ...

I guess there is a more convenient way for me. Any help is appreciated.

Are you working with purely static content? If so, then you might consider bypassing Apache for local development and use http-server or serve via Node.js or SimpleWebServer.

Those won’t listen on standard port 80/tcp, but at least you won’t have to deal with file permission and ownership.

1 Like

Some other options:

  • Run git as apache:
sudo -u apache git -C /var/www/html pull
  • Utilize ACLs:
sudo setfacl -R -m u:apache:rwX,d:u:apache:rwX /var/www/html

My environment based currently on html, MariaDB, php and javascript. I have already reviewed Node.js. Maybe I will do a migration in future.

sudo setfacl -R -m u:apache:rwX,d:u:apache:rwX /var/www/html

I never used ACL, no need so far. But in this case it is really the option.
Now it works w/o changing with chmod ...

Thanks for the tip.

1 Like

The files do not need to owned by apache.
They need to be readable by apache.

I install as root so that they cannot be changed by apache.

What I do is run an install.sh script that copies from a git clone to the production server. I do not run git on the production server.

That script will also set permissions, for CGI etc, as needed.

Often I have generated HTML content that I will create in the install.sh and then copy.
For example my pysvn.barrys-emacs.org has a page that lists all the source kits. That page is generated based on the kits that are available.
But the kits are not in git.