Danbooru Installation guide on FreeBSD (6.2)
Provided by Shuugo
Cleanup of dovac's guide: http://uruchai.com/2007/12/24/in-depth-guide-on-installing-danbooru-on-freebsd

A minimal FreeBSD profile installation is encouraged. You can use VMWare to test how things work before trying on an actual machine.

1)) Updating ports:
You can find how fully work here: http://www.freebsd.org/doc/en_US.ISO8859-1/books/handbook/ports-using.html but basically you will only need:

1. portsnap fetch
2. portsnap extract

2)) Install the following things through ports

1. cd /usr/ports/devel/mkmf/ && make install clean
2. cd /usr/ports/ftp/wget/ && make install clean
3. cd /usr/ports/editors/nano/ && make install clean
4. cd /usr/ports/devel/subversion/ && make install clean (May ask for configuration: Choose "libiconv", "python25", enable "huge stack size", and disable "ipv6"
5. cd /usr/ports/databases/memcached/ && make install clean
6. cd /usr/ports/graphics/gd/ && make install clean (Make sure you enable iconv support)
7. cd /usr/ports/databases/postgresql83-client/ && make install clean (config defaults are ok)
8. cd /usr/ports/databases/postgresql83-server/ && make install clean (config defaults are ok)

3)) Editing rc.conf for starting postgres and memcached at boot.

1. nano /etc/rc.conf
2. Add the following at the end of the file:

postgresql_enable="YES"
memcached_enable="yes"
memacached_flags="-l 127.0.0.1 -d m 100"

3. Press Control + X to save.

4. We run "/usr/local/etc/rc.d/postgresql initdb" to get ready to initialize postgres for first time.

5. Use "/usr/local/etc/rc.d/postgresql start", to start the postgresql server.

4)) Ruby on rails installation

1. cd /usr/ports/lang/ruby18/ && make install clean (Disable ipv6)
2. rubygem-rails port is broken, download it from rubyforge
2a wget http://rubyforge.org/frs/download.php/29548/rubygems-1.0.1.tgz
2b tar xvf rubygems-1.0.1.tgz
2c cd rubygems-1.0.1
2d ruby setup.rb
3. cd /usr/ports/www/rubygem-rails/ && make install clean (Be sure it's rubygem-rails-1.2.6. Rails 2.0 isn't compatible yet)
4. cd /usr/ports/www/rubygem-redcloth/ && make install clean
5. cd /usr/ports/www/rubygem-mongrel/ && make install clean

Some gems are not available through ports

6a wget http://rubyforge.org/frs/download.php/29624/postgres-0.7.9.2007.12.22.gem
6b /usr/bin/gem18 install --no-ri --install-dir /usr/local/lib/ruby/gems/1.8 ./postgres-0.7.9.2007.12.22.gem (There's a chance that it's not gem18, but gem I'll assume it's the correct path, if not, replace it on the following steps too)

7. /usr/bin/gem18 aws-s3 diff-lcs acts_as_versioned html5 (Accept all dependencies)

5)) Danbooru installation

1. Create the danbooru user, -> adduser (danbooru, and choose a password)
2. cd /home/danbooru
3. svn co svn://danbooru.donmai.us/danbooru/trunk (This will get you the latest trunk)
4. cd trunk/
5. mv * ..
6. cd ..
7. rm -r trunk/

8. Database creation:
8a su pgsql
8b CREATE DATABASE danbooru;
8c \q
8d psql -d danbooru -f /home/danbooru/db/postgres.sql
8e exit

6)) Danbooru configuration

1. cd /home/danbooru/config
2. mv database.yml.example database.yml
3. nano database.yml 
3a Change all users to pgsql (Control+X to save and exit)
4. mv local_config.rb.example local_config.rb
5. nano local_config.rb 
NOTE: You can check for additional configuration parameters and a brief explanation in default_config.rb
5a. Change the parameters needed an add these parameters
CONFIG["password_salt"] = “choujin-steinerr” (replace the salt with something else)
CONFIG["image_store"] = :local_flat (replace with :local_hierarchy if you want scaled folders for example /01/23/fullhash.ext, leave :local_falt to leave all the images in one same folder)
CONFIG["enable_caching"] = false (change to true to enable memcache, this will speed up things)
CONFIG["memcache_servers"] = ["localhost:4000"] (change to "localhost:11211")
5b Control + X to save and exit.

6. Compiling the resizer
6a You can rather choose between using "ruby extconf.rb" or "ruby extconf.rb --with-gd-dir=/usr/local/gd", if you are using this last option you can ignore the 6b 6c and 6d steps. Using the first method will give you always the same gd version while the second command, the gd version will be updated when you update it through ports.
6b cp /usr/local/include/gd.h gd.h
6c cp /usr/local/include/gd_io.h gd_io.h
6d cp /usr/local/include/gdfx.h gdfx.h
6e make
6f make install

7. cd /home/danbooru
7b /usr/local/bin/rake db:migrate

7)) Basic webserver

- Now you can run "mongrel_rails start", this will make danbooru public on your hostname:3000. You will see debug information in the console

- For running it with mongrel and serving it "normally" you can use "mongrel_rails start -p 80 -d" This will tell mongrel to run on port 80 and as a daemon (not displaying anything in the console)

8)) Advanced webserver

Is encouraged that you rather configure Apache or lighttpd to proxy (or vhosting) the rails app. However this last method requries advanced configuration files and server modules.

If you plan only on running danbooru here's a good configuration for lighttpd usage (you can install it through ports)
Mongrel running as a daemon (4 threads) You might want to add this to the rc.conf if you want to start it automatically

1. cd /home/danbooru
2a mongrel_rails start -d -p 8001 -e production -P log/mongrel-1.pid
2b mongrel_rails start -d -p 8002 -e production -P log/mongrel-2.pid
2c mongrel_rails start -d -p 8003 -e production -P log/mongrel-3.pid
2d mongrel_rails start -d -p 8004 -e production -P log/mongrel-4.pid

Then on lighttpd.conf be sure to have the following mods enabled (Remove # before its names if not):
-mod_rewrite
-mod_redirect
-mod_access
-mod_accesslog
-mod_compress
-mod_proxy

3. Add this to your lighttpd.conf:

proxy.balance = "fair" 
proxy.server  = ( "/" => 
     ( ( "host" => "127.0.0.1", "port" => 8001 ),
     ( "host" => "127.0.0.1", "port" => 8002 ),
     ( "host" => "127.0.0.1", "port" => 8003 ),
     ( "host" => "127.0.0.1", "port" => 8004 ) ) )

4. Restart lighttpd: "/usr/local/etc/rc.d/lighttpd restart"