Setup Subversion and Trac on CentOS 5
Recently I set up a virtual server to use as a development machine. It runs on CentOS 5 and hosts several Subversion repositories with associated Trac projects.
There are many guides and plenty of help on the net to help you setup such a system. However, when I tried to do it I came across a few problems and I hope this post may help at least a few people trying to do the same as me. I am not going to rewrite the great tutorials out there, I will just point you to them and note what things I did differently.
This 'guide' should get you from a fresh install of CentOS 5 linux to one or more working Subversion (SVN) repositories and associated Trac wiki's. Apache/WebDAV is used as the network layer. I have only tested this on a fresh install of CentOS 5.
The Environment
I am aiming for the following:
- CentOS 5, SVN installed. Apache2 as the network layer using mod_dav_svn.
- Trac running on Apache with mod_python
- SVN repositories located at: /srv/svn (e.g. /srv/svn/my-project), accessible via http://server/svn/my-project
- Trac projects located at: /srv/trac (e.g /srv/trac/my-project) accessible via http://server/trac/my-project
How I did it
Not all the steps are vital (probably) but this is how I got it working. Feel free to skip any non-relevant steps (i.e. there is probably no need for a fresh install). Replace any occurence of <project> with the name of your first project.
1. Fresh install of CentOS. I followed most of the Perfect Setup Guide, except the mail and ISPConfig stuff. The important part is setting up the Apache2 web server.
2. Make sure SVN and mod_dav_svn are installed. As root:
yum install subversion mod_dav_svn
vim /etc/httpd/conf/httpd.conf
If the following two lines are not present, add them:
LoadModule dav_svn_module modules/mod_dav_svn.so LoadModule authz_svn_module modules/mod_authz_svn.so
3. Install Trac: Follow Nick's guide with the alternative Clearsilver installation below. Skip the Apache Configuration part.
Follow all of parts 1 and 2. Instead of part 3 do:
wget http://dag.wieers.com/rpm/packages/clearsilver/clearsilver-0.10.4-1.el5.rf.i386.rpm rpm -i clearsilver-0.10.4-1.el5.rf.i386.rpm wget http://dag.wieers.com/rpm/packages/clearsilver/python-clearsilver-0.10.4-1.el5.rf.i386.rpm rpm -i python-clearsilver-0.10.4-1.el5.rf.i386.rpm
Continue with parts 4.1 and 4.2 of Nick's guide. Remember, leave out Apache configuration section.
4. Create your first SVN Repository:
svnadmin create --fs-type fsfs /srv/svn/<project>
5. Initialise a Trac project for your new repository:
trac-admin /srv/trac/<project> initenv
For the trac-admin command use the defaults if not sure, giving a descriptive name for the project. The `Path to repository` is: /srv/svn/<project>.
6. Set the correct file permissions for apache
chown -R apache.apache /srv/svn/<project> chown -R apache.apache /srv/trac/<project>
7. Tell apache where to find the new repository. Here we create an additional Apache configuration file specifically for the SVN repositories.
vim /etc/httpd/conf.d/subversion.conf
Add the following directive:
<Location /svn/<project>> DAV svn SVNPath /srv/svn/<project> AuthType Basic AuthName "<project> Repository" AuthzSVNAccessFile /srv/svn/svn-acl-conf AuthUserFile /srv/svn/<project>.htpasswd Require valid-user </Location>
8. Add a repository user:
touch /srv/svn/<project>.htpasswd htpasswd -m /srv/svn/<project>.htpasswd <username>
9. Create the Access Control List for the SVN Repository
vim /srv/svn/svn-acl-conf
Add the following directives:
[<project>:/] <username> = rw
Where <username> represents the username of the repository user you created earlier.
10. Tell apache where to find the new Trac project. Here we create an additional Apache configuration file specifically for the Trac projects.
vim /etc/httpd/conf.d/trac.conf
Add the following directives:
<Location /trac/<project>> SetHandler mod_python PythonHandler trac.web.modpython_frontend PythonOption TracEnv /srv/trac/<project> PythonOption TracUriRoot /trac/<project> </Location> <Location "/trac/<project>/login"> AuthType Basic AuthName "trac" AuthUserFile /srv/trac/<project>.htpasswd Require valid-user </Location>
11. Add a Trac user:
touch /srv/trac/<project>.htpasswd htpasswd -m /srv/trac/<project>.htpasswd <username>
12. Give admin permissions to the Trac user you just created:
trac-admin /srv/trac/<project> permission add <username> TRAC_ADMIN
Where <username> represents the username of the Trac user you just created.
13. Restart Apache:
service httpd restart
You should now have SVN and Trac installed. You will have an SVN repository setup (http://server/svn/<project>) and the Trac wiki (http://server/trac/<project>) associated with the repository.
Please let me know if this helped you. If you come across any problems I will be happy to try and help.
Resources
The last part of CentOS HowTos: Subversion will give you a quick introduction on how to use SVN.
Subversion setup guides: here and here
Trac setup guides: here and here.
ClearSilver template system (used by Trac).
Posted by Daniel Skinner 1 year, 5 months ago
Tags: centos, Guides, subversion, trac, tutorial, version control













Comments
Thanks a lot, just tried this out, left out the trac install, worked first time.
Great howto. Thanks. One small change on your item 4…
svnadmin create -fs-type fsfs /srv/svn/
should be:
svnadmin create –fs-type fsfs /srv/svn/
Note the double dash in front of fs-type.
Regards,
PC
I’m glad it helped you out.
Thanks for reporting the error, I will fix it right away.
This saved me a lot of work. Big Thanks!
Additionally to the steps above I had to add
LoadModule dav_svn_module modules/mod_dav_svn.so
LoadModule authz_svn_module modules/mod_authz_svn.so
to my /etc/httpd/conf/httpd.conf
otherwise I got
Unknown DAV provider: svn
One more thing (just in case anyone else is running into this)
I had to disable SELinux otherwise modpython couldn’t access /srv/trac//VERSION
Glad it helped you out. Thanks for the feedback, I will add that to the guide shortly.
When you yum install mod_dav_svn, you get /etc/httpd/conf.d/subversion.conf, so you don’t really need to make any subversion changes to httpd.conf. Edit /etc/httpd/conf.d/subversion.conf instead.
Thanks Daniel for posting this guide.
I tried to follow this tutorial (but skipped the Trac steps) and just came up some problem on my Centos 5 (latest one)
1. I added these lines
LoadModule dav_svn_module modules/mod_dav_svn.so
LoadModule authz_svn_module modules/mod_authz_svn.so
the apache did not start until I added an other line:
LoadModule dav_module modules/mod_dav.so
2. Everything seem work fine, I can see the successful message as below when type http://localhost/svn
Revision 0: /
——————————————————
Powered by Subversion version 1.4.2 (r22196).
the problem is that i could not able to create, edit or commit the file to repository.
Here is the error message:
Can’t create directory ‘/subversion/svn/db/transactions/0-1.txn’: Permission denied.
Anyone have idea why this happended?
Cheers
Can you create, edit or commit from a command line?
If you can then you might need to ensure the user which apache is running as has permission to write to the files.
On my version apache is the user, so I would try something like:
chown -R apache.apache /subversion/svn/
Let me know it that works!
Hi Daniel,
Thanks for your reply.
1. I could not create, edit or commit from command line at all.
2. Not sure which version apache is for user or root, but all the steps (your guides) above were done under ROOT account
I typed this command line
# httpd -version
and got this respond
Server version: Apache/2.2.3
Server built: Nov 10 2007 12:44:14
3. I did try your suggestion
chown -R apache.apache /subversion/svn/
and also
chown -R apache.apache /subversion
but the same error message came back still.
I’m quite stumped :(
Please let me know if you have any other thoughts.
Cheers,
Dave
[...] Installing Trac on CentOS 5 I’m using Slicehost, but these instructions should work for any hosting provider running CentOS 5. I am not using Subversion (because it sucks and has been slain by Git). If you need SVN support, check out the posts by Nick or Daniel Skinner. [...]
Dave,
Do:
cd /subversion/svn/
ls -la
Do the permissions look reasonable?
If not, try doing a temporary hack: chmod -R 777 to see if that fixes the issue - if it does don’t leave it like that but at least we have identified it’s file/ownership permissions that is problematic.
Hi Daniel,
Thanks very much for helps. The problem was came from SELinux, it actually blocked users from accessing to httpd service.. Phew.. here is the error message from Setroubleshoot
SELinux prevented /usr/sbin/httpd from writing 10-1.txn.Detailed DescriptionSELinux prevented /usr/sbin/httpd from writing 10-1.txn.
If 10-1.txn is a core file, you may want to allow this. If 10-1.txn is not a core file, this could signal a intrusion attempt.
Allowing Access
Changing the “allow_daemons_dump_core” boolean to true will allow this access: “setsebool -P allow_daemons_dump_core=1.”
The following command will allow this access:
setsebool -P allow_daemons_dump_core=1
Please note that the suggestion does not work at all. I disable SELinux by editting /etc/selinux/config and change the SELINUX line to SELINUX=permissive:
Cheers mate.
I also thought I did fairly well. Everything seemed to install and restart, but I get this error
ClearSilver not installed (No module named neo_cgi)
when I browse to my trac url. However, if I go back and revisit the clearsilver rpm instructions, I’m told clearsilver IS already installed. Any ideas?
Try re-installing the python bindings:
wget http://dag.wieers.com/rpm/packages/ clearsilver/python-clearsilver-0.10.4-1.el5.rf.i386.rpm
rpm -i python-clearsilver-0.10.4-1.el5.rf.i386.rpm
Thanks Daniel that did the trick; we are now on Trac ;-)
[...] up a server to use as a development machine. From a standard CentOS 5 installation I have installed SubVersion and Trac. Now I have finally got round to installing phpUnderControl for continuous integration and build [...]
Hey awesome blog! Know anyone who would be interested in part time admin’ing a Linux box? Hit me up!
Hello,
Does this guide remain valid in case of virtual hosts configuration ?
Thanks
Emilien
Hi Emilien,
Yes, this guide will apply to a VHost setup.
You should be able to simply replace the Location directives with VirtualHost directives. The content of the directive remains the same with the addition of the servername and serveralias directives of course.
For the trac login you may want to place the location directive within the trac virtualhost if that is how you would like things setting up.
Let me know how it goes.
Daniel
Yeah, it works well !
Thank you Daniel.
Emilien
Daniel,
I’ve gotten Trac and subversion installed, however i’m using Trac 11.1 and i’m getting a lot of python tracebacks in my httpd error logs:
PythonHandler trac.web.modpython_frontend: File “/usr/lib/python2.4/site-packages/Trac-0.11.1-py2.4.egg/trac/web/main.py”, line 381, in dispatch_request\n env = open_environment(env_path, use_cache=not run_once)
PythonHandler trac.web.modpython_frontend: File “/usr/lib/python2.4/site-packages/Trac-0.11.1-py2.4.egg/trac/env.py”, line 567, in open_environment\n env = env_cache.setdefault(env_path, open_environment(env_path))
PythonHandler trac.web.modpython_frontend: File “/usr/lib/python2.4/site-packages/Trac-0.11.1-py2.4.egg/trac/env.py”, line 571, in open_environment\n env = Environment(env_path)
PythonHandler trac.web.modpython_frontend: File “/usr/lib/python2.4/site-packages/Trac-0.11.1-py2.4.egg/trac/env.py”, line 185, in __init__\n load_components(self, plugins_dir and (plugins_dir,))
PythonHandler trac.web.modpython_frontend: File “/usr/lib/python2.4/site-packages/Trac-0.11.1-py2.4.egg/trac/loader.py”, line 109, in load_components\n loadfunc(env, search_path, auto_enable=plugins_dir)
PythonHandler trac.web.modpython_frontend: File “/usr/lib/python2.4/site-packages/Trac-0.11.1-py2.4.egg/trac/loader.py”, line 39, in _load_eggs\n distributions, errors = working_set.find_plugins(
PythonHandler trac.web.modpython_frontend: File “/usr/lib/python2.4/site-packages/pkg_resources.py”, line 640, in __init__\n self.scan(search_path)
PythonHandler trac.web.modpython_frontend: File “/usr/lib/python2.4/site-packages/pkg_resources.py”, line 669, in scan\n for dist in find_distributions(item):
PythonHandler trac.web.modpython_frontend: File “/usr/lib/python2.4/site-packages/pkg_resources.py”, line 1577, in find_on_path\n for entry in os.listdir(path_item):
PythonHandler trac.web.modpython_frontend: OSError: [Errno 13] Permission denied: ‘/srv/trac/test/plugins’
Any light you can shed on this?
Much appreciated!
Ian
Upon further analysis, SELinux on CentOS5 was the culprit…
That’s nearly always the problem! I would be interested in knowing how to get it working with SELinux in enforcing mode - This is something I will look into.
It’s really very simple… I had to beat my head on my desk before i realized how simple it was, but it’s simple, heh.
From root’s home directory (i use this path, because doing this poops a few files out, and it really doesn’t matter where you do it from) SELinux must be running for this to work.
grep -i ‘Trac’ /var/log/audit/audit.log |audit2allow -M trac
This will create a file called trac.pp, and another called trac.te.
Then, to import it into the kernel:
semodule -i trac.pp
That’s it. You’re done.
Explanation:
audit2allow allows you to create a policy based on the AVC in the audit.log file that SELinux generates. You find the lines that show that the service ‘trac’ has been blocked, and audit2allow uses them to create a policy package (.pp file).
Once you’re done, load the .pp file by using the semodule command.
Oh…
And there’s a way to avoid having to do this with subversion as well… If you put your respository in /var/www, you don’t have to worry about setting up an SELinux policy.
This trick doesn’t work with Trac, you still have to create a policy. I think because python is accessing files.
Excellent - Thanks for the explanation.
My pleasure, excellent tutorial!
[...] I’m using Slicehost, but these instructions should work for any hosting provider running CentOS 5. I am not using Subversion (because it sucks and has been slain by Git). If you need SVN support, check out the posts by Nick or Daniel Skinner. [...]
Thanks you huge, all work, a manual simply fairy tale. It was taken with others in the sum about 5 hours, now all has earned from the first attempt. Thanks.
Hi,
SVN and Trac commands work fine, but when I try to going to the url on the browser I get a 500 error. The error log reports:
[Wed Nov 19 22:40:03 2008] [error] [client 127.0.0.1] PythonHandler trac.web.modpython_frontend: Traceback (most recent call last):
[Wed Nov 19 22:40:03 2008] [error] [client 127.0.0.1] PythonHandler trac.web.modpython_frontend: File “/usr/lib64/python2.4/site-packages/mod_python/apache.py”, line 287, in HandlerDispatch\n log=debug)
[Wed Nov 19 22:40:03 2008] [error] [client 127.0.0.1] PythonHandler trac.web.modpython_frontend: File “/usr/lib64/python2.4/site-packages/mod_python/apache.py”, line 464, in import_module\n module = imp.load_module(mname, f, p, d)
[Wed Nov 19 22:40:03 2008] [error] [client 127.0.0.1] PythonHandler trac.web.modpython_frontend: File “/usr/local/lib/python2.5/site-packages/Trac-0.11.2-py2.5.egg/trac/__init__.py”, line 14, in ?\n __version__ = __import__(’pkg_resources’).get_distribution(’Trac’).version
[Wed Nov 19 22:40:03 2008] [error] [client 127.0.0.1] PythonHandler trac.web.modpython_frontend: ImportError: No module named pkg_resources
Any ideas of what I could be doing wrong?
Thank you.
BTW - I am on CentOS 5.2 and I installed Trac-0.11.2 . SVN version is 1.54. CentOS installs default with Python 2.4, but I installed 2.5 through yum using remi’s repository.
The trac web server brings everything up ok. I am just having a really hard time getting this to work in Apache.
Thank you.
The error you are seeting is a Python exception and ultimately the error is ‘No module named pkg_resources’
It Python setuptools installed?
on the clicent I’m fill usrname and passwork see low
Authorization Required
This server could not verify that you are authorized to access the document requested. Either you supplied the wrong credentials (e.g., bad password), or your browser doesn’t understand how to supply the credentials required.
pls help me
Hi,
You can use Naraio for trac, subversion,Apache and openldap.
It can be downloaded from http://opensourcedevelopment.net.
It is free open source product…..
Regards
hello, you should prefer this solution about selinux ;)
sudo chcon -R -h -t httpd_sys_content_t /srv/svn
sudo chcon -R -h -t httpd_sys_content_t /srv/trac/
subversion explains this trick in link below
http://subversion.tigris.org/faq.html
sorry I spoke to fast about trac,
the solution is here:
http://trac.edgewall.org/wiki/TracWithSeLinux
Hey, thanks for the guide, it was the only one that guided me to a successful Trac configuration (or the only one I could understand, at least). I have a couple of questions:
1. How do I have /trac in the browser to list all my projects? I believe it can be done by Trac.
2. Is there anyway to do the creation of new projects without having to add them every time by hand to httpd.conf? Maybe there is a more practical way?
Thanks in advance.
I’m glad the post was of use to you!
1. I’m not entirely sure - sounds reasonable though.
2. Yes there is. You need to write some form of shell script to make the changes for you. Note there is a non-interactive version of trac-admin you will need to use.
Alternatively, the next evolution of this setup is to use something like Buildix which will elegantly solve 1 and 2 for you by providing a rich integration between Trac, CruiseControl and Subversion, allowing you to easily create and manage projects.
See: http://buildix.thoughtworks.com/
izeen: Your comment is awaiting moderation.
Hi daniel,
Thanks for your excellent work.I have installed as per your suggestion without tracker.I am able to modify my original file and commit so that the modification can be accessed by respective revision numbers in command prompt.When i try to view it in apache i am able to see the files but there is no option of editing or deleting the files.can u help me and also i am getting the error message
while restarting the httpd service but access to the svn repository is working fine
service httpd restart
shell-init: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
chdir: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
Stopping httpd: [ OK ]
Starting httpd: [ OK ]
I have to tell: THANKS!
I still have to understand all steps, because uses of .so modules of APACHE as mod_dav_svn.so are a mistery for me. We don’t use SVN currently. Now Im going to make a post to spanish users of TRAC. I was able to backup/restore from a older version of TRAC. Let me post some doubts in future :D
Bye!
Rubén Ortizs last blog post..Unable to open pty: No such file or directory
[...] http://www.daniel-skinner.co.uk/ [...]
Thank you so much!
Instead of the guide linked in step 3, I just used “yum install trac”. Everything seems to be working great.
This looks really good. The last piece I would like to do is add SSL for some security. Any suggestions?
I was having two problems:
1. Couldn’t log into the SVN repository (at http://server/svn/project) - Apache was writing in the error log that it doesn’t have permission to open the htpasswd file, even after I chmodded it to 777.
2. Accessing the TRAC URL was giving a 500 Internal Server Error and complaining in the log about being unable to load Genshi.
Solution? Disable SELinux.
Great HowTo. It works!
Hey,
i followed your steps and seems to work, but i bound already a VirtualHost to *:80.
So have i to add another VirtualHost with a different ServerName?
Perhaps you can share some infos :)
Thx a lot!
Hey there,
I followed everything and it is working fine. Trac is up and all. Only thing is I can not connect to my SVN server. When I try
svn list I get:
svn: PROPFIND request failed on ‘/svn/’
svn: PROPFIND of ‘/svn/’: 403 Forbidden ()
for my server url I used http://server/svn/ where “server” is the URL where trac is happily running.
any ideas?
Cheers,
P
[...] stumbled upon this article and I must say it’s a great guide for getting both of these applications up and running [...]
Mate… love your work, heaps helpful and will make it in my list of best-of’s!
Ihave cent os 4.7, python 2.3.4 and trying to install trac 0.11.4, after i configured every thing i got this error can any body help me…
Traceback (most recent call last):
File “/usr/lib/python2.3/site-packages/Trac-0.11.4-py2.3.egg/trac/web/api.py”, line 367, in send_error
‘text/html’)
.
.
File “/usr/lib/python2.3/site-packages/Trac-0.11.4-py2.3.egg/trac/db/api.py”, line 111, in _parse_db_str
scheme, rest = db_str.split(’:', 1)
ValueError: unpack list of wrong size