Support #855

Install Refinery CMS on FreeBSD

Added by Daniel Curtis almost 4 years ago. Updated almost 4 years ago.

Web Server
Target version:
Start date:
Due date:
% Done:


Estimated time:
1.50 h
Spent time:


This is guide for setting up Refinery CMS with Nginx and PostgreSQL on FreeBSD 10.

Prepare the Environment

  • Make sure the system is up to date:
    pkg update && pkg upgrade

Install PostgreSQL

  • Install postgresql:
    pkg install postgresql94-server
  • Initialize, start, and enable postgresql at boot:
    echo 'postgresql_enable="YES"' >> /etc/rc.conf
    service postgresql initdb
    service postgresql start
  • Log in to postgresql user account
    su - pgsql
  • Connect to postgresql database
    psql -d template1
    • Create a user for RefineryCMS:
      CREATE USER refineryuser WITH PASSWORD 'SuperSecretPassword' CREATEDB SUPERUSER;
    • Create the RefineryCMS production database & grant all privileges on database
      CREATE DATABASE refinerydb OWNER refineryuser encoding='UTF8';
    • Quit the database session

Install Refinery CMS

  • Install a few dependencies:
    pkg install ruby ruby22-gems rubygem-bundler rubygem-rails ImageMagick-nox11 postgresql-libpqxx
  • Install the refinerycms gem:
    gem install refinerycms
  • Create a new refinerycms instance:
    cd /usr/local/www
  • Edit the Gemfile
    vi Gemfile
    • And add the pg gem to the dependencies:
      gem 'pg'
  • And run the install bundler again to install the pg gem:
    bundle install
  • Copy the sample postgresql database config over as the main database config:
    cp config/database.yml.postgresql config/database.yml
  • Then edit the database config:
    vi config/database.yml
    • And make the production section is correct:
        adapter: postgresql
        encoding: unicode
        database: refinerydb
        pool: 5
        username: refineryuser
        password: SuperSecretPassword
        min_messages: warning
  • Run the database migrations:
    env RAILS_ENV=production bundle exec rake db:setup
  • Generate a secret key and copy the contents to the secrets.yml file:
    env RAILS_ENV=production bundle exec rake secret
  • Edit the secrets.yml file:
    vi config/secrets.yml
    • And replace <%= ENV["SECRET_KEY_BASE"] %> with the value generated above:
        secret_key_base: 7604e60f8441442aec7ba23bd9139dbfe40403381382c4efeb1a697e476a81c2a9c08643d1a1b872dbb2cf1c06f03e9d86f52ad22ff8bab93b74cd5413dc5c15
  • Precompile javascript and CSS files:
    env RAILS_ENV=production bundle exec rake assets:precompile
  • Test RefineryCMS by running the built-in web server:
    env RAILS_ENV=production rails server -b
  • Press Ctrl + C to kill the server.

Install Nginx

  • Add the following to the make.conf file to use nginx while compiling passenger:
    echo 'OPTIONS_UNSET+= APACHE22 DOCS NLS X11 EXAMPLES' >> /etc/make.conf
    echo 'OPTIONS_SET+= PASSENGER SYMLINK NGINX' >> /etc/make.conf
  • Install nginx with passenger support:
    portmaster www/nginx
  • Install Passenger
    portmaster www/rubygem-passenger
  • Start and enable nginx at boot:
    echo 'nginx_enable="YES"' >> /etc/rc.conf
    service nginx start
  • Create a configuration directory to make managing individual server blocks easier
    mkdir /usr/local/etc/nginx/conf.d
  • Edit the main nginx config file:
    vi /usr/local/etc/nginx/nginx.conf
    • And strip down the config file and add the include statement at the end to make it easier to handle various server blocks:
      load_module /usr/local/libexec/nginx/;
      load_module /usr/local/libexec/nginx/;
      load_module /usr/local/libexec/nginx/;
      worker_processes  1;
      error_log  /var/log/nginx-error.log;
      events {
          worker_connections  1024;
      http {
          include       mime.types;
          default_type  application/octet-stream;
          sendfile        on;
          keepalive_timeout  65;
          # Load Phusion Passenger module globally
          passenger_root /usr/local/lib/ruby/gems/2.2/gems/passenger;
          passenger_ruby /usr/local/bin/ruby22;
          passenger_max_pool_size 15;
          passenger_pool_idle_time 300;
          # Load config files from the /etc/nginx/conf.d directory
          include /usr/local/etc/nginx/conf.d/*.conf;
  • Add a server block:
    vi /usr/local/etc/nginx/conf.d/
    • Add the following:
      server {
          listen       80;
          root         /usr/local/www/;
          access_log   /var/log/;
          error_log    /var/log/;
          passenger_enabled on;
          passenger_user    www;
          passenger_group   www;
  • Restart nginx:
    service nginx restart



#1 Updated by Daniel Curtis almost 4 years ago

  • % Done changed from 0 to 50
  • Status changed from New to In Progress
  • Description updated (diff)

#2 Updated by Daniel Curtis almost 4 years ago

  • % Done changed from 50 to 100
  • Status changed from In Progress to Resolved

#3 Updated by Daniel Curtis almost 4 years ago

  • Status changed from Resolved to Closed

Also available in: Atom PDF