PHP – Is It a Good Idea to Install Mercurial on Your Server and Use hg pull to Deploy?

mercurialPHPproduction

I've just started at a new job this past month and looks like they have NO source control for their code. They are relying on the backups their hosting provider takes for them.

After talking a bit I convinced my boss that we should definitely be using source control and after I gave a short seminar on it, the entire team is on board; they loved Mercurial.

So right now this is the way we work:

º----------BitBucket
º---------/
º--------/

Myself and the three other developers hg pull from BitBucket, make our changes, then hg push to BitBucket.

Now for deployment, someone would need to FTP the latest files towards the production server.

I was thinking of installing Mercurial on our server, and using hg clone (subsequently hg pull) to keep the versions up to date on production.

º---push->-----BitBucket----<-pull-----º (production server)
º---push->----/
º---push->---/

Is this a good idea? Any potential pitfalls I may not be seeing? Has anybody here done something similar? How do you deploy a large PHP framework application (We're using Moodle)?

Best Answer

This is certainly a good idea and it is a common method to use for deployment. You might want to use a stable branch for deployment purposes whilst keeping trunk for ongoing development so that you can test the stable branch before you deploy it into production.

The only problem can come when you have sensitive information in your code base (such as API keys etc) that you do not wish to upload to third party servers (in your case that would be Bitbucket). In this case a simple script that is run once you have pulled the data from the repository to restore the sensitive data in the correct place will solve that issue.

Related Topic