How to get started deploying PHP applications from a subversion repository?

Andrew picture Andrew · Apr 29, 2009 · Viewed 9.6k times · Source

I've heard the phrase "deploying applications" which sounds much better/easier/more reliable than uploading individual changed files to a server, but I don't know where to begin.

I have a Zend Framework application that is under version control (in a Subversion repository). How do I go about "deploying" my application? What should I do if I have an "uploads" directory that I don't want to overwrite?

I host my application through a third party, so I don't know much other than FTP. If any of this involves logging into my server, please explain the process.

Answer

troelskn picture troelskn · Apr 29, 2009

Automatic deploy + run of tests to a staging server is known as continuous integration. The idea is that if you check in something that breaks the tests, you would get notified right away. For PHP, you might want to look into Xinc or phpUnderControl

You'd generally not want to automatically deploy to production though. The normal thing to do is to write some scripts that automates the task, but that you still need to manually initiate. You can use frameworks such as Phing or other build-tools for this (A popular choice is Capistrano), but you can also just whisk a few shell-scripts together. Personally I prefer the latter.

The scripts themselves could do different things, depending on your application and setup, but a typical process would be:

  • ssh to production server. The rest of the commands are run at the production server, through ssh.
  • run svn export svn://path/to/repository/tags/RELEASE_VERSION /usr/local/application/releases/TIMESTAMP
  • stop services (Apache, daemons)
  • run unlink /usr/local/application/current && ln -s /usr/local/application/releases/TIMESTAMP /usr/local/application/current
  • run ln -s /usr/local/application/var /usr/local/application/releases/TIMESTAMP/var
  • run /usr/local/application/current/scripts/migrate.php
  • start services

(Assuming you have your application in /usr/local/application/current)