What is a safe method to upload changes to the production server?

If I am updating a high traffic website via Phpstorm deployment SSH and somebody makes a request where half the files are written or half files are old and half are new, it can make my website appear broken. Could anyone please tell me the recommended solution to prevent this this from occuring (preferebly via Phpstorm deployment)?



The method I'm adopting is to use Git and Capistrano.  https://help.github.com/articles/deploying-with-capistrano

I have a 7$/month personal account on Github, which let's me create private repositories.  Github already has capistrano installed and configured since they run ruby, so I don't need to do any setup for that.  All I need to do is configure the SSH credentials and path info, and then as soon as I do a push of commits into a designated/configured branch - those changes will be transferred via ssh/scp over to the server.  

This doesn't, in and of itself, fix your issue as it is still copying files over so a request can be made in the middle.  It will just make the entire deployment much faster as it goes from a fast github server directly to the production server.

The process would be something like:
Change to git branch: development
do some work
make commits
do some work
make commits
Change to git branch: production
Merge development commits into production
Commit merge
Push changes to github
Github Gets new commit in production
Deploys new files

For more advanced usage, you can setup Capistrano pre and post deployment scripts
Assuming your files are located at /var/www
     rm -rf /var/deploy
     cp -r /var/www /var/deploy
Let github deploy files to /var/deploy
     rm -rf /var/oldwww
     mv /var/www /var/oldwww
     mv /var/deploy /var/www
So except for the one brief nanosecond between renaming www to oldww and renaming deploy to www, your website will just keep running

You could also play around with rsync to syncronize the files in www to deploy instead of deleting it and copying the files over.

It may not be "within" PHPStorm, but it uses PHPStorms native git support


Thank you for the very detailed response Gary have been researching it. On google I have come across a Php based build tool called "Phing" which seems to do simmilar operations to Capistrano tool (but I am still very unsure if it will solve my deployment scenario). If you dont mind, could you please tell me your reasoning for deciding to use it instead of Phing.


Phing requires a server to "live" on to do the deployments.   I use Phing for other purposes[running unit tests, packaging software into zip files, et].  But for deployment, I simply don't want to have to build my own deployment management server.  Using Capistrano through Github, I don't.  Github is already running the deployment server, so all I need to do is setup the configuration files to tell it what to do.

If there was a problem with my personal deployment server, I'd have to fix it, and might not even know about it.   Wheras if there is a problem with Github, someone else is likely to run into it and report it before me, and they will fix it. :-)


Oh, and speaking of phing - PHPStorm will recognize/parse a Phing config file for you and give you a list of tasks you can invoke.   So it would probably be helpful to create a "deploy" phing process which does the branch merge/push to github automatically for you.   I hadn't thought of that, but now I'm going to add that to my process!  Thanks.


I can understand your reasoning and development and deployment flow much better now Gary - Thank you for explaing it in detail! :-)  I'll also let you know if I discover other useful methods
-Thomas P.


Please sign in to leave a comment.