Project

General

Profile

Support #855

Updated by Daniel Curtis about 8 years ago

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

 h2. Prepare the Environment 

 * Make sure the system is up to date: 
 <pre> 
 pkg update && pkg upgrade 
 </pre> 

 h2. Install PostgreSQL 

 * Install postgresql: 
 <pre> 
 pkg install postgresql94-server 
 </pre> 

 * Initialize, start, and enable postgresql at boot: 
 <pre> 
 echo 'postgresql_enable="YES"' >> /etc/rc.conf 
 service postgresql initdb 
 service postgresql start 
 </pre> 

 * Log in to postgresql user account 
 <pre> 
 su - pgsql 
 </pre> 

 * Connect to postgresql database 
 <pre> 
 psql -d template1 
 </pre> 
 #* Create a user for RefineryCMS: 
 <pre> 
 CREATE USER refineryuser WITH PASSWORD 'SuperSecretPassword' CREATEDB SUPERUSER; 
 </pre> 
 #* Create the RefineryCMS production database & grant all privileges on database 
 <pre> 
 CREATE DATABASE refinerydb OWNER refineryuser encoding='UTF8'; 
 </pre> 
 #* Quit the database session 
 <pre> 
 \q 
 exit 
 </pre> 

 h2. Install Refinery CMS 

 * Install a few dependencies: 
 <pre> 
 pkg install ruby ruby22-gems rubygem-bundler rubygem-rails ImageMagick-nox11 postgresql-libpqxx 
 </pre> 

 * Install the refinerycms gem: 
 <pre> 
 gem install refinerycms 
 </pre> 

 * Create a new refinerycms instance: 
 <pre> 
 cd /usr/local/www 
 refinerycms refinery.example.com 
 cd refinery.example.com 
 </pre> 

 * Edit the Gemfile 
 <pre> 
 vi Gemfile 
 </pre> 
 #* And add the pg gem to the dependencies: 
 <pre> 
 gem 'pg' 
 </pre> 

 * And run the install bundler again to install the pg gem: 
 <pre> 
 bundle install 
 </pre> 

 * Copy the sample postgresql database config over as the main database config: 
 <pre> 
 cp config/database.yml.postgresql config/database.yml 
 </pre> 

 * Then edit the database config: 
 <pre> 
 vi config/database.yml 
 </pre> 
 #* And make the production section is correct: 
 <pre> 
 production: 
   adapter: postgresql 
   encoding: unicode 
   host: db.example.com 
   database: refinerydb 
   pool: 5 
   username: refineryuser 
   password: SuperSecretPassword 
   min_messages: warning 
 </pre> 

 * Run the database migrations: 
 <pre> 
 env RAILS_ENV=production bundle exec rake db:setup db:migrate 
 </pre> 

 * Generate a secret key and +copy the contents to the secrets.yml+ file: 
 <pre> 
 env RAILS_ENV=production bundle exec rake secret 
 </pre> 

 * Edit the secrets.yml file: 
 <pre> 
 vi config/secrets.yml 
 </pre> 
 #* And replace @<%= ENV["SECRET_KEY_BASE"] %>@ with the value generated above: 
 <pre> 
 production: 
   secret_key_base: 7604e60f8441442aec7ba23bd9139dbfe40403381382c4efeb1a697e476a81c2a9c08643d1a1b872dbb2cf1c06f03e9d86f52ad22ff8bab93b74cd5413dc5c15 
 </pre> 

 * Precompile javascript and CSS files: 
 <pre> 
 env RAILS_ENV=production bundle exec rake assets:precompile 
 </pre> 

 * Test RefineryCMS by running the built-in web server: 
 <pre> 
 env RAILS_ENV=production rails server -b 0.0.0.0:3000 
 </pre> 

 * Open a web browser and go to http://refinery.example.com:3000/refinery to add the administrative user. 

 * Press *Ctrl + C* to kill the server. 

 h2. Install Nginx 

 * Add the following to the make.conf file to use nginx while compiling passenger: 
 <pre> 
 echo 'OPTIONS_UNSET+= APACHE22 DOCS NLS X11 EXAMPLES' >> /etc/make.conf 
 echo 'OPTIONS_SET+= PASSENGER SYMLINK NGINX' >> /etc/make.conf 
 </pre> 

 * Install nginx with passenger support: 
 <pre> 
 portmaster www/nginx 
 </pre> 

 * Install Passenger 
 <pre> 
 portmaster www/rubygem-passenger 
 </pre> 

 * Start and enable nginx at boot: 
 <pre> 
 echo 'nginx_enable="YES"' >> /etc/rc.conf 
 service nginx start 
 </pre> 

 * Create a configuration directory to make managing individual server blocks easier 
 <pre> 
 mkdir /usr/local/etc/nginx/conf.d 
 </pre> 

 * Edit the main nginx config file: 
 <pre> 
 vi /usr/local/etc/nginx/nginx.conf 
 </pre> 
 #* And strip down the config file and add the include statement at the end to make it easier to handle various server blocks: 
 <pre> 
 load_module /usr/local/libexec/nginx/ngx_http_passenger_module.so; 
 load_module /usr/local/libexec/nginx/ngx_http_headers_more_filter_module.so; 
 load_module /usr/local/libexec/nginx/ngx_stream_module.so; 

 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; 
 } 
 </pre> 

 * Add a *refinery.example.com server block*: 
 <pre> 
 vi /usr/local/etc/nginx/conf.d/refinery.example.com.conf 
 </pre> 
 #* Add the following: 
 <pre> 
 server { 
     listen         80; 
     server_name    refinery.example.com; 
     root           /usr/local/www/refinery.example.com/public; 
     access_log     /var/log/refinery.example.com-access.log; 
     error_log      /var/log/refinery.example.com-error.log; 

     passenger_enabled on; 
     passenger_user      www; 
     passenger_group     www; 
 } 
 </pre> 

 * Restart nginx: 
 <pre> 
 service nginx restart 
 </pre> 

 * Open a web browser and go to http://refinery.example.com. 

 h2. Resources 

 * http://www.refinerycms.com/guides/installation-prerequisites 
 * http://www.refinerycms.com/guides/getting-started 
 * https://github.com/refinery/refinerycms

Back