I’m running an Apache web server and was wondering what’s the best way to deploy changes (from github) to the web server?
/var/www/ right now is only writable by root.
Should I have my git project directly in /var/www/? (so it creates /var/www/.git/?)
However, when I need to run commands (i.e. sudo git push) wouldn’t work (since my ssh keys are not under sudo).
Would I be better off making /var/www/ writable by myself (and not just root)? Or should I add ssh keys to the root user? Or should I do something else entirely?
Thanks.
I use rsync to sync the contents of my local machine with the server, and if you’re just deploying to one server, then it’s pretty simple (and Capistrano is overkill.). I put the following aliases in
~/.bash_profile:Then, from the git repo on my local machine. I do:
If it looks fishy, I could do
egetwithout the -n and then just do agit diff -w. Then, I could dogit checkout -- path/to/filefor the files I want to keep my changes for. Then, I commit the changes that were on the server that I didn’t get yet. This would only happen if the files on the server are changing in a different way than from deployments. Otherwise, you know that your local version is always more up to date than the files on the server and so don’t have to worry about overwriting things on the server that you don’t yet have on your local. Continue…Done!
Check out the rsync(1) Mac OS X Manual Page for more info.
Another option is to use the Git post-receive hook. But, you’ll have to install Git on the server to do that. Also, I recommend putting the
.gitdirectory outside of your publicwwwdirectory for security & cleanliness reasons. You can do this with the Gitcore.worktreeconfiguration option. For example, from~/git/example.com.git, dogit init --bare; git config core.worktree ~/sites/example.com/. That makes~/git/example.com.gitlike the.gitdir for~/sites/example.com/.