Home > Bazaar, Programming, Web Programming > webbzr – php to browse a bzr repository from a web page

webbzr – php to browse a bzr repository from a web page

August 6th, 2009 Leave a comment Go to comments

– You can see webbzr in action here

Latest changes

  • Version 1.4 (Jun 30, 2010)Fixed a vulnerability where webbzr could be used to list content outside of the webbzr root.
  • Version 1.3 (Jan 24, 2010) Branches and directories within branches can now be download as a tgz or tbz2 package straight from the bzr repository.
  • Version 1.2 (Jan 21, 2010) Security fix (thanks to Andrew Bradley)
  • Version 1.1 (Oct. 6 2009) Fix for repository that are not at the root of a url, for instance: http://www.site.com/~user/bzr/ (thanks to Dr. Rich Wareham)
  • Version 1.0 (Aug. 5 2009) Initial version


Bazaar (bzr) can push and pull branches on a remote server without having to install anything on the server side. This is useful in cases where you have access to a web server without admin privileges (i.e. you could not install WebDAV or setup a svn site). With bzr, you simply upload (sftp) your branch to a directory visible from your web page, and then people download (branch) using http.

Next step, I wanted to allow browsing of the branch from the web. This feature is “free” with svn through WebDAV, and there have been extra tools to browse svn and cvs (e.g. ViewVC). For bzr however, all I could find was LoggerHead which works as an actual web server. It has to start a daemon and open ports – pretty much defeating my initial motivation for using bzr.

I figured I’d just hack something quick.



webbzr is a php script that will:

  • List the content of a directory and show normal and versioned files
  • Allow browsing into the repository
  • Allow viewing or downloading of files in the repository
  • Allow downloading of branches or directories as a tgz/tbz2 package
  • Allow browsing of revisions (going back in time)
  • Display information about the last modifications

Files, not just directories, can be browsed by version. For example:

Hiding the Parameters from the URL

Using mod_rewrite, browsing is transparent (you can browse using the actual path in the url). For example, the link to http://bazaar.enseed.com/app/webbzr/ brings you straight into a branch. This is more convenient than using the equivalent url: http://bazaar.enseed.com/.webbzr/webbzr.php?path=app/webbzr/.

To make this possible without configuring the web server directly, we use a .htaccess file that redirects requests to the script:

RewriteEngine on
RewriteCond %{REQUEST_URI} !^/\..*$
RewriteRule ^(.*)$ /.webbzr/webbzr.php?path=$1 [L,QSA]

This reads: given that the request uri does not start with a “.” (the script in stored in .webbzr/ to avoid recursive redirection), whatever the request was, pass it as an argument named path to webbzr.php.

Formatting the Output

The webbzr.php script actually outputs xml, not html. The xml is transformed on the client side with an xslt (webbzr.xsl) and styled with css (webbzr.css). That means you can change the look if without having to touch the php code at all.


1. Download

To download:

bzr branch http://bazaar.enseed.com/app/webbzr/

2. Configure

Move to webbzr/.webbzr:

cd  webbzr/.webbzr/

In the config.php file you will have to edit the following variables:

  • $BZRURL: this should be the url to the root of your web site (i.e. from where the script will run)
  • $BZRBINARY: how to invoke bzr. This may simply be “bzr” if it’s in your path.
  • $XSLABSOLUTEURL: absolute url to the webbzr.xsl file.
  • $CSSABSOLUTEURL: absolute url to the webbzr.css file.

Move back to the webbzr directory (cd ..) and edit the .htaccess file. Next to the RewriteRule, make sure the url to the webbzr.php is fine. By default, it expects to be in /.webbzr/webbzr.php

3. Install

Copy the .htaccess file to the root of your browsing directory. Next to it, copy the .webbzr/ directory with the webbzr.php, config.php, webbzr.css, webbzr.xsl and the img/ directory.

4. Try it

And let me know if it works…

