Z
zero@
Guest
This is how I got Ruby on Rails (RoR) working on my Plesk machine. I didn't find any major problems with Plesk's implementation, although it took me about 6 hours of trial-and-error to get it working right. SWSoft - you could seriously use some documentation for each Operating System you support.
My OS: Debian stable, using the default Rails package and fcgid. In this entry, I will try to remember everything I did to get it working. I may forget something. Your system may be different than mine. You may use yum instead of apt-get. All I know is what I know (which is not much), but I will try to help out anyone who needs help. Hopefully others will join in.
Before we begin, some warnings: I am not an expert! Be careful with what I show you here. I may be completely off-base, and if I am, please feel free to tell me. The instructions are Debian-centric, so you may have things installed in different places. Line numbers that I give below might be different on your machines, or in future versions of Rails, so use your best judgment when making changes.
Also, VERY important: It is NEVER good practice to create applications directly on your server! You should do development on a local development server, or your own workstation, and then transfer it to your server when you are fairly certain that it works and is secure. Any Rails application that I show below should NOT, under any circumstance, be left on your server for anything other than testing.
In these instructions, I try to be as generic as possible. Anything inside {brackets} should be changed to your own personal settings.
First thing's first: In your Plesk control panel, make sure that you have your server updated with Ruby On Rails is installed. To do so, go to Server > Updater and enable "Ruby on Rails Support."
After this, go to your domain, and enable FastCGI, which will allow your site to use RoR.
Open up a terminal, log in to your server. First, let's make sure that we have the important parts installed:
Now let's make sure that we have the correct version of FastCGI installed. We want to use mod-fcgid rather than mod-fastcgi.
There may be some packages I'm forgetting. Originally, for some reason my machine had everything installed, but I had ruby1.8, and not the basic "ruby" package (which just points to ruby 1.8, I think). So every time the application called for "/usr/bin/env ruby" it couldn't use it. That might have been my screw-up, but I don't think it was. Anyway, just FYI.
Change to your httpdocs directory:
Create a basic rails application. To do so, use this command:
Remember to replace {railsapp} with the name of your application.
Change the file ownership to the domains user/group:
Change the permissions on the sessions directory:
Note: Someone let me know if this is a bad idea ... I don't think it is, but I'm not sure. My system had problems writing to the sessions folder unless I chmod'd 777.
Change directory to your new application and edit your .htaccess file in the public/ directory:
On line 2, change:
To:
On line 32, change:
To:
Test your installation. Go to http://www.{domainname.com}/{railsapp}/public/
You should see the standard "Welcome Aboard" Rails index page. If you click "About Your Application's Environment," you will see an error. It should read:
"Application error
Rails application failed to start properly"
Note: This error occurs because Rails 1.1.6 (the version of Rails installed by default on Plesk systems), is stable, and not cutting edge. It was an emergency security release, and this part of the application did not work. This is a known issue, and not a big one. It will not be fixed in Rails 1.1.6. You'll have to install the most up-to-date version manually (probably via gem) to get this working, and it's not worth it for the purposes of just getting Rails working.
Now, let's edit the configuration for fcgid:
Take note to make sure that the SocketPath is pointing to the right place. You configuration should already point to the right place, so don't change anything that doesn't need to be changed! Anything that is missing from your configuration that is listed here, add to your configuration.
I'm sure that you can add these config items to each vhost.conf file, but for my purposes, it's not important to do so because I don't use fcgid for anything other than Rails on this server. So I'll just add it to the main config.
Make sure that the fcgid module is enabled:
Restart apache2:
Now let's create an actual application for testing. It's relatively simple and fast. First, you need to go back into your Plesk control panel, and create a blank mySQL database for your domain, and a new user and password for that database. Edit your new application's database configuration with these new settings. Let's change the "Production" settings for now:
Again, this is just for testing. Normally you would have settings for development, test & production.
Now let's change your app's environment variables.
Add this around the top few lines:
Restart apache2:
This example is from the excellent book Rails Cookbook from O'Reilly. This is from the first few pages. It is an excellent book, and my tutorial will do it no justice
Instead of creating database tables by hand, make sure you are in your {railsapp} directory and use this command:
You may have to add 'ruby' to the beginning of that line, but probably now. That created a file in db/migrate named 001_build_db.rb . Let's edit this file, and change it to the following:
Run the following command to build the table:
rake db:migrate
The language table is built! We are creating a simple language application to list languages and their descriptions. Now we just need to use scaffolding to create the application. That's easy:
Now let's boot up WEBrick and see if the app is working
Go to your app: http://www.{domainname.com}:3000/languages/
It should be working! Now stop WEBrick using Control-C, and go to your application here:
http://www.{domainname.com}/{railsapp}/public/languages/
That's it for now. See if these help, and post if you experience any issues. Be sure to check your application's error log (in log/production.log), apache2's error log (/var/log/apache2/error_log), and your domain's error log if it doesn't show up.
My OS: Debian stable, using the default Rails package and fcgid. In this entry, I will try to remember everything I did to get it working. I may forget something. Your system may be different than mine. You may use yum instead of apt-get. All I know is what I know (which is not much), but I will try to help out anyone who needs help. Hopefully others will join in.
Before we begin, some warnings: I am not an expert! Be careful with what I show you here. I may be completely off-base, and if I am, please feel free to tell me. The instructions are Debian-centric, so you may have things installed in different places. Line numbers that I give below might be different on your machines, or in future versions of Rails, so use your best judgment when making changes.
Also, VERY important: It is NEVER good practice to create applications directly on your server! You should do development on a local development server, or your own workstation, and then transfer it to your server when you are fairly certain that it works and is secure. Any Rails application that I show below should NOT, under any circumstance, be left on your server for anything other than testing.
In these instructions, I try to be as generic as possible. Anything inside {brackets} should be changed to your own personal settings.
First thing's first: In your Plesk control panel, make sure that you have your server updated with Ruby On Rails is installed. To do so, go to Server > Updater and enable "Ruby on Rails Support."
After this, go to your domain, and enable FastCGI, which will allow your site to use RoR.
Open up a terminal, log in to your server. First, let's make sure that we have the important parts installed:
Code:
apt-get install ruby-rails ruby ruby1.8 ruby-activesupport psa-rubyrails-configurator
Now let's make sure that we have the correct version of FastCGI installed. We want to use mod-fcgid rather than mod-fastcgi.
Code:
apt-get remove libapache2-mod-fastcgi --purge
apt-get install libapache2-mod-fcgid psa-mod-fcgid-configurator
There may be some packages I'm forgetting. Originally, for some reason my machine had everything installed, but I had ruby1.8, and not the basic "ruby" package (which just points to ruby 1.8, I think). So every time the application called for "/usr/bin/env ruby" it couldn't use it. That might have been my screw-up, but I don't think it was. Anyway, just FYI.
Change to your httpdocs directory:
Code:
cd /var/www/vhosts/{domainname.com}/httpdocs
Create a basic rails application. To do so, use this command:
Code:
rails {railsapp}
Remember to replace {railsapp} with the name of your application.
Change the file ownership to the domains user/group:
Code:
chown {user}:{group} {railsapp}
Change the permissions on the sessions directory:
Code:
chmod 777 {railsapp}/tmp/sessions
Note: Someone let me know if this is a bad idea ... I don't think it is, but I'm not sure. My system had problems writing to the sessions folder unless I chmod'd 777.
Change directory to your new application and edit your .htaccess file in the public/ directory:
Code:
nano {railsapp}/public/.htaccess
On line 2, change:
Code:
AddHandler fastcgi-script .fcgi
Code:
AddHandler fcgid-script .fcgi
On line 32, change:
Code:
RewriteRule ^(.*)$ dispatch.cgi [QSA,L]
Code:
RewriteRule ^(.*)$ dispatch.fcgi [QSA,L]
Test your installation. Go to http://www.{domainname.com}/{railsapp}/public/
You should see the standard "Welcome Aboard" Rails index page. If you click "About Your Application's Environment," you will see an error. It should read:
"Application error
Rails application failed to start properly"
Note: This error occurs because Rails 1.1.6 (the version of Rails installed by default on Plesk systems), is stable, and not cutting edge. It was an emergency security release, and this part of the application did not work. This is a known issue, and not a big one. It will not be fixed in Rails 1.1.6. You'll have to install the most up-to-date version manually (probably via gem) to get this working, and it's not worth it for the purposes of just getting Rails working.
Now, let's edit the configuration for fcgid:
Code:
nano /etc/apache2/mods-available/fcgid.conf
Code:
<IfModule mod_fcgid.c>
AddHandler fcgid-script .fcgi
SocketPath /var/lib/apache2/fcgid/sock
DefaultInitEnv RAILS_ENV production
IdleTimeout 600
ProcessLifeTime 3600
MaxProcessCount 8
DefaultMaxClassProcessCount 3
IPCConnectTimeout 8
IPCCommTimeout 48
</IfModule>
Take note to make sure that the SocketPath is pointing to the right place. You configuration should already point to the right place, so don't change anything that doesn't need to be changed! Anything that is missing from your configuration that is listed here, add to your configuration.
I'm sure that you can add these config items to each vhost.conf file, but for my purposes, it's not important to do so because I don't use fcgid for anything other than Rails on this server. So I'll just add it to the main config.
Make sure that the fcgid module is enabled:
Code:
a2enmod fcgid
Restart apache2:
Code:
apache2ctl graceful
Now let's create an actual application for testing. It's relatively simple and fast. First, you need to go back into your Plesk control panel, and create a blank mySQL database for your domain, and a new user and password for that database. Edit your new application's database configuration with these new settings. Let's change the "Production" settings for now:
Code:
nano {railsapp}/config/database.yml
Code:
production:
adapter: mysql
database: {database_name}
username: {database_username}
password: {database_userpassword}
host: localhost
Again, this is just for testing. Normally you would have settings for development, test & production.
Now let's change your app's environment variables.
Code:
nano {railsapp}/config/environment.rb
Add this around the top few lines:
Code:
ENV['RAILS_ENV'] = "production"
RAILS_ENV = ENV['RAILS_ENV']
Restart apache2:
Code:
apache2ctl graceful
This example is from the excellent book Rails Cookbook from O'Reilly. This is from the first few pages. It is an excellent book, and my tutorial will do it no justice
Instead of creating database tables by hand, make sure you are in your {railsapp} directory and use this command:
Code:
script/generate migration build_db
You may have to add 'ruby' to the beginning of that line, but probably now. That created a file in db/migrate named 001_build_db.rb . Let's edit this file, and change it to the following:
Code:
class BuildDb < ActiveRecord::Migration
def self.up
create_table :languages, :force => true do |t|
t.column :name, :string
t.column :description, :string
end
end
def self.down
drop_table :languages
end
end
Run the following command to build the table:
rake db:migrate
The language table is built! We are creating a simple language application to list languages and their descriptions. Now we just need to use scaffolding to create the application. That's easy:
Code:
script/generate scaffold language
Now let's boot up WEBrick and see if the app is working
Code:
script/server
Go to your app: http://www.{domainname.com}:3000/languages/
It should be working! Now stop WEBrick using Control-C, and go to your application here:
http://www.{domainname.com}/{railsapp}/public/languages/
That's it for now. See if these help, and post if you experience any issues. Be sure to check your application's error log (in log/production.log), apache2's error log (/var/log/apache2/error_log), and your domain's error log if it doesn't show up.