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.
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
Installing Danbooru divided into several steps:
- Installation and configuration required software
- Fetch Danbooru source
- 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
- 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.
- Or if you can’t find it (or missed the chance), run
#sysinstallafter installation, choose Configure > Packages > FTP (Passive) > Select nearest FTP location > ports-mgmt > portupgrade > Install > etc.
- Update your system by doing
#freebsd-update fetch install. Make sure to do this at least once a month.
- Update entire ports collection by doing
#csup -h cvsup.freebsd.org /usr/share/examples/cvsup/ports-supfile. Replace cvsup.freebsd.org with other mirror if you want to. Simply run
#portsnap fetchfollowed by
- Edit /etc/make.conf: Add
WITHOUT_X11=yesto the file (or create one if it didn’t exist already)
- Upgrade installed packages with
- Software installation:
- GD image processing library:
#portinstall gd. Enable iconv
- ruby gems:
#portinstall ruby-gems. Enable pthread *
#portinstall postgresql-server. Choose to install postgresql83-server and postgresql83-client *
- Install additional gems:
#gem install postgres
#gem install diff-lcs
#gem install html5
#gem install fcgi -- --with-fcgi-dir=/usr/local*
#gem install memcache-client
#gem install gchartrb
#gem install json
#gem install rails --version=2.1.0
#gem install acts_as_versioned
#gem install superredcloth --source http://code.whytheluckystiff.net
- Reload list of installed programs with
#rehashif you use (t)csh – the default FreeBSD shell for root account
- Initialize PostgreSQL database:
$/usr/local/bin/initdb -A md5 -D /usr/local/pgsql/data -E utf-8 -U postgres -W
- Add these lines to /etc/rc.conf:
- Add these lines to /etc/login.conf for PostgreSQL:
- Remake login.conf.db:
- Start memcached and PostgreSQL:
- Edit kernel config for IPv6:
#echo net.inet6.ip6.v6only=0 >> /etc/sysctl.conf
Fetch Danbooru source
- Getting on /usr/local/www/danbooru:
#svn co svn://donmai.us/danbooru/trunk danbooru
- 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
- 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:
password: *database password*
- 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;
- 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"
- Create libresizer:
#ruby extconf.rb --with-gd-dir=/usr/local
- Install database…
#psql -U postgres -W danbooru < db/postgres.sql
- Run migration script
#setenv RAILS_ENV production
- 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:
Well, then you can start Danbooru by doing
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.