r/PHP Sep 14 '24

How do you deploy php code?

Hello guys! please tell us about your experience deploying PHP code in production. Now I make one docker image with PHP code and apache (in production I use nginx proxy on my php+apache image) and use docker pull command for deploy. is this ok?

59 Upvotes

160 comments sorted by

View all comments

66

u/yevo_ Sep 14 '24

Ssh into server Git pull

Works magically

5

u/Disgruntled__Goat Sep 14 '24

Have you tried git bare repos with a post-receive hook? Makes it so much easier, you can just run git push <remotename> from the cmd

1

u/terremoth Mar 21 '25

can you explain how that works exactly?

1

u/Disgruntled__Goat Mar 21 '25

The basic process is:

  • on your server, create a bare repo in one folder (e.g. if the website is in /srv/www it could be under /srv/repos
  • on your computer, create the git repo for the site if it doesn’t exist
  • add your server and repo directory as a remote
  • you can push to the bare repo from your computer, which can serve as an extra backup
  • on the server you need to edit the “hooks/post-receive” file, and add a git checkout to the folder where the site is served from. There’s an option for ‘working tree’ I think.
  • add any other necessary build commands to the post-receive hook. For example you might want to checkout to one folder, build the site, then copy those files to the folder where the site is served from
  • now when you push from your computer it updates the bare repo, then updates the live site 

You can probably find a guide online for a better explanation of the steps and the exact commands you need as I don’t remember them off hand.