Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

kfirba's avatar
Level 50

Auto deploy from a remote git repo to a server

Hello!

I'm looking for a way to deploy from a remote git repository to a server (trying to DigitalOcean's one).

To be honest, I have an idea but It's pretty dangerous. I can use a web-hook on the remote repository (gitlab or bitbucket) to POST my website at some URI for example, https://example.com/git and then the URI will trigger a:

git pull

to get the changes. The problem is, who says that Bob won't do that manually? There needs to be some way to defend against it which I'm not entirely sure. Is it safe enough to assume that it's safe if the request was made by gitlab.com or bitbucket.com?

I believe that services like Forge use a web-hook to "poke" forge.laravel.com and then they SSH into the server and pull the changes (I might be terribly wrong).

What do you think? What would be a safe way to do that?

0 likes
9 replies
bashy's avatar

Make it an obscure link. Enable IP check. Lots of options!

kfirba's avatar
Level 50

@bashy So you do think that my idea of using web-hook was good but I just need to guard the request if I get you right?

bashy's avatar

Yeah that's perfectly fine to use a webhook. Just make sure it's not something guessable.

/git-nKdpe7DE2K8p54W5N8DUhSV5i7yyBt2h

/jC38FuNGcP

Something like those :)

kfirba's avatar
Level 50

@bashy Well, I certainly get your point. a not "guessable" URI is one step, guess I will have to parse the request and figure out who made the request, when, and maybe I can find a way to attach custom headers to the request, gotta explore that I guess.

ssddanbrown's avatar

If you have ssh access then instead of pushing to a remote repo and pulling back down to the server via a hook you could push directly to a bare repo on the server. I usually follow this guide for setting a repo on the server.

1 like

Please or to participate in this conversation.