How to Install a Mephisto Blog on your Rails Slice as a Subdomain
January 21st, 2008
In this article, I will show you how to install a Mephisto Blog on your server so that it is accessible through a subdomain such as "blog.yoursite.com". While this tutorial is written specifically for installing Mephisto on a VPS Slice on Slicehost, I've divided it into sections so that the directions can be easily followed to install any blogging platform on any VPS or dedicated server that uses Apache and Mongrel.
This took me about 7 hours and 3 beers to figure out and get working on my server (RateMyStudentRental.com), but hopefully, with my help you'll be up and running in a mere half hour and 1 beer (provided you're not underage of course). And on to the tutorial!
Basically, here are the steps that need to be performed:
- Install the blog on your computer and get it running as a separate application
- Open your first beer and get comfortable
- SSH into your server and set up a new svn repository for the app on your existing server right alongside the existing repository for your existing app
- Capify your new Mephisto blog on your computer (if you’re not using Capistrano, you’re really missing out)
- Import app from your computer into your repository, check it back out and deploy to server right alongside your existing app
- Configure Apache server to redirect subdomain traffic to the blog’s directory on the server rather than the directory of your existing app, using Virtual Hosts
- Drink one more beer to celebrate (or maybe hold off until after your first post)
Hopefully now you have a bit better idea of what we’re about to do. So, let’s do it now.
1. Install blog and get it running on your computer as a separate app
If you are going to use a platform other than Mephisto, follow the appropriate instructions to get it running on your computer and skip to Step 2.
Now, for Mephisto, the install directions from their site are as follows:
- Create a database named mephisto (or one of your choosing).
- Copy config/database.example.yml to config/database.yml
- Edit database.yml and set your database credentials.
- Upload the entire mephisto directory to your webserver.
- Make sure you upload the tzinfo gem (see above) with the directory, or that your host has it preinstalled.
- Run rake db:bootstrap from a terminal of some sorts (use rake db:bootstrap RAILS_ENV=production to be sure you’ve bootstrapped the production database.)
However, when I tried this, I had problems getting Step 6 to work. To solve the problem, I had to upgrade my rake, gems, and rails to the latest versions (rake 8.1, gems 1.0.1, and rails 2.02), using the following commands
sudo gem update rake
sudo gem update
sudo gem update rails
Oh and make sure the tzinfo gem is installed on both your computer and the server
sudo gem install tzinfo
Then I had to uninstall the stable version of Mephisto (6.1) and instead install the latest and greatest build (7.2) from the Mephisto svn trunk repository
svn co http://svn.techno-weenie.net/projects/mephisto/trunk
Now go into your favorite mysql tool (or terminal) and create a new database for your blog. Then open up database.sample.yml in the config folder and configure your database info to match your new database’s name, user and password, then save it as database.yml. Go back to the directory of your app in terminal and run
rake db:bootstrap
Hopefully your tables got created properly. This is where all my original problems occurred though. If you are getting “no method found” or “permission denied” errors, make sure that you are using the latest rake and rails versions (some important changes happened between rake v7 and rake v8, same goes for Rails 1.2 and Rails 2.0 that will cause the bootstrap rake file to not execute properly with the former versions). Now, you should be able to go to that directory in your terminal and get it running from your computer
ruby script/server
In your browser, navigate to http://localhost:3000/admin, login and make sure all is working.
2. Get Beer
Alright, you’re doing good. We’ve made some real progress, so it’s time to pop open that first beer. Remember though, we’re going for quality here, so it better be something good like Stella Artois or Guiness, none of that domestic crap.
3. Setup SVN
If you are using Slicehost as my app (www.ratemystudentrental.com) is, then hopefully you used the deprec gem along with Capistrano to deploy your original app. If you did, then rejoice, and skip to Step 4. If not, check out this wiki to get Capistrano and the deprec gem working.
Otherwise, you hopefully remember enough about your original deployment that you can do it again with this blog app. But basically, you will need to SSH into your server, navigate to the parent directory of your existing app, create a new directory for your blog right beside it, then create a svn repository for it right beside your existing app’s repository (wherever that is), svn import your blog into the new svn repository, and then check it back out to your computer.
4. Capify your Blog App
If Cap and deprec are already on your computer, issue the following command from your blog app directory in terminalcd /path/to/railsapp
deprec --apply-to . --name projectname --domain yoursite.com
Note that the domain is just yoursite.com, not blog or blog.yoursite.com. Now, open up the newly created config/deploy.rb and fill in the details. The lines you need to uncomment and fill in are:
1 2 3 4 |
set :domain, "yoursite.com" set :application, "projectname" set :deploy_to, "absolute/path/to/your/new/project/on/server" set :user, "yourusernameonserver" |
Unless you already have an svn repository for your blog setup somewhere, uncomment this line too
role :scm, domain |
Then uncomment the appropriate apache and mongrel config lines as shown in my deploy.rb file below. You may need to change the directory of your apache2 config files (you should probably SSH to your server, and look around to find out where your apache2 .conf files are). Mine are in /usr/local/apache2/conf, though a lot of servers have them at /etc/apache2/conf.
set :apache_conf, "/usr/local/apache2/conf/apps/#{application}.conf" |
Make sure that you tell apache to serve your blog to different proxy ports than your existing app.
set :apache_proxy_port, 4000 |
My app was using the 8000 ports, so I put my blog on the 4000 ports. Also, change the number of mongrel instances to the appropriate value. You can typically count on 50-60MB of memory use per mongrel instance, so don’t overdo it. My app is running on a 512MB Slice at slicehost with 4 mongrel instances (4 x 60MB = 240MB). I figured 2 mongrels should be good enough for the Mephisto blog (2 x 60MB = 120MB). 240 + 120 = 360MB < 512 MB, so we’re good.
set :apache_proxy_servers, 2 |
Also, if you have a SSH certificate set up on your computer, so that you don’t have to enter your username and password into the terminal everytime you go to SSH into your server, you’ll need the following line added at the end with the path on your computer to your SSH certificate
ssh_options[:keys] = %w(/home/yourcomputerusername/.ssh/id_rsa) |
Here is what my ‘deploy.rb’ looks like:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
require <i>deprec/recipes</i> # ============================================================================= # ROLES # ============================================================================= # You can define any number of roles, each of which contains any number of # machines. Roles might include such things as :web, or :app, or :db, defining # what the purpose of each machine is. You can also specify options that can # be used to single out a specific subset of boxes in a particular role, like # :primary => true. set :domain, "ratemystudentrental.com" role :web, domain role :app, domain role :db, domain, :primary => true role :scm, domain # ============================================================================= # REQUIRED VARIABLES # ============================================================================= # You must always specify the application and repository for every recipe. The # repository must be the URL of the repository you want this recipe to # correspond to. The deploy_to path must be the path on each machine that will # form the root of the application path. set :application, "msrblog" set :deploy_to, "/var/www/apps/#{application}" # XXX we may not need this - it doesn't work on windows set :user, 'yourserverusername' set :repository, "svn+ssh://#{user}@#{domain}#{deploy_to}/repos/trunk" set :rails_env, "production" # Automatically symlink these directories from current/public to shared/public. # set :app_symlinks, %w{photo, document, asset} # ============================================================================= # SPECIAL OPTIONS # ============================================================================= # These options allow you to tweak deprec behaviour # If you do not keep database.yml in source control, set this to false. # After new code is deployed, deprec will symlink current/config/database.yml # to shared/config/database.yml # # You can generate shared/config/database.yml with 'cap generate_database_yml' # # set :database_yml_in_scm, true # ============================================================================= # APACHE OPTIONS # ============================================================================= set :apache_server_name, domain # set :apache_server_aliases, %w{alias1 alias2} # set :apache_default_vhost, true # force use of apache_default_vhost_config # set :apache_default_vhost_conf, "/usr/local/apache2/conf/default.conf" set :apache_conf, "/usr/local/apache2/conf/apps/#{application}.conf" set :apache_ctl, "/etc/init.d/httpd" set :apache_proxy_port, 4000 set :apache_proxy_servers, 2 set :apache_proxy_address, "127.0.0.1" # set :apache_ssl_enabled, false # set :apache_ssl_ip, "127.0.0.1" # set :apache_ssl_forward_all, false # set :apache_ssl_chainfile, false # ============================================================================= # MONGREL OPTIONS # ============================================================================= set :mongrel_servers, apache_proxy_servers set :mongrel_port, apache_proxy_port set :mongrel_address, apache_proxy_address set :mongrel_environment, "production" set :mongrel_config, "/etc/mongrel_cluster/#{application}.conf" # set :mongrel_user_prefix, 'mongrel_' # set :mongrel_user, mongrel_user_prefix + application # set :mongrel_group_prefix, 'app_' # set :mongrel_group, mongrel_group_prefix + application # ============================================================================= # MYSQL OPTIONS # ============================================================================= # ============================================================================= # SSH OPTIONS # ============================================================================= ssh_options[:keys] = %w(/home/yourcomputerusername/.ssh/id_rsa) # ssh_options[:port] = 25 |
5. Migrate Blog to Server
And now for the exciting part, migrating everything to your server. Don’t forget to really enjoy your beer throughout this step, but pace yourself. You don’t want to be incoherent while playing around with your server. In your terminal from the directory of your blog app, run this command
cap setup
Now, if you did not already have a svn repo somewhere, run this command to set that up on your server
cap setup_scm
Your terminal should have spit out the address to your new svn repo. At this point, navigate to the directory of your blog app on your computer and go one level above. You should have a new folder now called projectname_machine or projectname.test or something like that (I don’t remember exactly). Anyway, that is now your new working directory. You can safely delete your original directory projectname folder from your computer or archive it, and rename the new directory back to projectname.
Now go into the new directory, reopen config/deploy.rb, and replace the line
set :repository, "svn+ssh://#{user}@#{domain}#{deploy_to}/repos/trunk" |
with the new explicit path that terminal gave you for the svn address (basically, the variables will just be replaced with their actual values).
Mephisto-specific
If you are using Mephisto, go back to terminal and issuecap deploy
You will now need to SSH into your server. Navigate to the current directory of your newly deployed blog app, and issue the command
rake db:bootstrap RAILS_ENV=production
Again, if you have problems, make sure that your server also has completely updated rake, gems, and Rails as you did with your computer. Your blog app should now be on your server and under revision control.
Non-Mephiso instructions
Note that if you’re using a blog platform other than Mephisto, you’ll instead run
cap deploy_with_migrations
assuming you have the blog app running on your computer with the proper tables and migrations set up.
Now, Everybody!
cap restart_apache
cap restart mongrel_cluster
6. Configure Apache2
You should now be about ¾ done with your beer by this time. Put your beer aside for this step, because it can be a little confusing, and differs depending on your exact server setup and configuration. My server is running Ubuntu 7.04 Feisty with Apache2 and Mongrel, so that’s what I’ll be dealing with specifically here.
The idea is that you’re going to be modifying your server’s configuration files so that it knows to look at the HTTP header of incoming requests and route requests of the appropriate subdomain to the directory of your blog app rather than your main app. Technically, what we’re doing is setting up a Name-based Virtual Host. You can read more about name-based vhosting here.
First, find your Apache2’s httpd.conf file. Most of the time you can find it in /etc/apache2/conf, but my server was setup by deprec, which put it in /usr/local/apache2/conf. In this directory, look to see if you have a folder called apps. If you do, then go in there and you should have two .conf with the titles of your original app and your new blog app. Deprec did that for you.
If you didn’t use deprec, then you’ll just have the original one, which you will need to copy and rename the copy to your blog app name. Either way, now you open up the projectname.conf file and change the following lines:
ServerName www.yoursite.com
DocumentRoot /var/www/apps/projectname/current/public
To
ServerName blog.yoursite.com
DocumentRoot /var/www/apps/projectname/current/public
Also, if you have any ServerAlias lines, delete those.
If you did not already have this file and copied it over, you will need to go back into your conf directory, open up httpd.conf and tell it to look for the new projectname.conf.
For more help setting up your .conf file, check out this code for setting up Mephisto to work with multiple sites.
If you did not have an apps folder in /usr/local/apache2/conf, then you will need to add this to your httpd.conf.
ServerName blog.yoursite.com
DocumentRoot /var/www/apps/projectname/current/public
The ‘*’ above may also be your specific IP address, but on anything after apache 1.3.12, ‘*’ works just fine. Now all you have to do is add an A Record to tell the interwebs to send all requests for your new subdomain to your IP address. You may need to find out how to do this with your server peeps. Here’s a good resource for messing with DNS Records.
For Slicehost, this is how you do it… go to manage.slicehost.com and login to your account. Go to the DNS tab. Go to Records for your domain. Click new record. Now, you’re going to set up a new A Record. In the ‘Name’ box, enter the subdomain that is setup for your blog in the apache2 .conf file. Mine is blog. In Data, enter your IP address. Then make the other to entries match whatever the numbers are for your www A Record that should already be set up for your Slice. My numbers are 0 and 3600 respectively. Then add it and you should be in business!
Navigate to subdomain.yoursite.com/admin login. If you get any Mephisto errors, you might have a problem with folder permissions on your server. If this is the case, SSH into your server, navigate to projectname/current, and issue the command:
sudo chmod –R 777 public
You may also need to do this for your themes directory if you plan on modifying your themes at all
sudo chmod –R 777 themes
7. W00t!
Now you’re done! Chug the rest of that beer, write your ‘Hello World’ blog post and take the rest of the night off!
June 12th, 2008 at 12:19 AM Thank you very much. This was helpful!
June 12th, 2008 at 12:24 AM Thank you very much. This was helpful!
June 14th, 2008 at 03:06 PM Buy tramadol cod Tramadol cod next day delivery Overnight tramadol cod shipping Ultram overnight without prescription US tramadol cod sales Buy zoloft without prescription Soma no prescription overnight Propecia no prescription needed Ambien shipped c.o.d Buy soma without prescription Soma cheap overnight delivery Tramadol shipped cod Soma shipped cod Buy Carisoprodol no prescription Tramadol overnight Buy ambien cod Cheap tramadol overnight Tramadol free shipping Buy zoloft online without prescription Order tramadol cod Buy fioricet without prescription
June 23rd, 2008 at 02:17 AM Tramadol without prescription Buy soma cod Tramadol next day delivery Soma overnight delivery Order tramadol cod Soma online overnight delivery Tramadol no prescription overnight Buy phentermine without prescription Phentermine 37.5 mg no prescription Order tramadol cod overnight delivery Phentermine without prescription Order tramadol overnight delivery Overnight tramadol no prescription Order Soma without prescription Order Soma without prescription Buy tramadol online without prescription Order tramadol without prescription Tramadol free shipping Buy soma no prescription Tramadol no prescription needed Buy phentermine without a prescription
July 15th, 2008 at 10:34 PM Wow! Not only informative, but entertaining, and it makes me feel less like an alcoholic for drinking the beers I'd be drinking anyway. Bravo!
July 24th, 2008 at 06:52 PM Tramadol without prescription overnight delivery Viagra No Prescription Next Day Delivery Buy Viagra Online Cod Order tramadol online without prescription buy viagra without a prescription Tramadol Cod Overnight Viagra No Prescription Overnight Delivery Order phentermine cod overnight Ambien Without A Prescription Or Doctor Ambien Cod Overnight Delivery Cheap Ambien Next Day Overnight diazepam no prescription Buy fioricet without prescription Ambien Overnight Shipping No Prescription Diazepam no prescription overnight delivery Phentermine no prescription overnight delivery Buy hydrocodone without prescription Fedex Ambien Overnight Buy Ambien With No Rx No Prescription Required For Ambien No Prescription Next Day Delivery Tramadol