I tried to make a good tutorial to figure out, how to install trac 1.1.2-dev on ubuntu 12.04. This was mainly done as a walkthrough for me, and I hope that you ‘ll find nice too.
I asume that you have a fresh install of ubuntu 12.04, so you firstly have to do:
sudo apt-get update
sudo apt-get upgrade.
Out of our scope I am just saying that, I allways want to take the role of root, even on an ubuntu linux system so the first thing I do is:
sudo passwd root
after setting a password for a root user, you are able to do:
and then you are logged in a root session.
One more thing that helps me a lot is to set bash_autocompletion for root user. This is tricky and easy in Ubuntu. You have to edit the the .bashrc file in your home directory. For the root user is:
so lets do it:
and then just comment out the 3 last lines in this file and more accurately these 3 lines:
if [ -f /etc/bash_completion ] && ! shopt -oq posix; then . /etc/bash_completion fi
now we are ready to proceed to the installation guide.
install trac 1.1.2-dev on ubuntu 12.04
lets apt-get install all packages needed:
apt-get -y install python-setuptools python-genshi python-genshi-doc mysql-client-5.5 mysql-server-5.5 python-mysqldb python-babel python-docutils enscript subversion git apache2 libapache2-mod-python mercurial python-dev python-pygments
I hope that I haven’t forget a package 😛
At the time of installing mysql-server-5.5 you will be asked to set a root password for the database server. Choose one to enter. After the successful installation of mysql server and all the other package, lets prepare our database server for the trac installation.
use the mysql client you just installed:
mysql -u root -p
enter the root password you have chosen
In this section I have to say that for each trac project you will need a database, so lets the database a relative name. I named mine trac_myproject. So enter on mysql console the following commands:
CREATE DATABASE trac_myproject DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_bin;
GRANT ALL ON trac_myproject.* TO tracuser@localhost IDENTIFIED BY 'tracpass';
tracuser and tracpass in the above example are just example names.
Now write down the db connection string, that you will need when you will create your first trac project.
As an advice I ‘ll say that you shouldn’t use the char @ as member of the password beacuse trac will fail to make the connection to the database.
Once we are ready with the database lets get our hands dirty with trac!
Trac latest dev and TracMercurial plugin installation
we have to get the sources for the trac and TracMercurial:
I got the clones of these repositories to my root directory:
svn co http://svn.edgewall.org/repos/trac/trunk/
hg clone http://hg.edgewall.org/trac/mercurial-plugin#1.0
get into the directory trunk
python setup.py install
get into mercurial-plugin directory
python setup.py bdist_egg
After this procedure a python egg file has been created for the plugin, which we will copy into our project’s folder later. After this procedure we can use trac commands to create environment to create projects and more.
Create our trac environment directory
We can now create our trac environment diractory. You can initialize anywhere you want. My opinion is to create a directory under /usr/share/ directory named trac. Under this directory you can deploy your trac projects. Keep in mind that this directory will be exposed to web access.
trac-admin /usr/share/trac/myproject initenv
now you will be asked for a name of the project and the db connection string for this project ( mysql://tracuser:tracpass@localhost:3306/trac_myproject )
chown -R www-data:www-data /usr/share/trac/myproject
with the trac-admin command we created and initialized a project environemnet. Now you can create and initialize as much projects as you want under /usr/share/trac directory
We changed the group and owner of the project directory to apache user (www-data) to the project because we will now setup apache with mod_python module to serve the trac projects.
Usually main apache configuration file is /etc/apache2/apache2.conf, and we will edit it a litle to use python module for apache.
Add the following lines at the end of the file:
<Location "/trac"> SetHandler mod_python PythonInterpreter main_interpreter PythonHandler trac.web.modpython_frontend PythonOption TracEnvParentDir /usr/share/trac PythonOption TracUriRoot /trac </Location>
You should now check if module mod_python is enabled. Check if a file python.load exists under /etc/apache2/mods-enabled/ directory. If it does not exist create it your self:
and add this line to the file:
LoadModule python_module /usr/lib/apache2/modules/mod_python.so
If you want basic authentication via apache then add to the /etc/apache2/apache2.conf file the following lines:
add the following
<LocationMatch "/trac/[^/]+/login"> AuthType Basic AuthName "Trac" AuthUserFile /etc/trac/trac.htpasswd Require valid-user </LocationMatch>
save and exit
htpasswd -c /etc/trac/trac.htpasswd admin
enter a password for the admin user
Now restart apache:
service apache2 restart
You can now visit the http://your-ip/trac/ or if you want to visit it locally http://127.0.0.1/trac/
I installed trac to a remote server so I visit my projects by using it’s ip. Keep in mind that you should check for firewall settings to allow access to port 80.
Configure the project to use TracMercurial
now we should copy the python egg file we created when installing the TracMercurial plugin into project’s plugin directory.
cp /root/mercurial-plugin/dist/TracMercurial-22.214.171.124dev-py2.7.egg /usr/share/trac/myproject/plugins/.
the name of the egg may vary depending of the dev version.
now lets make a profile for the mercurial, because it will be needed at next steps.
and add the following lines by your needs.
[ui] username = Administrator <admin@trac>
Ofcourse this is a test environment, and we will create the repository inside the trac project directory. In an mercurial server environment you can include the actual repository directories.
mkdir -p /usr/share/trac/myproject/hg/
now lets init a hg project
hg init (project-directory) cd (project-directory) ------ (add some files) ------ hg add hg commit -m 'Initial commit'
Our last configuration step is to configure project see the repository
check if these lines exist and if not, add them
[hg] node_format = short show_rev = yes
[components] tracext.hg.* = enabled
then under [trac] tag edit the corresponding to match:
repository_dir = /usr/share/trac/myproject/hg/(project-directory) repository_type = hg
now you should do one more time:
chown -R www-data:www-data /usr/share/trac/myproject service apache2 restart
I hope that all work fine!!!