April 3, 2009

How to get Bugzilla working with the nginx web server

Filed under: Tips — Tags: , , — Webopius @ 6:44 pm

Overview – Perl, CGI, PHP and nginx co-existing!

This article will give you an overview of how to get the Perl/CGI based Bugzilla bug logging system to work with the nginx web server whilst also co-existing with php based fastcgi.

Scene setter

OK, I could have gone the easy route and used Apache as my web server but I’ve recently become a heavy user of the lightweight, fast web server nginx (“Engine X”).

I use the nginx server on a couple of Unix VPS systems I have hosted with Slicehost … and they fly along quite happily. Today, I decided that I ought to get more sophisticated with my bug and enhancement tracking across the various websites that I run. I immediately chose Bugzilla as the ideal application for the job – I’ve used it before, it’s proven and robust and can also be combined with Deskzilla if a Client GUI is required.

So, off I go to begin the install using the documentation. Start with Perl. Check. MySQL.. Check. Perl Modules… now, at this point I’m getting a little tired of the install as I’m used to simply copying the files into a location for the web server, running a DB install script and that’s it! Bugzilla needs a lot of install steps.

Bugzilla with Perl and CGI on nginx

Finally, I get through all the install steps to the point in the Bugzilla documentation that discusses the Web server (I glibly skips over the recommendation to use Apache). At this point, the documentation asks you to run ‘http://yourserver.com/testagent.cgi’.

Bang. nginx doesn’t have a clue what to do with this file.

The solution

After a few hours of trying out different solutions, I thought it would help to give you a method that worked for me. This solution allows you to run nginx, php, cgi and perl based scripts in harmony together.

1. Download a Perl Wrapper script. I used this Perl Wrapper.

2. Save the file as a non-root user, give it a filename such as ‘perlwrap.pl’.

3. Make sure that this user has write access to /var/run/nginx/ directory.

4. Run ‘perlwrap.pl’

5. Now, as root, configure your site’s nginx configuration file (located in /etc/nginx/sites-available/sitename). Here are the relevant sections from my working configuration file permitting both php, perl and cgi to work together:

   location / {
             root   [YOUR BUGZILLA DIRECTORY];
             index index.cgi index.php index.html index.htm;
   }
   location ~ ^.*\.php$ {

    fastcgi_pass   127.0.0.1:9000;
    fastcgi_index  index.php;
    fastcgi_param  SCRIPT_FILENAME  [YOUR BUGZILLA DIRECTORY]$fastcgi_script_name;
    include        /usr/local/nginx/fastcgi.conf;
   }

   location ~ ^.*\.cgi$ {
    fastcgi_pass   unix:/var/run/nginx/perl_cgi-dispatch.sock;
    fastcgi_index  index.cgi;
    fastcgi_param  SCRIPT_FILENAME  [YOUR BUGZILLA DIRECTORY]$fastcgi_script_name;
    include        /usr/local/nginx/fastcgi.conf;
   }

If the references to ‘fastcgi’ mean nothing, take a look at the comments section of this posting about nginx and the lighttpd fastcgi script:

6. Now, restart nginx: /etc/init.d/nginx restart

7. Visit your Bugzilla site and re-run ‘testagent.cgi’. If all is well you will see an ‘OK’ message.

8. Finally, visit your site’s home page and Bugzilla should appear running on nginx!

  • Tags