Skip to main content
added 515 characters in body
Source Link
zuiqo
  • 927
  • 8
  • 15

That depends on your exact way of doing it. Right now it seems to me you have a git repo in your httpdocs that you deploy to, basically using HEAD as your actual website - that is NOT the correct way. I'm not sure how you are able to push to this configuration at all?

What you want to do is use a bare repo somewhere outside the httpdocs-folder, and checkout the files to httpdocs after pushing. While this sounds complicated, its pretty easy to do, here is a step-by-step tutorial: http://caiustheory.com/automatically-deploying-website-from-remote-git-repository


If your webserver needs access to some files, such as a wordpress installation, you need to add chmod and chgrp commands to the post-receive hook, otherwise your files belong to the wrong user (the one you used to push the commit, not the webserver).

Simply make a new script to change ownership that you call from the post_receive hook via sudo scriptname.sh (name it change_own.sh or whatever) :

chown -R wwwrun /path/to/httpdocs chgrp -R www /path/to/httpdocs 

and allow the script to be run without password via visudo by adding gituser ALL=(ALL) NOPASSWD: /path/to/change_owner.sh at the end.

Assumptions made: wwwrun - webserver user; www - webserver group; gituser - user to push commits

Addendum: A friend used this method and complained about how he had to update Wordpress over and over again. The obvious reason is that if the Webapplication updates itself, und thus replaces its code, these changes will not be transferred back into the repository, because the hook only works one way. Thus after each commit, the hook overrode all changes the Wordpress-Installation made through updates. The imho quickest workaround is to run the updates on the developer machine, then commit to deploy.

That depends on your exact way of doing it. Right now it seems to me you have a git repo in your httpdocs that you deploy to, basically using HEAD as your actual website - that is NOT the correct way. I'm not sure how you are able to push to this configuration at all?

What you want to do is use a bare repo somewhere outside the httpdocs-folder, and checkout the files to httpdocs after pushing. While this sounds complicated, its pretty easy to do, here is a step-by-step tutorial: http://caiustheory.com/automatically-deploying-website-from-remote-git-repository


If your webserver needs access to some files, such as a wordpress installation, you need to add chmod and chgrp commands to the post-receive hook, otherwise your files belong to the wrong user (the one you used to push the commit, not the webserver).

Simply make a new script to change ownership that you call from the post_receive hook via sudo scriptname.sh (name it change_own.sh or whatever) :

chown -R wwwrun /path/to/httpdocs chgrp -R www /path/to/httpdocs 

and allow the script to be run without password via visudo by adding gituser ALL=(ALL) NOPASSWD: /path/to/change_owner.sh at the end.

Assumptions made: wwwrun - webserver user; www - webserver group; gituser - user to push commits

That depends on your exact way of doing it. Right now it seems to me you have a git repo in your httpdocs that you deploy to, basically using HEAD as your actual website - that is NOT the correct way. I'm not sure how you are able to push to this configuration at all?

What you want to do is use a bare repo somewhere outside the httpdocs-folder, and checkout the files to httpdocs after pushing. While this sounds complicated, its pretty easy to do, here is a step-by-step tutorial: http://caiustheory.com/automatically-deploying-website-from-remote-git-repository


If your webserver needs access to some files, such as a wordpress installation, you need to add chmod and chgrp commands to the post-receive hook, otherwise your files belong to the wrong user (the one you used to push the commit, not the webserver).

Simply make a new script to change ownership that you call from the post_receive hook via sudo scriptname.sh (name it change_own.sh or whatever) :

chown -R wwwrun /path/to/httpdocs chgrp -R www /path/to/httpdocs 

and allow the script to be run without password via visudo by adding gituser ALL=(ALL) NOPASSWD: /path/to/change_owner.sh at the end.

Assumptions made: wwwrun - webserver user; www - webserver group; gituser - user to push commits

Addendum: A friend used this method and complained about how he had to update Wordpress over and over again. The obvious reason is that if the Webapplication updates itself, und thus replaces its code, these changes will not be transferred back into the repository, because the hook only works one way. Thus after each commit, the hook overrode all changes the Wordpress-Installation made through updates. The imho quickest workaround is to run the updates on the developer machine, then commit to deploy.

Source Link
zuiqo
  • 927
  • 8
  • 15

That depends on your exact way of doing it. Right now it seems to me you have a git repo in your httpdocs that you deploy to, basically using HEAD as your actual website - that is NOT the correct way. I'm not sure how you are able to push to this configuration at all?

What you want to do is use a bare repo somewhere outside the httpdocs-folder, and checkout the files to httpdocs after pushing. While this sounds complicated, its pretty easy to do, here is a step-by-step tutorial: http://caiustheory.com/automatically-deploying-website-from-remote-git-repository


If your webserver needs access to some files, such as a wordpress installation, you need to add chmod and chgrp commands to the post-receive hook, otherwise your files belong to the wrong user (the one you used to push the commit, not the webserver).

Simply make a new script to change ownership that you call from the post_receive hook via sudo scriptname.sh (name it change_own.sh or whatever) :

chown -R wwwrun /path/to/httpdocs chgrp -R www /path/to/httpdocs 

and allow the script to be run without password via visudo by adding gituser ALL=(ALL) NOPASSWD: /path/to/change_owner.sh at the end.

Assumptions made: wwwrun - webserver user; www - webserver group; gituser - user to push commits