Thursday 9 April 2015

SVN and SVN Manager on Ubuntu 14.04.02

Today I had to install a new SVN server with SVNManager. I used the following instructions taken from THIS site.

How to install svn for apache and svnmanager on Ubuntu

This tutorial will guide through installation of subversion on Ubuntu to work with apache, and then installing svnmanager. Svnmanager is a handy tool that lets you manage the users and repositories through the web interface. Before we begin, make sure you have a lamp server setup on Ubuntu.
First, lets install subversion and apache library:


sudo apt-get install subversion libapache2-svn
Lets create the directories in which svn repositories and configurations will reside and give apache access to them:


cd /srv
sudo mkdir svn
sudo mkdir svnconfig
cd svn
sudo mkdir repos
sudo chown -R www-data.www-data /srv/svnconfig /srv/svn
In the terminal run the following commands:
sudo a2enmod dav_svn
sudo a2enmod authz_svn
sudo service apache2 restart
sudo /etc/init.d/apache2 restart
Next, we need to set up apache and allow access to subversion repository:


sudo gedit /etc/apache2/mods-enabled/dav_svn.conf
Uncomment the lines like below, file names will be created at a later stage by svnmanager:
<location /svn>
# Uncomment this to enable the repository
DAV svn

# Alternatively, use SVNParentPath if you have multiple repositories under
# under a single directory (/var/lib/svn/repo1, /var/lib/svn/repo2, ...).
# You need either SVNPath and SVNParentPath, but not both.
SVNParentPath /srv/svn/repos

# Basic Authentication is repository-wide. It is not secure unless
# you are using https. See the 'htpasswd' command to create and
# manage the password file - and the documentation for the
# 'auth_basic' and 'authn_file' modules, which you will need for this
# (enable them with 'a2enmod').
AuthType Basic
AuthName "Subversion Repository"
AuthUserFile /srv/svn/htpasswd

# The following three lines allow anonymous read, but make
# committers authenticate themselves. It requires the 'authz_user'
# module (enable it with 'a2enmod').
Require valid-user

# To enable authorization via mod_authz_svn
AuthzSVNAccessFile /srv/svn/accessfile

</location>
Lets restart Apache:


sudo /etc/init.d/apache2 restart
Now lets create a new user in MySql for svnmanager. Get to mysql client using this command:


sudo mysql -u root -p
Type in your password and execute this mysql command:


CREATE DATABASE svnmanager;
GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, ALTER on svnmanager.* to svnmanager identified by 'password';
FLUSH PRIVILEGES;
Where password should be replaced by your password.
Next, if you followed my tutorial on installing lamp, you may need to add php-pear as it was not added previously. Got to the terminal and type:


sudo apt-get install php-pear
Next, lets install the pear VersionControl_SVN module, type:


sudo pear install -f -o VersionControl_SVN
Now we are ready to install SVNManager. Download the latest package, I’ll get mine from http://svnmanager.org, at the time of writing the latest is 1.08. The file itself is at http://prdownloads.sourceforge.net/svnmanager/svnmanager-1.08.tar.gz I am going to download the tar.gz one in my Apache web directory which is /var/www/ :


cd /var/www/
sudo wget http://prdownloads.sourceforge.net/svnmanager/svnmanager-1.10.tar.gz
Now lets untar (Ubuntu tar tutorial) it:


sudo tar xzf svnmanager-1.10.tar.gz
I will rename the folder for convenience:


sudo mv svnmanager-1.10 svnmanager
Now the fun part, lets copy and open the configuration file:


cd svnmanager
sudo cp config.php.linux config.php
sudo gedit config.php
Here you can start changing the language and htpasswd locations if you need. Since I have default installation and everything seems correct, I move to the next lines for svn locations:


$svn_config_dir = "/srv/svnconfig";
$svn_repos_loc = "/srv/svn/repos";
$svn_passwd_file = "/srv/svn/htpasswd";
$svn_access_file = "/srv/svn/accessfile";
$svn_trash_loc = "/srv/svn/trash";
Now if you have smtp server, you need to specify it in order for email notifications to function, which is a pretty nice feature in svnmanger. To intall smtp server just for the sake of experiment, you can just type ‘sudo apt-get install postfix’ and leave it with no configuration option. You can reconfigure it later with ‘sudo dpkg-reconfigure postfix’.


$smtp_server = "yoursmatpserverurl";
Next, database configuration, replace ‘yourpassword’ with password you made for svnmanager user:


$dsn = "mysqli://svnmanager:yourpassword@localhost/svnmanager";
Now save the file and restart Apache:


sudo /etc/init.d/apache2 restart
Go to http://localhost/svnmanager/ and you should see the message that the tables have been created. Reload the page and login with ‘admin’ ‘admin’, which we left untouched in the configuration file. Don’t worry, once you login and create admin user, config credentials will not work. Go to create your new user, set him as admin and type ‘admin’ in the lowest ‘password’ box, which is your current default password.
You are now set with SVNManager, which, I believe, significantly helps to manage multiple users and repositories.
Phew, took me forever to write this post as I was installing svn and svnmanager at the same time. Please let me know how it works for you. :)
Update: once you create a repository, try to access it in browser at http://localhost/svn/your_repository_name/ . If it shows 500 Internal Server Error, you may have to go back and edit /etc/apache2/mods-available/dav_svn.conf and change the line AuthUserFile to:
AuthUserFile /srv/svn/passwdfile
since the file htpasswd may not exist and cause this error to happen. Just checked my apache logs and this was the problem.
Another update: I did a postfix install on Ubuntu to send mail and updates to repositories to the needed users (handy feature). However, I had problems with svnmanager sending the mail. I checked my /var/log/mail.log and was getting:
Aug 26 13:02:00 my-ubuntu postfix/smtpd[13809]: connect from localhost[127.0.0.1]
Aug 26 13:02:00 my-ubuntu postfix/smtpd[13809]: warning: Illegal address syntax from localhost[127.0.0.1] in MAIL command:
Aug 26 13:02:00 my-ubuntu postfix/smtpd[13809]: lost connection after RSET from localhost[127.0.0.1]
Aug 26 13:02:00 my-ubuntu postfix/smtpd[13809]: disconnect from localhost[127.0.0.1]
The problem seemed to be that my hostname was an ip address, which needs to be in square brackets like svnmanager@[192.168.1.5]. Then I edited the mail functionality:


/var/www/svnmanager/svnmanager/UserModule$ sudo gedit InvitePage.php


where you can edit $mail->From = “svnmanager@[$servername]“; by adding those square brackets. Also, you can edit the $message if needed.
Also, may need to edit InviteManagePage.php in the same folder to suit your needs.

No comments:

Post a Comment