Update your website directly from your git repository

Here is a php script you can use to update your website from your git repository.  You can pass 2 parameters to it:

  • “r” – revision you want checked out from git (r=head works also)
  • “l” – number of log entries you want to view

For example, if I was running it on this site here is what each URL would do:

You need to make sure that the directory structure is owned by the HTTP daemon user (so that the files can be updated.)  It is best to run it initially from the command line as that user on the server to make sure everything is working properly.

One word of caution; you should restrict access to who can run this script (maybe with HTTP-Auth over HTTPS) because the script isn’t perfect and you don’t want to let anyone make changes to your site.  There are also certain security risks that are increased when you have your website files owned by the webserver user.  It is recommended that you only use this script in a protected environment.

/gitpull.php – show current status and last 3 log entries (make no changes)