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:
- Installation and configuration required software
- Fetch Danbooru source
- Configuration
- 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
#sysinstall
after 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 fetch
followed by#portsnap extract
- Edit /etc/make.conf: Add
WITHOUT_X11=yes
to the file (or create one if it didn’t exist already) - Upgrade installed packages with
#portupgrade -ai
- 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
*
- lighttpd:
- 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 http://code.whytheluckystiff.net
- postgresql:
- Reload list of installed programs with
#rehash
if you use (t)csh – the default FreeBSD shell for root account - Initialize PostgreSQL database:
#su pgsql
$/usr/local/bin/initdb -A md5 -D /usr/local/pgsql/data -E utf-8 -U postgres -W
*enter password*
$exit
# - Add these lines to /etc/rc.conf:
memcached_enable="YES"
memcached_flags="-l 127.0.0.1"
postgresql_enable="YES"
lighttpd_enable="YES" - Add these lines to /etc/login.conf for PostgreSQL:
pgsql:
:lang=en_US.UTF-8:
:tc=default: - Remake login.conf.db:
#cap_mkdb /etc/login.conf
- Start memcached and PostgreSQL:
/usr/local/etc/rc.d/memcached start
/usr/local/etc/rc.d/postgresql start - Edit kernel config for IPv6:
#sysctl net.inet6.ip6.v6only=0
#echo net.inet6.ip6.v6only=0 >> /etc/sysctl.conf
Fetch Danbooru source
- Getting on /usr/local/www/danbooru:
#cd /usr/local/www
#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
Configuration
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:
production:
adapter: postgresql
database: danbooru
username: postgres
password: *database password*
host: 127.0.0.1
- 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
# - 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:
#cd lib/danbooru_image_resize
#ruby extconf.rb --with-gd-dir=/usr/local
#make - Install database…
#psql -U postgres -W danbooru < db/postgres.sql
- Run migration script
#cd /usr/local/www/danbooru
#setenv RAILS_ENV production
#rake db:migrate - 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.
Pingback: animeBSD2 · Generic Danbooru INSTALL documentation
Might want to put that lightttpd script up again.