ROR安装过程

Step 1: As usual, the first thing we'll want to do is make sure your version of Hardy Heron 8.04 is up to date.:

sudo apt-get update
sudo apt-get dist-upgrade

Step 2: We'll be installing some software that needs to be built so we'll need to get packages required for compiling. In one swoop, you can type this command and get everything you need:

sudo apt-get install build-essential

Step 3: Once you've got the tools, it's time to grab MySQL and Ruby. Just copy and paste this command into your terminal if you're in a hurry.

sudo apt-get install ruby ri rdoc mysql-server libmysql-ruby ruby1.8-dev irb1.8 libdbd-mysql-perl libdbi-perl libmysql-ruby1.8 libmysqlclient15off libnet-daemon-perl libplrpc-perl libreadline-ruby1.8 libruby1.8 mysql-client-5.0 mysql-common mysql-server-5.0 rdoc1.8 ri1.8 ruby1.8 irb libopenssl-ruby libopenssl-ruby1.8 psmisc

If you hadn't previously installed MySQL you'll be asked to set a root password. Don't forget what you choose!

Step 4: Grab the latest ruby gems and install them. As always be sure to check rubyforge.org to make sure you're grabbing the latest one. As of this writing it's 1.1.1 but it never hurts to check.

wget http://rubyforge.org/frs/download.php/35283/rubygems-1.1.1.tgz
tar xvzf  rubygems-1.1.1.tgz
cd rubygems-1.1.1
sudo ruby setup.rb

Once it's done you can remove the .tgz file and erase the rubygems-1.1.1 directory too.

Step 5: Make symlinks. Just in case the symlinks did not get created for you (the symlink for gem was missing for me so don't assume) go ahead and create them with these commands:

sudo ln -s /usr/bin/gem1.8 /usr/local/bin/gem
sudo ln -s /usr/bin/ruby1.8 /usr/local/bin/ruby
sudo ln -s /usr/bin/rdoc1.8 /usr/local/bin/rdoc
sudo ln -s /usr/bin/ri1.8 /usr/local/bin/ri
sudo ln -s /usr/bin/irb1.8 /usr/local/bin/irb

Step 6: Install ruby on rails!! I installed this on a minimal Slicehost install and it took forever because of the limited ram. I'm going to suggest you run the command and skip the rdoc and ri installs unless you really want them. (in which case the below command is simply sudo gem install rails)

sudo gem install rails --no-rdoc --no-ri

Step 7: Let's install mongrel now that we've got ruby gems and rails working. If you've done this before you'll be happy to see that it's getting easier as rubygems is now grabbing dependencies and also checking your architecture.

sudo gem install mongrel --no-rdoc --no-ri

At this point you have a complete rails stack ready for local development on Hardy, Sidux, or Debian. If you want to get things going for a server (install nginx, mongrel cluster) then read on. Otherwise you're done, so happy developing!

Step 8: The first thing in preparing to deploy this sucker is to grab a real web server. I'm still using Nginx.. haven't been disappointed with performance in the slightest.

sudo apt-get install libpcre3 nginx libfcgi-dev libfcgi-ruby1.8 libfcgi0ldbl

When it asks you what webserver to pre-configure leave everything blank. We're using nginx not apache this time. (Apache 2 with Ruby on Rails for Gutsy is covered here.)

Step 9: Let's install and configure mongrel cluster. This is a lengthy set of tasks each of which is important so please pay special attention and seek help in your favorite forums if you aren't familiar with linux. For new users: tab-autocomplete is your friend.

sudo gem install mongrel_cluster --no-rdoc --no-ri

Copy the init file over to /etc/init.d/ by typing this all on one line:

sudo cp /usr/lib/ruby/gems/1.8/gems/mongrel_cluster-1.0.5/resources/mongrel_cluster /etc/init.d/mongrel_cluster

You may need to change the above command if a version other than mongrel_cluster-1.0.5 was installed.

Next, add a path statement to mongrel_cluster file just above the CONF_DIR variable:

sudo vi /etc/init.d/mongrel_cluster
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local:/usr/local/sbin:/usr/local/bin

You may also want to change the USER=mongrel to USER=www-data but I'll leave that up to you.

Let's modify permissions and make sure we boot mongrel on startup:

sudo chmod +x /etc/init.d/mongrel_cluster
sudo update-rc.d mongrel_cluster defaults

We're not quite done yet -- we need to setup the mongrel cluster correctly [source]. This assumes your primary rails app is in /var/www/myrailsapp. Modify the below line according to your setup.

sudo mongrel_rails cluster::configure -e production \ -p 8000 -N 3 -c /var/www/myrailsapp -a 127.0.0.1 \ --user www-data --group www-data

Now let's create a symlink to that file from within /etc where all our configs live:

sudo mkdir /etc/mongrel_cluster
cd /etc/mongrel_cluster/
sudo ln -s /var/www/myrailsapp/config/mongrel_cluster.yml

You can download a sample mongrel_cluster file HERE. Regardless, I think it's a good idea to download it and compare it to what the above command produced.

Step 10: We're *almost* done. Next step is to configure Nginx. Here's a sample nginx.conf file for your /etc/nginx/ folder. It's set up to handle one rails app and phpmyadmin. Adding additional servers just means more server blocks. I strongly suggest backing up your original nginx.conf file before copying this over.

The last step is to turn everything off and then turn it on again:
Mongrel (stop): sudo /etc/init.d/mongrel_cluster stop
Mongrel (start): sudo /etc/init.d/mongrel_cluster start
Nginx (stop):sudo /etc/init.d/nginx stop
Nginx (start): sudo /etc/init.d/nginx start

Bonus: Right now you're ready to go, but you should consider installing the mysql gem as well to boost performance. Do that by grabbing the headers and installing the gem.

sudo apt-get install libmysqlclient-dev
sudo gem install mysql --no-rdoc --no-ri

Troubleshooting: If your rails app fails to start:

    * Make sure your database settings are correct in your config/database.yml file. Especially look at the socket and mysql password.
    * Be sure that your rails app has the correct permissions. You can do that by running sudo chown -R www-data:www-data /var/www/railsapp This command may change depending on how you set up nginx and mongrel!
    * Check to see all the gems you need for your app are installed
    * Check to see if your app starts in development mode with a simple sudo ruby script/server. If not, check the output message
    * Always check your production log. If you don't have one, create it using sudo touch production.log and set it using sudo chmod 0666 production.log

That should be it. I always seem to miss some small detail or another so feel free to leave a comment if I overlooked or skipped a step. Happy coding!

你可能感兴趣的:(mysql,nginx,Ruby,Rails,rubygems)