Site logo image
[Home Page]

[RSS Feeds]

[IRC Server]

Return to web hosting guides

Print Page mail icon

Adding search capability to a website with Xapian Omega for Apache web-servers on Debian

Date: 2022-02-04

  In this guide you’re going to setup the Xapian Omega search engine CGI application for a simple static web-site. It is assumed that you are already running an Apache server and are familiar with Apache, so this guide will not delve into unrelated Apache setup configurations about CGI script aliases and security settings. The only security precaution that you should be aware of is to not run the Apache service as root, especially when dealing with CGI scripts.

  • Install and configure
  • Configuring a search box
  • Conclusion
  • References

  • Install and configure

    Start by installing the Xapian Omega package.

    sudo apt install xapian-omega

    The Omega CGI script file will be located in /usr/lib/cgi-bin/
    The Xapian and Omega tamplates and database files will be located in /var/lib/xapian-omega/

    After the package completes installation, you can run the omindex application to recursively index the contents of your site. The following example will index only HTML files.

    If you would prefer to include other files in the index of your site, you can read the list of supported mime types here.[1]

    omindex --db /var/lib/xapian-omega/data/default --mime-type html:text/html --url /directory-to-index /path/to/directroy-to-index
    omindex --db /var/lib/xapian-omega/data/default --mime-type html:text/html --url /blog /var/www/website/html/blog/

    If you would prefer to index additional directories from your sites document root, you can use the preserve flag in the omindex command. If you don’t specify the preserve option in the command, then each time you run omindex, it will replace the previous index contents.

    omindex -p --db /var/lib/xapian-omega/data/default --mime-type html:text/html --url /reviews /var/www/website/html/reviews/

    Enable the CGI and Actions module for Apache so that the script can be ran.

    a2emod cgi actions

    Now to test Omega. Open a web browser and go to You should see a search prompt where you can keyword search for the indexed HTML files from the previous omindex command.

    From your HTML site editor, you can add the following to create a simple search box.

    <form method="GET" action="/cgi-bin/omega" role="search">
      <input name="P" placeholder="Search for..." size="50" autofocus>
        <button type="submit">Search</button>

    The autofocus option will focus a users input onto the search box upon loading the site so that they wouldn’t have to move their cursor to activate the box themselves. This is a usability preference that you don’t need to include if it becomes a disruption for your site.

    If you would prefer to create a search that implements an alternative database than the “default,” you can add the following to your document. I am using “alt_database” as the alternative database name.

    <form method="GET" action="/cgi-bin/omega" role="search">
      <input name="P" placeholder="Search for..." size="50" autofocus>
      <input type="hidden" name="DB" value="alt_database">
        <button type="submit">Search</button>

    There are other CGI input parameters for Omega that you can read about here[2]


    Over a period of time in running a web-site, it’s common to accumulate a number of blogs, guides, and miscellaneous materials that can build up to such an amount that the accessibility of those past articles can become lost to the readers as it is buried away.

    Many webmasters and bloggers alike have unwittingly placed a lion’s share of the ability to search their sites into the hands of commercial search engine services such as Google, where accurate results won’t always be guaranteed.







    [Return to top]

    Last modified date: 2022-02-14

    nationality icon

    Copyright © 2020-2022 All Rights Reserved.