Setting Up a Radiant Site
I’ve successfully set up two Radiant v0.9.1 sites now and need to document what I did so that I can remember all this when I go to create another couple of Radiant sites.
All this stuff may be old by the time you read it, so take into account the date of this post and the Radiant version I’m working with (v0.9). If you’re reading this and you notice an error, please email me and request that I make a correction (I’ll try to add a comment extension to this site).
Also, keep in mind that this post is more for me to remember what I did than to be used as a cut and paste recipe for setting up a new site. We all have our own working environment. But maybe this will help someone else to figure out what has to happen to create and deploy an initial site.
Now without further ado, here’s how I set up a Radiant site. Some of the stuff like RVM, Capistrano, Passenger and so on are for a future post.
1 radiant <sitename> --database=postgresql 2 cd <sitename> 3 git init 4 cp ~/.gitignore_template .gitignore 5 cp ~/.rvmrc_template .rvmrc 6 vim .rvmrc
Change
1 :%s/<sitename>/________________/g 2 ZZ
(I can’t imagine not using RVM for managing Ruby project environments, it’s too scary.)
Now back to the command line (you have to cd to the parent directory and back into the project directory to activate, and therefore test, the .rvmrc file):
1 cd .. 2 cd <sitename> 3 git add .; git commit -m "initial commit" 4 git config --global user.name "Kevin Triplett" 5 git config --global user.email kevin@mopacmedia.com 6 git remote add origin git@github.com:KevinTriplett/<sitename>.git 7 8 git submodule add git://github.com/Squeegy/radiant-settings.git vendor/extensions/settings 9 git submodule init; git add .; git commit -m "add settings extension as git submodule" 10 11 git submodule add git://github.com/kbingman/paperclipped.git vendor/extensions/paperclipped 12 git submodule init; git add .; git commit -m "add paperclipped extension as git submodule" 13 14 git submodule add git@github.com:KevinTriplett/radiant-import-export-extension.git vendor/extensions/import_export 15 git submodule init; git add .; git commit -m "add import_export extension as git submodule" 16 17 git submodule add git@github.com:KevinTriplett/radiant-sheets-extension.git vendor/extensions/sheets 18 git submodule init; git add .; git commit -m "add sheets extension as git submodule"
Now is a good time to load textmate or your favorite text editor with project directory:
1 mate .Add the following lines to config/environment.rb and while there, change the time zone setting and extension load order.
1 config.extensions = [ :settings, :all ] 2 config.time_zone = 'Central Time (US & Canada)' 3 4 config.gem 'pg' 5 config.gem 'imagesize', :lib => 'image_size'
Now edit the config/database.yml file:
1 development: 2 adapter: postgresql 3 database: <sitename>_development 4 username: radiant 5 password: 6 7 test: 8 adapter: sqlite3 9 database: <sitename>_test 10 username: radiant 11 password:
Back on the command line:
1 git add .; git commit -m "configure gems, change time zone, update database.yml"
SKIP THIS NEXT PART UNLESS INSTALLING ON A FRESH MACHINE
If installing to a new development machine, you may have to install postgresql (my database of choice). Otherwise, skip these next few sets of commands:
1 sudo port -v install portgresql84-server 2 sudo mkdir -p /opt/local/var/db/postgresql84/defaultdb 3 sudo chown postgres:postgres /opt/local/var/db/postgresql84/defaultdb 4 sudo su postgres -c '/opt/local/lib/postgresql84/bin/initdb -D /opt/local/var/db/postgresql84/defaultdb' 5 sudo /opt/local/etc/LaunchDaemons/org.macports.postgresql84-server/postgresql84-server.wrapper start
Run the psql utility to access the database utility (DO NOT FORGET THE SEMI-COLONS AT THE END OF EACH COMMAND):
1 psql -U postgres template1 2 3 create user <superuser> createdb createuser; 4 create user radiant createdb; 5 create database <sitename>_development owner radiant encoding 'UTF8'; 6 \q
Before you install the pg gem, you may have to add this to your ~/.bash_profile:
1 vim ~/.bash_profile 2 3 # add the following to the file: 4 export PATH=/opt/local/bin:/opt/local/sbin:/opt/local/lib/postgresql84/bin:$PATH 5 export ARCHFLAGS='-arch x86_64' 6 7 # reload the new profile 8 source ~/.bash_profile
If you already have postgresql all set up and configured, continue here:
CONTINUE FROM HERE IF YOU SKIPPED THAT PREVIOUS PART
Run the psql utility to access the database utility (DO NOT FORGET THE SEMI-COLONS AT THE END OF EACH COMMAND):
1 psql -U postgres --dbname=template1 2 3 create database <sitename>_development owner radiant encoding 'UTF8'; 4 grant all privileges on database <sitename>_development to radiant; 5 \q
Now back on the OS command line:
1 gem install paperclip --version "~>2.3.1.1" 2 gem install radiant 3 gem install pg 4 gem install imagesize 5 gem install compass 6 gem install json 7 gem install uuidtools
Now we can build the core database:
1 rake db:bootstrap
I always choose option 4: styled blog template.
Now we’ll migrate the extension database features and update (ie., add) any extension assets (images, stylsheets, javascript, etc) to the public folder. Be sure to run the settings migration FIRST before running the remaining extension migrations:
1 rake radiant:extensions:settings:migrate 2 rake db:migrate:extensions 3 rake radiant:extensions:update_all
Now it’s time for the wonderful Capistrano. We’ll add some additional recipes that are useful for deployment and production server maintenance:
1 gem install capistrano 2 gem install morhekil-capistrano-deepmodules 3 4 git submodule add git@github.com:KevinTriplett/rubaidhstrano.git vendor/plugins/rubaidhstrano 5 git submodule add git://github.com/saizai/superdeploy.git vendor/plugins/superdeploy 6 git submodule init; git add .; git commit -m "prep for capistrano, before capify" 7 8 capify .
Edit the Capfile file, which is in the site’s root directory, and replace all the contents with the following (make sure to replace <sitename>):
$:.unshift(File.expand_path('./lib', ENV['rvm_path'])) # Add RVM's lib directory to the load path. require 'rvm/capistrano' require 'capistrano/deepmodules' set :rvm_ruby_string, 'ree-1.8.7-2010.02@<sitename>' load 'deploy' if respond_to?(:namespace) # cap2 differentiator Dir['vendor/plugins/*/recipes/*.rb'].each { |plugin| load(plugin) } load 'config/deploy' # remove this line to skip loading any of the default tasks
Edit the config/deploy file (again, make sure to replace <sitename>):
set :rvm_type, :system set :application, "<sitename>" set :repository, "git@github.com:KevinTriplett/<sitename>.git" # TODO: setup an asset compressor set :compress_assets, :none set :git_enable_submodules, 1 ssh_options[:keys] = [File.join(ENV["HOME"], ".ssh", "id_rsa-webadmin")] set :scm, :git set :user, "webadmin" set :deploy_via, :remote_cache # set :deploy_via, :copy set :tag_on_deploy, false set :copy_exclude, %w(.git doc test) set :keep_releases, 6 before "deploy", "deploy:check_revision" after "deploy:update", "deploy:cleanup" after "deploy:symlink","customs:symlink" namespace :deploy do desc "Make sure there is something to deploy" task :check_revision, :roles => [:web] do unless `git rev-parse HEAD` == `git rev-parse origin/#{branch}` puts "" puts " \033[1;33m**************************************************\033[0m" puts " \033[1;33m* WARNING: HEAD is not the same as origin/#{branch} *\033[0m" puts " \033[1;33m**************************************************\033[0m" puts "" exit end end end namespace(:customs) do task :symlink, :roles => :app do run <<-CMD ln -nfs #{shared_path}/system/assets #{release_path}/public/assets CMD end end
================
!MAKE SURE TO CHANGE <sitename> IN THE ABOVE FILES!
================
Back on the command line, create the deploy environments:
mkdir config/deploy touch config/deploy/production.rb touch config/setup_load_paths.rb
Now edit the new config/deploy/production.rb file and add the following:
set :host, "xxx.xxx.xxx.xxx" set :branch, "master"
Edit the new config/setup_load_paths.rb and add the following:
if ENV['MY_RUBY_HOME'] && ENV['MY_RUBY_HOME'].include?('rvm') begin rvm_path = File.dirname(File.dirname(ENV['MY_RUBY_HOME'])) rvm_lib_path = File.join(rvm_path, 'lib') $LOAD_PATH.unshift rvm_lib_path require 'rvm' RVM.use_from_path! File.dirname(File.dirname(__FILE__)) rescue LoadError # RVM is unavailable at this point. raise "RVM ruby lib is currently unavailable." end end
Back on the command line:
1 git add .; git commit -m "config capistrano, after capify"
SKIP THIS IF THIS IS NOT A NEW DEVELOPMENT MACHINE OR EXTRA_TIGHT SECURITY NEEDED FOR THIS SITE:
Create new ssh key and add to github deploy keys (if new server or needs tight security).
CONTINUE HERE:
Now log into production server:
1 cd /u/apps 2 sudo mkdir <sitename> 3 sudo chown webadmin <sitename> 4 sudo chmod 775 <sitename> 5 cd <sitename> 6 echo "rvm use ree-1.8.7-2010.02@<sitename>" | sudo tee .rvmrc 7 cd .. 8 rvm gemset create <sitename> 9 cd <sitename> 10 sudo chmod 644 .rvmrc 11 sudo chown root:root .rvmrc 12 sudo mkdir -p shared/system/assets 13 sudo chown -R webmin:webmin shared 14 gem install paperclip --version "~>2.3.1.1" 15 gem install radiant 16 gem install passenger 17 gem install pg 18 gem install capistrano 19 gem install compass 20 gem install daemon_controller 21 gem install json 22 gem install imagesize
Back on development machine:
1 cap production deploy:setup 2 cap production deploy:check
Make sure no errors from either cap recipe. Now back on production server, edit the database.yml file:
1 sudo vim shared/config/database.ymlMake the file look like the following (except replace
base: &base adapter: postgresql timeout: 5000 username: <user> password: <password> host: localhost production: database: <sitename>_production <<: *base
On the production server command line (/u/apps/
1 psql --dbname=template1 2 create user <user> createdb; 3 alter user <user> with password '<password>'; 4 create database <sitename>_production owner <user> encoding 'UTF8'; 5 \q
Again, back on the development machine:
1 git push origin master 2 cap production deploy
Make sure no capistrano errors — it should end with something like:
triggering after callbacks for `deploy' * executing `deploy:cleanup' *** no old releases to clean up
Once more, back on production server (/u/apps/
1 cd current 2 rvmsudo rake production db:migrate 3 rvmsudo rake production db:bootstrap # I always choose the styled blog template 4 rvmsudo rake production radiant:extensions:settings:migrate # DO THIS ONE FIRST! 5 rvmsudo rake production db:migrate:extensions 6 sudo /etc/init.d/apache2 restart
Time to launch the site! Set up a new http configuration file:
sudo vim /etc/apache2/sites-available/www.<sitename>.com # insert the following lines into the file: <VirtualHost *:80> ServerName <sitename>.com Redirect permanent / http://www.<sitename>.com/ </VirtualHost> <VirtualHost *:80> ServerName www.<sitename>.com DocumentRoot /u/apps/<sitename>/current/public <Directory "/u/apps/<sitename>/current/public"> Options FollowSymLinks Options -Indexes AllowOverride None Order allow,deny Allow from all </Directory> ErrorDocument 503 /system/maintenance.html RewriteEngine On RewriteCond %{REQUEST_URI} !.(css|gif|jpg|png)$ RewriteCond %{DOCUMENT_ROOT}/system/maintenance.html -f RewriteCond %{SCRIPT_FILENAME} !maintenance.html RewriteRule ^.*$ - [redirect=503,last] </VirtualHost> # and replace the <sitename> references: :%s/<sitename>/_______________/g
Back on the production server command line:
1 sudo a2ensite www.<sitename>.com 2 sudo /etc/init.d/apache2 reload
That should be the start of the site, assuming the DNS records point to this server (doh)!