Josh Kendall

Subversion in the Cloud

Update: I've hit a roadblock where I can checkout from my repositories, but not commit to them. I get a 170001 authentication error; I don't want to use Apache+Mod_SVN. I want to just run nginx, so I'll looking for any info on doing just that.

Setting up your own Subversion server on the cloud is extremely easy; with unlimited users and repositories, it's a much better option than some of the hosted solutions. Since I'm a fan of the Rackspace Cloud, this article will cover how to setup one of their servers running CentOS Linux 5.4. I'm also a Mac user, so when I say type something in Terminal just read that as type this in [your favorite ssh app here].

Setup

Create a new 256mb server from within your control panel and make sure you choose CentOS 5.4 as the operating system. Once your server is ready and you receive the email with your ip address, username, and password; open Terminal.app and ssh to your server with the following command and then enter your password when prompted.

Installing nginx and Subversion

Once logged in we need to include the EPEL (Extra Packages for Enterprise Linux) repository so that we can install nginx. We do this by entering the following into Terminal and press enter:

Once that's done type the following into Terminal and press enter to install both nginx and Subversion, you'll be asked if it's ok to install the software; press "y", then enter to continue the installation. You may also be asked about importing the EPEL GPG key, again press "y" followed by enter to continue.

Configuring nginx

We need to make some changes to the nginx configuration before we continue, these aren't necessary, but can be helpful. Open the configuration file using the nano command in Terminal.

Now that the configuration file is open we need to change a few lines, specifically the ones for worker_processes, tcp_nopush, and keepalive_timeout. You will also need to make sure to uncomment both the tcp_nopush and gzip on; lines.

These are what you should change each to say:

Now, if you plan on also hosting websites on there you'll want to add the following directly under the gzip line.

Press Ctrl+X to exit; then press "y" followed by enter to save your changes. Now we need to setup a virtual host so that you can actually access your repositories through remote connections with third-party apps like Versions. To do this we edit the virtual host config file like we just did the nginx config file.

Now, there's going to be existing data in this file; since it's all commented out, I suggest just removing it by pressing Ctrl+K until everything is gone. Next we need to enter the following information, changing the svn.domain.com to whatever domain you want to use for accessing your SVN repositories.

This sets our site up so that its web root is our repository root and our configuration folder is not accessible. You'll be able to access your repositories from third-party applications or through Terminal by checking out from svn.domain.com/repo_name/ once we finish the next few sections. But first we need to create the directories we referenced so enter the following into Terminal:

Starting nginx and creating repositories

Now is a good time to start nginx as we've completed all of the configuration for it, we do this by running the following command:

We also need to make sure it automatically starts if the server reboots, so to do that we need enter the following into Terminal.

One final thing we need to do for both nginx and Subversion is to allow their default ports in the iptables. So to do that we need to enter the following into Terminal:

If you were to browse to the domain you setup for SVN right now you should see a "Welcome to nginx on EPEL!" page. The final few steps are setting up the repositories and adding users. To add a user to your repositories you need to edit (or create) a passwd file.

If your file has data in it move to the line directly below where it says [users] and enter your username in username = password format. If your file is empty you will need to create the line that says [users] and then create your username/password line. Save and exit the file, then we'll create/edit the svnserve.conf file.

This file only needs to have the following information in it:

Now that we have that saved, we will create our repositories; we do this with the handy svnadmin command (replace "repo_name" with the actual name you want for your repository).

You can even nest multiple repositories into subfolders if you wish:

Final steps

Now that we've configured everything for Subversion and created a repository or two; we need to actually start the Subversion server.

Just like nginx we want Subversion to start automatically on reboot, so we need to edit our crontab file to do just that.

Once open press Shift+i to enter Insert mode; now enter the following:

Press the ESC key, type :w and press enter to save the file; now type :q and press enter to exit the editor.

That's it, you should be able to checkout and commit to your repositories using the same tools you normally do. Just remember that you access your repositories using the domain name you setup in the virtual host followed by that repository name (e.g. svn.domain.com/repo1).

Comments are closed.