Categories: Bazaar, Programming, Web Programming Tags:
  1. November 24th, 2009 at 07:48 | #1


    I’m searching for a way to offer a webinterface to bazaar on my website. Unfortunately my website is running on a shared host which makes it impossible to install additional software. But as my webspace supports python and ruby on rails scripts, I just wanted to ask if your website is running on a shared host, too, or if you own a dedicated server.

    If your site is running on a shared host, too, can you please tell me how you managed the bazaar setup on the server?

    Thanks for any help and the cool php script :D.

  2. petit
    November 24th, 2009 at 19:09 | #2

    Hello Ben,

    This site and http://bazaar.enseed.com/ are on a shared server. The only requirement is that you install bzr. I have posted instructions to do that as a user (for when you cannot sudo) here: http://thoughts.enseed.com/installing-bazaar-bzr-locally-on-a-web-host/

    You will end up with a bzr binary in your ~/bin which will be used by webbzr. Let me know if you’re having troubles.

  3. February 25th, 2010 at 12:46 | #3

    I want to use bzr on my university project. I’ve installed bzr on school shared server and tried to install webbzr. I faild. Don’t know where.
    I’m getting internal server error 500. When I rename .htaccess file this error gones.
    I have Apache 2.0 and php 5.1.4, here is my php info http://www.ee.pw.edu.pl/~gargaso/phpinfo.php if it may help.

    I don’t fully understand how to modyfy .htaccess. I’ve done it this way:
    RewriteRule ^(.*)$ /home/ee/stud/gargaso/WWW/.webbzr/webbzr.php?path=$1 [L,QSA]

    where /home/ee/stud/gargaso/WWW/ is my full path to the public html folder.

    Thanks for any support.

    PS Please contact me on my mail if you can. Thanks.

  4. November 22nd, 2010 at 10:52 | #4


    First off thanks for the great software! I’m using it for my own BZR projects as Loggerhead has more requirements than just BZR and PHP.

    I’ve stumbled into a problem that might be coming from either my lack of understanding about BZR, or a lack of understanding about the intentions of webbzr. For some reason my version of webbzr does not notice that all the files below the root of the branch are under revision control. So changing revision in the browser does nothing and you can’t see any comments about the files checked in (other than at the root). These files are all checked in to BZR but exist as a branch, rather than a checked out repository.

    To see the example go to: http://www.mattoates.co.uk/code/bzr/

    Thanks for any help you can give as to what might be causing this.

    I will take a look at the webbzr code and see if I can find out what I am doing wrong.

    Have fun,

  5. June 8th, 2011 at 07:36 | #5

    With my setup http://repository.varesano.net/ in order to allow bzr client functioning on the same URL, I had to change the suggested .htaccess into:
    RewriteEngine on
    RewriteCond %{REQUEST_URI} !^/\..*$
    RewriteCond %{HTTP_USER_AGENT} !^bzr/.*
    RewriteRule ^(.*)$ .webbzr/webbzr.php?path=$1 [L,QSA]

    This way the whenever the client is a bzr the script doesn’t redirect. I think it may be possible to produce the same result also using %{REQUEST_URI} but I didn’t investigate on that.

  6. June 8th, 2011 at 08:26 | #6

    Looks like it’s pretty simple to modify the php to support arbitrary revision packaging and downloading. See my patch on http://sprunge.us/PRKV

    I tryed to modify the xsl to provide links like ?download=tgz&rev=11 when browsing a revision different from the latest but I failed.. :-(

  7. January 12th, 2012 at 16:19 | #7

    Hi. Webbzr is great, it’s replaced my loggerhead install and uses less resources. Unfortunately, I can’t seem to use the “bzr branch” feature for branching code that webbzr has. i.e. If you goto tim.purewhite.id.au/code/handbrake-cluster/ you can see all the code in webbzr no problem. However using ‘bzr branch http://tim.purewhite.id.au/code/handbrake-cluster/‘ fails with a connection closed error message.
    On the server I see an OPTIONS request, and then a POST request to /code/handbrake-cluster/.bzr/smart which when accessed via the web interface gives me a blank page. the .bzr part works, it’s the /smart part that doesn’t. Am I missing something with the install? This is running on a Nginx frontend proxying to php-fpm.



  1. No trackbacks yet.

Please leave these two fields as-is:

Protected by Invisible Defender. Showed 403 to 159,832 bad guys.