3

I'm having a problem with allowing Apache to automatically have write access to an .htaccess file being pulled from a git repository.

Here's my process:

I'm logged in as a newly created user "webadmin", which has been added to the group "apache" (i'm on CentOS so it's equivalent to www-data) and I have created an empty directory:

/var/www/html/test

I've ensured that on this directory, i've done the following:

$ umask 002 
$ chown -R apache:apache /var/www/html/test
$ chmod -R g+rw /var/www/html/test 

This is to make sure that the directory is owned by the group "apache", and since my user "webadmin" is part of that group, I assume that anything I add with this user will also be writeable by the apache user (php scripts).

Still using the webadmin user, I then run a

git clone myrepo.git .

Which pulls my WordPress website files down into the directory. Included in this is an .htaccess file. This file needs to be writeable by WordPress, so that it can modify rules. All files pulled down are owned by webadmin with the group of apache.

For whatever reason, the .htaccess file is not by default writeable by apache until i again run:

$ chmod -R g+rw /var/www/html/test 

Why would I have to run this command again? Is there any way I can make it so that this file can but automatically written to by apache when it's pulled down without having to run the -R g+rw command?

1 Answer 1

2

Your need is exactly opposite of this stackoverflow post. So in short, you can choose to:

  • Set umask appropriately (presumably to 002, according to your post) before running git
  • Add a git hook script to change file permission after cloning.

The first choice is generally easier to do.

2
  • Thanks, so basically you are saying it needs to be done every time before running a git clone?
    – Joe
    Jul 11, 2014 at 22:15
  • 1
    Yes, but of course you would have easier life if the umask can be set automatically before running git clone. There's no enough info on how you are running git so the "correct" way depends. For example, if you're running git from PHP script, then you would want to take a look at PHP umask() function. Jul 11, 2014 at 22:43

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .