user4465396
user4465396

Reputation:

Use source from Git to run a website

Is there any way, to run website, using source from Git?

For example, I have private repository in Bitbucket, and I want to use this source in my website automatically (so the source will be automatically downloaded on my server) and when I make changes in repository (for example, update any file), the source is automatically updated in my webisite.

In this case, I want to use Laravel.

Thank you.

Upvotes: 1

Views: 67

Answers (2)

Kip
Kip

Reputation: 558

You can achieve this if you have git installed on the target machine by using a post-receive hook.

  1. Repository init (instructions are for Linux)

    • Create a user called git.
    • mkdir /var/repo/your_name.git
    • cd to that dir.
    • Run git init --bare

      1. Create post-receive to push files to /var/www/your_site
    • cd hooks
    • Create post-receive:
    • #!/bin/sh git --work-tree=/var/www/your_site --git-dir=/var/repo/your_name.git checkout -f sudo /usr/local/bin/post-receive-your_site
      1. Change ownership of files in /var/www to web.web (the owner/group of the html dir). Since this runs as git, you need to allow special sudo on the script, which means putting it in one of the safe directories, i.e. /usr/local/bin.
    • Create post-receive-your_name: #!/bin/sh find /var/www/your_site/ -type f -group 'git' -exec chown web:web {} \; find /var/www/your_site/ -type d -group 'git' -exec chown web:web {} \;
    • As root:
      cd /usr/local/bin
      ln -s /var/repo/your_name.git/hooks/post-receive-your_site
      vi /etc/ssh/sshd_config and add "AllowUsers YOUR_SSH_ID git
      vi sudoadd: git ALL=(ALL:ALL) NOPASSWD: /usr/local/bin/post-receive-your_site

      After setting the repository up, you'll need to git remote add live <YOUR NEW REPOS>, and then you can push to production by running git push live master.

Upvotes: 0

Curtis
Curtis

Reputation: 113

It sounds like what you're looking for are webhooks. Webhooks allow for a git command to be executed automatically when a specific task is done, such as a 'git push' to your repository.

In your instance a webhook could be set up to execute a script on your server to run a 'git pull' command. Here's the documentation that Bitbucket provides on the subject - https://confluence.atlassian.com/display/BITBUCKET/Manage+Webhooks

Upvotes: 0

Related Questions