1. Multiple project Trac set-up

    January 3, 2008 by bealers

    I’ve already installed Trac and I now want to be able to set-up multiple projects with the minimum of fuss.

    My requirements are:

    • Not having to mess with the Apache configuration every time I add a new project because I don’t want to have to restart apache
    • Make some simple modifications to the stanadard trac.ini so that, for example, the logo at the top links to the home of that trac project
    • Improve upon the default authentication where logging out involves closing the browser (which is a drag when accessing multiple projects)
    • Change the default wiki page text

    The most important job is to get Apache set-up properly. I’m using mod_python so:
    apt-get install libapache2-mod-python

    I then set-up a VirtualHost for http://my.trac.url, thus:

    <VirtualHost *>
    DocumentRoot /var/www/my.trac.docroot
    ServerName my.trac.url
    ServerAdmin webmaster@my.trac.url
    LogFormat "%h %l %u %t \"%r\" %s %b \"%{Referer}i\" \"%{User-agent}i\""
    TransferLog /var/log/apache2/trac-access.log
    ErrorLog /var/log/apache2/trac-error.log

    <LocationMatch "/.+/">
    SetHandler mod_python
    PythonInterpreter main_interpreter
    PythonHandler trac.web.modpython_frontend
    PythonPath "sys.path + ['/export/trac']”
    PythonOption TracEnvParentDir /export/trac
    PythonOption TracUriRoot /
    </LocationMatch>

    </VirtualHost>

    Note the LocationMatch. From the docs:

    This will instruct Apache to use mod_python for all locations different from root while having the possibility of placing a custom home page for root in your DocumentRoot folder.

    Therefore in /var/www/my.trac.docroot I’ve placed a one line PHP script that redirects users to our main website url.

    After restarting Apache I then set-up a new project ‘project1′ as per my mini Trac install how-to and visiting http://my.trac.url/project1/ gives me the vanilla Trac interface so we know it’s all working.

    The rest of the configuration is with Trac itself and is down to personal requirements and mine are already listed above. I’ve scripted everything I need to do to get a new project up and running and don’t intend to go though it all here. You can however download it and use it for your own purposes. You use this at your own risk and you should bear in mind the following cavets:

    • Assumes that the Account Manager plugin is already installed. I did easy_install http://trac-hacks.org/svn/accountmanagerplugin/trunk
    • The first user input is used as the Trac project name AND should match the name of the already set-up svn project
    • I’m using MySQL on the backend
    • A few of the trac.ini settings at the end are hard-coded though it is easy to change them

    I’m a lot more impressed with this version of Trac than the much older version we were using before and with the above set-up I can now have a project up and running within a few minutes.
    Related
    http://trac.edgewall.org/wiki/TracModPython
    http://trac-hacks.org/wiki/AccountManagerPlugin


  2. Installing Trac on Debian etch

    January 1, 2008 by bealers

    The following is a no-frills install guide for getting Trac up and running on a Debian ‘etch’ Linux system.

    The assumption is that you’ve already got mysql and subversion working and have created a subversion repository (tip: apt-get install mysql-server subversion).

    The first thing that we need to do is install Python, easy_install and the mysql & python bindings:
    apt-get install python python-setuptools python-mysqldb python-subversion

    To install trac via the easy_install command I suggest that you see what is the newest version of trac:
    svn list http://svn.edgewall.com/repos/trac/tags

    I then picked the newest tag and then installed:
    easy_install http://svn.edgewall.com/repos/trac/tags/trac-0.11b1

    I want to use the - note: experimental - MySQL support so I create a mysql db and create a trac user:

    mysql> create database trac;
    mysql> grant all on trac.* to trac@localhost identified by 'password';

    To test it is all working I create our first project:

    trac-admin /export/trac/MY_PROJECT initenv

    A number of self explanitory questions are asked, here are selected answers:

    Database connection string [sqlite:db/trac.db]> mysql://trac:password@localhost:3306/trac
    Path to repository [/path/to/repos]> /export/svn/MY_SVN_REPOSITORY

    Finally, test it is working:
    tracd --port 8000 /export/trac/MY_PROJECT

    Visiting http://server:8000/MY_PROJECT gives me the standard trac web interface and I can browse the SVN repository. There, that wasn’t too bad was it? We do still need to get it all sensibly configured so once I’ve done that I’ll post another article.

    Related:
    http://trac.edgewall.org/wiki/TracInstall


  3. Moving multiple subversion repositories

    December 20, 2007 by bealers

    I had a need to migrate all of our subversion repositories from an overworked machine onto a new dedicated machine. As I had about 30 repositories to copy over I didn’t fancy doing each dump -> copy -> create -> import manually so I came up with the following. Which, amazingly, worked first time. I’d say a total of an hour elapsed from sitting down to start the job to being finished.

    FWIW I’m running Debian Woody on the old machine and Debian Etch on the new one. Subversion was already installed on the new machine.

    So, on the current svn server, dump out all of the repositories:

    cd /export/svn
    mkdir ../svn.dumps

    for REPO in `ls`; do svnadmin dump $REPO > ../svn.dumps/$REPO.dump; done

    Now copy over to the new machine. Ok, you *could* gzip each one first but I didn’t mind having to wait whilst it copied over.

    cd ../
    scp svn.dumps/* root@<other machine>:/export/dumps

    On the new server su to root then and create the new repositories, import the dump files, change ownership and fix the file permissions:

    su -
    cd /export/dumps

    for REPO in `ls | sed -e '/\.dump/s/\.dump//g'`; do
    svnadmin create /export/svn/$REPO;
    svnadmin load /export/svn/$REPO < $REPO.dump;
    chown -R svn:svn /export/svn/$REPO;
    find /export/svn/$REPO -type d -exec chmod 2770 \{\} \;
    done

    (wait quite a while)

    Then create /etc/subversion/passwd and fill it with the contents from the old server.

    Now you can either check out the projects again, or even easier (I didn’t script this bit) switch the location within the checked out project, for example:


    cd /your/sandox/project/
    svn switch --relocate svn://old/sever/repos/trunk svn://new/sever/repos/trunk

    Job done.

    Actually no

    It turns out that I lied and there was one small thing that broke, I forgot to configure the authentication method on each repository in turn so you’d currently only have read access. To fix this all we need do is:

    su -
    cd /export/svn

    for REPOS in `ls`; do echo "password-db=/etc/subversion/passwd
    realm = YOUR REALM" >> $REPOS/conf/svnserve.conf; done

    Which ensures that for each repository svn will use your central password file


  4. Making Windows Server 2003 suck less when rebooting

    March 7, 2007 by bealers

    At the office I run a single Windows 2003 server which also runs Exchange 2003. It has a fat amount of RAM and 4x large SATA disks. Everything else the business needs - a number of Linux servers - run as VM Ware virtual machines on the server.

    Anyhoo, it takes the machine 20 minutes to reboot and this is simply not satisfactory especially bearing in mind that I need to perform some open heart surgery on it in the very near future because I need to rename the domain and simply can’t be arsed to do a fresh install.

    A quick bit of googling came up with this link the contents of which can be summarised thus:

    Fire up regedit and change the following:

    HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\ Control\WaitToKillServiceTimeout: 1000

    HKEY_CURRENT_USER\Control Panel\Desktop\AutoEndTasks: 1
    HKEY_USERS\Control Panel\Desktop\AutoEndTasks: 1

    HKEY_CURRENT_USER\Control Panel\Desktop\HungAppTimeout: 1000
    HKEY_USERS\Control Panel\Desktop\HungAppTimeout: 1000

    KEY_CURRENT_USER\Control Panel\Desktop\WaitToKillAppTimeout: 1000
    KEY_USERS\Control Panel\Desktop\WaitToKillAppTimeout: 1000

    and to make start-up a bit faster:

    HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\ Control\Session Manager\Memory Management\PrefetchParameters\EnablePrefetcher: 3

    HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Dfrg\ BootOptimizeFunction: N (to disable).

    It now takes about 1 min less to start up and has gone from 20 mins to about 30 secs to shut-down.


  5. Creating a subversion repository

    April 7, 2006 by bealers

    This item assumes that you already have svn installed and this is the first time you’ve created a repository for this server (else leave out certain bits)

    All items here worked on our local development server where subversion is already installed but up to now we had only been using it as a client to check out code from remote repositories.

    Create the repository

    [code]svnadmin create –fs-type fsfs /export/svn/ZF_blog[/code]

    edit /export/svn/ZF_blog/conf/svnserve.conf

    making sure
    [general] is un-commented
    passwd-db=/etc/subversion/passwd
    realm=SomeString

    Sort out authentication

    [code]useradd -d /export/svn -s /bin/false -m svn
    groupadd svn
    cd /export/svn
    chown -R svn:svn ZF_blog
    find ZF_blog -type d -exec chmod 2770 \{\} \;
    echo “[users]
    bealers=password” >> /etc/subversion/passwd[/code]

    cd to the folder where your code lies (in the correct structure):

    [code]/ZF_blog/branches
    /ZF_blog/tags
    /ZF_blog/trunk
    /ZF_blog/trunk/[/code]

    Import

    [code]cd ~bealers/tmp/ZF_blog
    svn import . file:///export/svn/ZF_blog/
    [/code]

    Edit the commit notes document, for me it opens up in vi. write/quit and your files should be imported

    Checkout

    [code]svn co svn://localhost/ZF_blog/trunk/ zf.blog
    svn: Can’t connect to host ‘localhost’: Connection refused[/code]

    Ah, this server does not have the svn server running, or inetd to run it on so as an aside:

    [code]apt-get install inetd
    echo “svn stream tcp nowait svn /usr/bin/svnserve svnserve -i -r /export/svn/” >> /etc/inetd.conf
    /etc/init.d/inetd start[/code]

    Checkout (again)

    [code]svn co svn://localhost/ZF_blog/trunk/ zf.blog
    A zf.blog/sql
    A zf.blog/sql/zf.blog.sql
    A zf.blog/codebase
    A zf.blog/codebase/app
    A zf.blog/codebase/app/models
    A zf.blog/codebase/app/models/db
    A zf.blog/codebase/app/models/db/Posts.php
    A zf.blog/codebase/app/controllers
    A zf.blog/codebase/app/controllers/IndexController.php
    A zf.blog/codebase/app/controllers/AdminController.php
    A zf.blog/codebase/app/views
    A zf.blog/codebase/app/views/postForm.php
    A zf.blog/codebase/app/views/~list.php
    A zf.blog/codebase/app/views/list.php
    A zf.blog/codebase/app/views/template.php
    A zf.blog/codebase/htdocs
    A zf.blog/codebase/htdocs/index.php
    A zf.blog/codebase/lib
    A zf.blog/codebase/lib/BealersApplicationController.php
    A zf.blog/codebase/etc
    A zf.blog/codebase/etc/init.inc
    Checked out revision 1.[/code]

    All I need do now is edit a line in the app to add the codebase folder to the application path and do the same again within Apache’s httpd.conf for the VirtualHost for this app.

    Related:
    http://subversion.tigris.org/


  6. Building a PHP development server

    April 2, 2006 by bealers

    Following these instructions will get you a Debian based PHP/MySQL development server set-up with the ability to have multiple developer sandboxes that are accessible from a remote machine on the local network, using Samba.

    Time needed < 1hr

    Install operating system

    If you are following these instructions verbatim then build your machine from a Debian netinst CD. Get networking going and make sure your /etc/apt.d/sources points to a local mirror. FYI I’ve set the server to use DHCP and told my DHCP server to assign it a fixed lease, in this case (192.168.2.110).

    Become root:

    su -

    install some absolute basics:

    apt-get install bzip2 ssh vim

    Install Apache

    apt-get -y --force-yes apache2 apache2-utils apache2-threaded-dev

    I always compile PHP and MySQL from source so I can get whatever is new. As this is a very basic debian install I need a few things before I can start compiling:

    apt-get -y --force-yes install gcc g++ make autoconf automake

    Install MySQL

    First Install a MySQL dependency:

    apt-get install libncurses5-dev

    Get the source:

    cd && mkdir -p build/src && cd build/src

    wget http://downloads.mysql.com/archives/mysql-5.0/mysql-5.0.27.tar.gz

    cd ..

    tar -zxvf src/mysql-5.0.27.tar.gz

    cd mysql-5.0.27/

    Configure and build:

    CFLAGS="-O3" CXX=gcc CXXFLAGS="-O3 -felide-constructors \
    -fno-exceptions -fno-rtti" ./configure \
    --prefix=/usr/local/mysql --enable-assembler \
    --with-mysqld-ldflags=-all-static

    make && make install

    Make it start on boot up automatically:

    cp support-files/mysql.server /etc/init.d/mysqld
    chmod 0755 /etc/init.d/mysqld
    update-rc.d mysqld start 75 2 3 4 5 .

    Do some simple configuration:

    groupadd mysql
    useradd -g mysql mysql
    cp support-files/my-medium.cnf /etc/my.cnf
    cd /usr/local/mysql
    chown -R mysql .
    chgrp -R mysql .
    bin/mysql_install_db
    chown -R root .
    chown -R mysql var

    This server is only for development so I turn off binary logging to save building up massive log files. In /etc/my.conf comment out this line so it look like:
    #log-bin=mysql-bin

    Compile and install PHP

    First install some PHP dependencies:

    apt-get install -y --force-yes flex libssl0.9.7 openssl libcurl3-dev libjpeg62-dev libgd2-xpm-dev libxml2-dev libmysqlclient15-dev

    get the source:

    cd ~/build/src
    wget http://uk.php.net/get/php-5.2.1.tar.bz2/from/this/mirror
    cd ..
    tar -jxvf src/php-5.2.1.tar.bz2
    cd php-5.2.1/

    Configure and build:

    ./configure --with-layout=GNU --with-pear=/usr/share/php --enable-track-vars \
    --enable-force-cgi-redirect --with-openssl=shared,/usr --with-zlib \
    --with-exec-dir=/usr/lib/php/libexec --prefix=/usr --with-apxs2=/usr/bin/apxs2 \
    --with-regex=php --with-config-file-path=/etc/php --with-curl=shared,/usr \
    --with-gd --with-zlib-dir=/usr --with-jpeg-dir=shared,/usr \
    --with-png-dir=shared,/usr --with-mysql=/usr --with-mysql-sock=/tmp/mysql.sock

    make

    Normally we’d ‘make install’ now, but this will break as httpd.conf is blank these days with the Apache 2 package. To trick the PHP installer that things are OK we’re going to add a dummy LoadModule line to httpd.conf. (I appreciate that this is a bit of a hack and slightly magic but as it’s a dev server for PHP then I can live with it)

    So:

    cd /etc/apache2
    echo "
    #LoadModule foo_module /usr/lib/apache2/modules/foo.so" > /etc/apache2/httpd.conf
    (the first line break is important)

    Now we can carry on:

    make install

    ..and copy the standard php.ini to the right place:

    mkdir /etc/php && cp php.ini-dist /etc/php/php.ini

    Then we configure Apache a bit more to make PHP work:

    echo "AddType application/x-httpd-php .php
    AddType application/x-httpd-php-source .phps" > /etc/apache2/conf.d/php

    Check it’s working:

    echo "<?php phpinfo(); ?>" > /var/www/phpinfo.php
    /etc/init.d/apache2 restart

    On the phpinfo screen (got to in my case by going to http://192.168.2.110/phpinfo.php) I check to see whether php.ini has been picked up, that MySQL is there plus other modules I normally have compiled in. Hmm I notice Curl is not loaded….

    A quick check of /usr/lib/php/20060613-zts shows me that curl.so is there so I change extension_dir as follows:

    extension_dir = "/usr/lib/php/20060613-zts"

    and add the line:

    extension=curl.so

    Whilst I’m there, make sure we get to see errors and warnings:

    error_reporting = E_ALL

    Restart Apache and Curl is loaded now.

    Ok so we now have a working web server but we need to be able to easily write files to the document root AND we want multiple developer sandboxes.

    Install Samba

    apt-get -y --force-yes install samba

    Now configure it by editing /etc/samba/smb.conf, I add:

    [homes]
    comment = Home Directory
    browseable = no
    read only = no
    writeable = yes
    available = yes

    /etc/init.d/samba restart

    Add a samba user, making the user name & password the same as the system user name (and ideally the same as the host user name) this makes connecting to the shares from the host a piece of cake as one does not need to specify a user name/password then. For the record it is possible to make Samba’s and the system password automatically update when either is changed but I’ve never got it to work and it’s not really a big deal to change a few passwords now and again, so the following suffices:

    smbpasswd -a bealers
    (enter password)

    If you are on Windows to check that it worked open up Windows explorer and enter \\192.168.2.110 into the address bar; you should see your home directory. Assuming that you can write to it then you can map a drive and your job is nearly done. The final job is to configure Apache to work from your home directory. I simply chrgp my home dir to www-data (the Apache user) and create a new virtual host container:

    chgrp /home/bealers www-data
    mkdir ~bealers/www && chown bealers.bealers www

    echo "<VirtualHost *>
    ServerName dev.bealers
    DocumentRoot /home/bealers/www
    <Directory>
    Options FollowSymLinks Indexes MultiViews
    AllowOverride All
    </Directory>
    ErrorLog /var/log/apache2/bealers.error.log
    LogLevel warn
    CustomLog /var/log/apache2/bealers.access.log combined
    </VirtualHost>" > /etc/apache2/sites-available/dev.bealers

    cd /etc/apache2/sites-enabled/
    ln -s ../sites-available/dev.bealers

    Assuming that you’ve internal DNS (or a horribly long hosts file) make sure that dev.bealers resolves to 192.168.2.110. Now popping http://dev.bealers into my browser gives me an (empty) directory listing for /home/bealers/www/, which is right.

    You can now either develop direct to the dev server or copy and paste the files over when you need to.

    In summary: onto a very basic Debian we installed Apache as a Debian package and MySQL/PHP were compiled from source; that gave us our web-server. As we want to easily save our changes and view them immediately without having to faff with FTP or SSH we write directly to the web root of our own sandbox on the server, to facilitate this we use Samba (although there are other options such as NFS).

    Enjoy.

    This page is updated when something notably changes. Last update April 07 when Etch became stable.


/div>