views:

401

answers:

3

Hi, I've read a number of topics in the same sort of ballpark as this one, but in all honesty I'm still not exactly sure on the best approach (as a starting point). I am a solo developer in a small office and I have around 30 websites which are hosted on a linux VPS. I want to start using using version control (probably SVN) and also set up a staging server. At the moment, I do development either locally on my machine before using FTP to upload to the live server, or ocassionally for small changes I edit the remote files directly, which is not an ideal approach.

I'm looking for some guidance on how to improve my development environment. I imagine I should be installing SVN on the web server, which would then allow me to check out versions to my local machine (which would also require SVN i think). Also, if I want to set up a staging server, should I just set up subdomains for each of the live websites, then use these subdomains for showing clients changes to the site before making them live?

Hope this makes sense!

A: 

You can actually install the SVN server on your local machine, which I would recommend in lieu of installing it on the web server (assuming you make backups). The easiest thing to do, since it’s only you using it, would be to use the file:// protocol, but using svnserve is a little more robust, and the preferred method if you want to take the time to do it.

Michael Hackner
If you are going to have a repo on your server and your home, why not just use something like git, which has been built from the ground up for doing that sort of stuff.
Chacha102
The OP did not suggest that he was considering having multiple repositories.
Michael Hackner
A: 

@Michael, I disagree - I would say it's better to install on the linux vps, especially if you are already paying for the hosting service. I find it very helpful to be able to browse and download stuff from my svn repo wherever I am, from whatever computer I'm on.

@nicky, I started with svn (and version control) several years ago and I took baby steps which made it easier to tackle.

If I had to do it over again, I'd read the svn book to start with. The book is very well laid out and didn't take more than 1-2 days to plow thru.

While you're reading, install svn on your linux vps with an apache front end.

Once you have that up, pick one of your websites and import it into svn. This is how I structure my svn repo. For example, say my repo is hosted at http://mysvn.mydomain.com/svn/:

  mywebsite1
     - trunk
     - tags
     - branches 
  mywebsite2
     - trunk
     - tags
     - branches

Don't worry about creating the perfect structure. It's pretty easy to re-organize especially when you're starting out. After you import a few projects into svn, you'll start to get a feel for which projects should have their own "trunk/tags/branches" dir structure and which can be combined.

For creating test environments, I do exactly what you describe. I use build scripts to checkout from svn and download files into dirs that are mapped to subdomains like "test.clientsite.com" (I work primarily in java and use ant and maven, but I think you can use whatever scripting language you're familiar with).

Once you get used to version control, you'll never go back, good luck!

Dave Paroulek
Fair enough; I only recommended it because the barrier to entry is slightly lower, and as we all know, the most important thing with version control is to start using it as soon as possible! :-)
Michael Hackner
Yeah, good point, it's good to get up and going as soon as possible but still think it's worth the effort to install remotely.
Dave Paroulek
Thanks Dave - this is a good starter for me. I'll set up SVN on the VPS first, as you suggest, then get familiar with it with one website before moving on to the next step. I'll spend some time going through the book and hopefully that'll be on the right track!
nicky77
I've installed SVN on my web server now and am just wondering where would be a sensible place to host the repos, given that the repos should be accessible via a URL - would you create a user account, then access it, for example, as follows - http://serverIP/~nicky/repos/?
nicky77
+1  A: 

This is what we do at work:

We have a staging server running Apache and a Subversion server. We have a post commit hook that updates a working copy in the htdocs directory, that way, when a developer commits something it automatically gets updated on the staging server, so everyone can see the latest code.

On the client's production servers (the ones we can control) we have the Subversion client installed and the website is a working copy. When we need to update the live site we login to a shell and run svn up. If you do something like this, make sure to limit access to the .svn directories, either with .htaccess files or from the main Apache config.

We have a custom app that manages the projects, but that is only because we're lazy and don't want to setup each project by hand, the app creates the necessary directories and working copies. You could write a quick script to do this.

We never, ever, edit files via FTP on the live site. All in all we have been using this setup for almost 2 years and aside from the occasional conflict on the staging server, we never have had any problems.

Dinu Florin
Out of curiosity; #1. Do you version all files, such as images too? Websites I work with often reside in a cms that upon image upload preserves a high-res version of the image as well as several smaller variations => can quickly become significant amount of data. #2 How do you solve the database bit. Does the staging server run against the same database as the live, or do you set up a "staging database" as well?
Tommy
1) Depends on the website, on some we version the images on others we don't. We never had any problems with the size of the repo even on large projects.2) We have a staging database, we have a port opened and a "test" user so each developer connects to the staging database from his local install.We learned trough some bad experiences that we should never develop on the production system, be that code or database changes, even the content is staged before hitting production.
Dinu Florin
Thanks for the reply, Dinu :) I can fully understand the approach, but it seems "cumbersome" to do all that, setting up a new database and all, when it's something really small that needs to be done. If you do this on all changes no matter size, which sounds smart, how much time do to estimate it adds to making the changes? Is it ever an issue getting the client to accept that the tiniest change will take a conciderable amount of time?
Tommy
Setup for a new project takes a couple of minutes, the database is created automatically we just do an import for the tables.The clients don't mind, they feel safer knowing that they can preview the changes before going live. Of course for a minor content change, or minor code fix we don't wait for the client to give his approval. With some good commit hooks you can do wonders :), our commits go to staging immediately, so it doesn't take longer than hitting commit. It takes a while before you get used to it, but believe me, it's worth it.
Dinu Florin