Debugging with PhpED and DBG

As long-term PhpED user I’ve always been well aware that I was not making the most of some of the more powerful features of my IDE, particularly the debugging capabilities. Well this week I finally got debugging set-up properly and as per most of my other blog posts I’m listing what I did here for future reference and just in case it helps anyone else. Continue reading

Multiple project Trac set-up

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

Vim auto indenting

I used to get annoyed when pasting text into a Vim window as each line would indent one more tab than the last line.

To fix it I used to add set noautoindent in /etc/vimrc, however this unsurprisingly turns off auto indenting, which is a useful feature for normal typing.

Today I came up with a definitive solution to this by setting a key binding for ‘pastetoggle’. Now in vimrc is the line:

set pastetoggle=<F11>

..meaning that should I need to paste in some formated text I simply press F11 when in insert mode to enter paste mode, paste my text in and then F11 again to exit paste mode (but still be in insert).

One could also do :set paste and :set nopaste, but this was far too much typing for my liking.

Note: This is working for me in Vim 7.0

Subversion over ssh

My background task over the Christmas holidays was to ensure that I had the ability to give read/write access to a subversion repository situated on a machine within our corporate network so that staff or external contractors can access it via the interweb but without me needing to open up additional ports on our firewall.

The server running Debian ‘etch’ is sitting within our DMZ and is only open to the outside world via port 80 for apache and also for ssh listening on a non-standard port. Internally we can access the repositories using the svn:// method between the internal network and the DMZ using the standard svn password-db authentication (and the handy password caching that this provides).

To give external access it seemed a no-brainer that I’d tunnel over ssh especially when I found out that I could set it up so that authentication would be dealt with by maintaining system (i.e. ssh) users for remote access (which all relevant staff have anyway) and could then administrate separately my local-only svn users that access via the plain-text svn://method. On balance I figured this would work for me as I’d rarely need to give access to an ‘outsider’ and when I did then them having a non-privileged user account on the machine wouldn’t be a big deal.

In the end it turned out to not be too difficult to get working though there was a bit of hoop jumping; I was expecting as much after reading this in the svn book:

Once you’ve jumped through these hoops, your repository should be accessible by all the necessary processes. It may seem a bit messy and complicated, but the problems of having multiple users sharing write-access to common files are classic ones that are not often elegantly solved.

Permissions were the biggest issue and the first thing that I did was to add all external users to the svn group. I already have everything chmoded 2770 with owner/group being ‘svn’ but when accessing over ssh the lock files (amongst others) are read-only for everyone except the svn user. To fix this I had to create two wrapper scripts for the svn and svnserve binaries respectively that set the correct umask:

#!/bin/sh
umask 002
/usr/bin/svn-real "$@"

…where svn-real is the renamed svn binary and this script is /usr/bin/svn, repeat for /usr/bin/svnserve.

That was pretty much it except that for external access the way to connect was slightly different. Firstly the connection ‘URL’ was of the form svn+ssh:// for example:
svn co svn+ssh://hostname/path/to/remote/project/trunk

Also, because we’re connecting over ssh via a non-standard port I needed to set an environment variable for the user on the client machine. To do so I simply added the following to their ~/.profile:
export SVN_SSH="ssh -p PORT_NUMBER".

That was it.

So, in summary to give external access all I now need do is:

  • Create a system account on the svn server
  • Add that account to the svn group
  • Tell that user to create a local SVN_SSH environment variable so they connect via ssh over the right non-standard port

Complicated to set-up? Not really. Easy to administer? Yes. Secure? As good as I could make it.

Installing Trac on Debian etch

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