1. Installing Subversion
Use apt-get:
sudo apt-get update sudo apt-get install subversion
2. Creating a Repository and SVN user
Let’s say you want your repository to be in /home/svn/repos, type in these commands:
cd /home sudo mkdir svn cd svn sudo svnadmin create repos
In order to control who has access to the repository, we will now add a user who will own the repository files.
Adding a user also adds a group with the same name.
sudo adduser svn
Now make it impossible for anyone to log in as this user by editing /etc/passwd to set the svn user shell to /bin/false.
Do this using the following command
sudo nano /etc/passwd
Find the line which starts svn (it should be the last line in the file) and change /bin/bash to /bin/false.
Now change the owner and group of the svn directory. If you are in svn/ directory, CD (=Change Directory) to /home, so type in
cd /home sudo chown -R svn:svn svn
This command will recursively change the owner and group of all files and folder under svn directory to user svn.
In order for someone to be permitted to use the repository they must be added to the svn group. My user name is asrar so I am going to add myself to the svn group by using the following command
sudo usermod -a -G svn asrar
3. Configure your newly created SVN repository
The configuration file for the repository is created as “/home/svn/repos/conf/svnserve.conf” and contains the option to enable password protection as well as a lot of other useful settings. The important lines to uncomment to force password access are:
anon-access = none auth-access = write
By setting “anon-access” to “none” you force people to enter passwords on connecting to the SVN. Just make sure there are no spaces in-front of those two lines. Otherwise some error will be occurred.
Now set up password protected access by uncommenting the following:
password-db = passwd
Settings “password-db” to “passwd” means the list of users and passwords in the “/home/svn/repos/conf/passwd” file will be used to check if someone has access. In a lot of cases it makes sense to keep this “passwd” file somewhere else so it can be used for all your repositories. In my case I set it to:
password-db = /home/svn/passwd
Just make sure to set the passwd file to be only readable by root:
sudo chmod 600 /home/svn/passwd
The “passwd” file is actually a very simple text file and looks something like:
[users] harry = harrypassword sally = sallypassword asrar = cheerup
4. Import your project to repository
Assuming you’ve put your project files are in a different place in /home/user/htdocs/magento. Now type in the following commands
cd /home/user/htdocs svn import . file:///home/svn/repos/magento -m"Initial project import" Take a note at magento directory. By adding this directory, svn will import all files from current directory (=/home/user/htdocs) to a separate directory named magento in /home/svn/. But we will not be able to see this directory under /home/svn/. This directory will only be used by Subversion (svn). This approach is very good to use different projects under one Subversion. Also make sure you insert a message while importing with -m "Some message". Otherwise you will be shown a text editor with the following line svn import this line and those below will be ignored But, like always don't be taken out by this just press CTRL + X and when shown Abort/Cancel/Continue press button for Continue.
5. Install openssh-server (if needed)
This step is optional. Now set up an ssh server, clients will connect to this machine using ssh:
sudo apt-get install openssh-server
6. Access your repository
The repository can now be accessed in two ways.
By using the svn+ssh protocol. Test this as follows:
svn co svn+ssh://username@domain.com/home/svn/repos
Or by using just svn protocol like below:
svn co svn://192.168.0.2/svnrepos/myyrailsproject
That’s all for now. Ohh and don’t forget to comment..healthy ones 😉