Please note that I’m no expert of doing some server stuff or what so ever, I wrote this tutorial based on my trial and error by using my company shared hosting server. By the way, I’m using CentOS Linux. To find out what Linux version/distro that you use, use this command: cat /etc/issue
Let’s just get to the point shall we:
1. Install SVN by run this command:
yum install mod_dav_svn subversion
After that, check whether your SVN is successfully installed by running this command:
If you see something like this below, then you’re good to go:
usage: svn [options] [args]
Type "svn help " for help on a specific subcommand.
Most subcommands take file and/or directory arguments, recursing
on the directories. If no arguments are supplied to such a
command, it will recurse on the current directory (inclusive) by
default.
2. Create a user for SVN by using this command:
htpasswd -cm /var/www/svn-auth-conf yourusername
Press Enter, then after that you need to key in your desire password as well.
To create another user, use this command:
htpasswd -m /var/www/svn-auth-conf anotherusername
3. Create your repository folder to save all your repository under /var/www/ by using this command:
4. Go to folder etc/httpd/conf.d And open the file subversion.conf by using this command:
, and edit the file so it will look like below:
LoadModule dav_svn_module modules/mod_dav_svn.so
LoadModule authz_svn_module modules/mod_authz_svn.so
<Location /repos>
DAV svn
SVNParentPath /var/www/svn
AuthType Basic
AuthName "Subversion repos"
AuthUserFile /var/www/svn-auth-conf
Require valid-user
</Location>
After that, restart your server by using this command:
/etc/init.d/httpd restart
5. Now we need some URL to access the SVN. Let say you already have some URL/domain say: http://svn.your-domain.com
Then after that, open your httpd.conf or virtual-hosts.conf file (usually you will find it under folder /etc/httpd/conf.d/ ) and add the line like below:
<VirtualHost *:80>
ServerName svn.your-domain.com
DocumentRoot "/var/www/svn"
ErrorLog logs/svn-err_log
CustomLog logs/svn_log common
</VirtualHost>
Restart your server once again.
/etc/init.d/httpd restart
From this step, you should already be able to access http://svn.your-domain.com/repos
6. Now it’s time to create a repository for one of your project.
Let say your files/folder of your web project is in this folder: /var/www/html/yourproject/
Go to folder /var/www/svn and use command below:
svnadmin create --fs-type fsfs yourproject
chown -R apache.apache yourproject
/etc/init.d/httpd restart
Now you just created a folder named yourproject under /var/www/svn/ to contain the repository of your web project later.
Then we need to import the web project under /var/www/html/yourproject/ to /var/www/svn/yourproject/ by using this command:
svn import /var/www/html/yourproject/ file:///var/www/svn/yourproject/ -m 'Initial import'
Then go to your root folder of where your project lies /var/www/html/ and run this command:
Please note: you might want to rename yourproject folder in to something else before run the command below.
svn checkout file:///var/www/svn/yourproject
That’s it, you managed to create repository of your web project files/folder. But there’s one more thing need to do. Let’s go to the next step shall we.
7. We need to setup automatic update to the web project every time we make commit to the repository. Here’s how.
Go to folder /var/www/svn/yourproject/hooks. Create a file name svnupdate.c and put the code below inside that file:
#include <stddef.h>
#include <stdlib.h>
#include <unistd.h>
int main(void)
{
execl("/usr/bin/svn", "svn", "update", "/var/www/html/yourproject",
(const char *) NULL);
return(EXIT_FAILURE);
}
And compile the file by using the command below:
gcc -o svnupdate svnupdate.c
And change the file ownership to root and set the permission also
chown root.root svnupdate
chmod +s svnupdate
Test your compiled code by running the command below:
If you see notification something like below, then your compiled code is success:
After that, still under folder var/www/svn/yourproject/hooks, copy-paste file post-commit.tmpl, then name it to post-commit (without any extension) and put the code below:
#!/bin/sh
/var/www/svn/yourproject/hooks/svnupdate
And change the file permisson
Restart your server.
OK, that is a wrap.
To test out the repository, download TortoiseSVN, access the repository by using this URL http://svn.your-domain.com/repos/yourproject and login using your user name and password from step 2.
If there’s something that you still don’t understand, please feel free to put in some comments, I will try my best to help you :-)
Same thing as well if you want to add something that I might miss in this tutorial.
Thanks
Recent Comments