Installing Danbooru on FreeBSD 7.0

Warning: this post is kind of outdated. Even though there’s no problem using it I don’t recommend following this any more.

Danbooru is basically a web gallery software with its main advantage in its advanced tagging system.

However, it’s written in one of modern programming language (and not specifically designed for web) Ruby, with bunch of additional “Gems” and using not-so-commonly-used PostgreSQL. Add the fact that it’s using its own image resizing library, and you’ll get a web software that’s “not intended to be installed by someone with weak heart.” (quoting from its old INSTALL page)

Fret not! In this article I’ll explain installation of Danbooru, esp. on FreeBSD, and be as detailed as possible.

And from scratch.

What “Danbooru” consists of

Before trying installation, we have to undestand what makes “Danbooru”. Unlike other web software like WordPress where you only need a websever, PHP (with its extensions) and MySQL, Danbooru needs more components. Here’s the what Danbooru need:

  • Web server for serving pages and static contents. Usually nginx or lighttpd.
  • FastCGI/Mongrel for generating pages from a Ruby source. (think something like PHP – just it’s only the initiator for generating pages, actual processing was done by Ruby on Rails)
  • Ruby (on Rails) for processing dynamic pages. With extensions. Generating dynamic pages.
  • Memcached (optional) for caching pages. Reducing the need for reading from hard drives. Not mandatory.
  • PostgreSQL for database. Storing dynamic information.
  • libresizer for image resizing. Specially designed to resize images uploaded to Danbooru.
  • Subversion to update Danbooru. Currently there’s no tarball for its source, nor an easy update path from manually-tarballed-source.

There are two methods

There are two methods in serving pages with Danbooru. One is by FastCGI and the other is Mongrel.

  • FastCGI. As it sounds, it’ll process the pages just like other type of CGI pages. There’s additional parameters required though.
  • Mongrel. A daemon specifically designed to serve Ruby pages. NOT to be used as webserver though as it’ll crawl if only uses one process. There is one way to use this properly that is by using mongrel_cluster gem. It enables process management which is better than FastCGI.

Both are not too difficult but I find using FastCGI much easier as I only need to start webserver to also start FastCGI. And you’ll be locked into using lighttpd.

Extra requirement

In addition to full access to machine, you’ll also need to install Danbooru on its own domain. Or if it’s not possible you can make the web server listen on another port

The installation

Installing Danbooru divided into several steps:

  1. Installation and configuration required software
  2. Fetch Danbooru source
  3. Configuration
  4. Final software configuration

Currently in this guide I’ll only explain installation of Danbooru using FastCGI as serving method. Maybe in later revision I’ll add guide for using Mongrel.

Installation and configuration required software

  1. Install FreeBSD. I’d recommend installing base, kernel, games and man. Post installation (when offered to install additional packages), choose to install portupgrade package, located at ports-mgmt directory.
  2. Or if you can’t find it (or missed the chance), run #sysinstall after installation, choose Configure > Packages > FTP (Passive) > Select nearest FTP location > ports-mgmt > portupgrade > Install > etc.
  3. Update your system by doing #freebsd-update fetch install. Make sure to do this at least once a month.
  4. Update entire ports collection by doing #csup -h /usr/share/examples/cvsup/ports-supfile. Replace with other mirror if you want to. Simply run #portsnap fetch followed by #portsnap extract
  5. Edit /etc/make.conf: Add WITHOUT_X11=yes to the file (or create one if it didn’t exist already)
  6. Upgrade installed packages with #portupgrade -ai
  7. Software installation:
    • lighttpd: #portinstall lighttpd
    • subversion: #portinstall subversion
    • GD image processing library: #portinstall gd. Enable iconv
    • ruby gems: #portinstall ruby-gems. Enable pthread *
    • memcached: #portinstall memcached
    • PostgreSQL: #portinstall postgresql-server. Choose to install postgresql83-server and postgresql83-client *
    • FastCGI: #portinstall fcgi-devkit *
  8. Install additional gems:
    • postgresql: #gem install postgres
    • diff-lcs: #gem install diff-lcs
    • html5: #gem install html5
    • fcgi: #gem install fcgi -- --with-fcgi-dir=/usr/local *
    • memcache-client: #gem install memcache-client
    • gchartrb: #gem install gchartrb
    • json: #gem install json
    • rails: #gem install rails --version=2.1.0
    • acts_as_versioned: #gem install acts_as_versioned
    • superredcloth: #gem install superredcloth --source
  9. Reload list of installed programs with #rehash if you use (t)csh – the default FreeBSD shell for root account
  10. Initialize PostgreSQL database:
    #su pgsql
    $/usr/local/bin/initdb -A md5 -D /usr/local/pgsql/data -E utf-8 -U postgres -W
    *enter password*
  11. Add these lines to /etc/rc.conf:
  12. Add these lines to /etc/login.conf for PostgreSQL:
  13. Remake login.conf.db: #cap_mkdb /etc/login.conf
  14. Start memcached and PostgreSQL:
    /usr/local/etc/rc.d/memcached start
    /usr/local/etc/rc.d/postgresql start
  15. Edit kernel config for IPv6:
    #sysctl net.inet6.ip6.v6only=0
    #echo net.inet6.ip6.v6only=0 >> /etc/sysctl.conf

Fetch Danbooru source

  1. Getting on /usr/local/www/danbooru:
    #cd /usr/local/www
    #svn co svn:// danbooru
  2. Securing source:
    #chown -R www:www danbooru
    #chmod -R 000 danbooru/config
    #chmod -R u=rwX danbooru/config
    #chmod 700 danbooru
    #chmod u=rwx danbooru/public/dispatch.fcgi


Everything here is done under danbooru folder (if you follow exactly instruction before, it’s on /usr/local/www/danbooru

  1. Copy config/database.yml.example to config/database.yml and edit production line like this (make sure to use correct indentation) – change the database name if you want:
    adapter: postgresql
    database: danbooru
    username: postgres
    password: *database password*
  2. Create database – make sure to use same database name with the one you wrote in database.yml:
    #psql -U postgres -W template1
    template1=# create database danbooru;
    template1=# q
  3. Create and edit config/local_config.rb (copy from local_config.rb.example) – It’s pretty much straightforward. You will also want to add these lines:
    CONFIG["enable_caching"] = true
    CONFIG["memcache_servers"] = ["localhost:11211"]
    CONFIG["web_server"] = "lighttpd"
  4. Create libresizer:
    #cd lib/danbooru_image_resize
    #ruby extconf.rb --with-gd-dir=/usr/local
  5. Install database… #psql -U postgres -W danbooru < db/postgres.sql
  6. Run migration script
    #cd /usr/local/www/danbooru
    #setenv RAILS_ENV production
    #rake db:migrate
  7. Rename public/maintenance.html to public/maintenance2.html if exist.

That’s it for Danbooru main configuration… which brings us to:

Final software configuration

Here we will configure lighttpd. Make sure you have read its documentation first.

To shorten time, the configuration is located at /usr/local/etc/lighttpd.conf, and here’s my default configuration:

[ lighttpd configuration file for Danbooru ]

Well, then you can start Danbooru by doing #/usr/local/etc/rc.d/lighttpd start

That’s it. Make sure to make your account first. The first created account will become administrator…

Comments, suggestions, fixes, flames etc are welcome.

Update January 31, 2009: fixes and updates. Still need more fixes though.

2 thoughts on “Installing Danbooru on FreeBSD 7.0

  1. Pingback: animeBSD2 · Generic Danbooru INSTALL documentation

Leave a Reply

Your email address will not be published. Required fields are marked *