1.从www.ruby-lang.org下载ruby-one click for windows安装包,双击按“安装向导”即可安装。以上安装包中包含RubyGems和SciTE,所以不需要单独下载安装。
2.安装rails:在确保网络连通的情况下,运行à”cmd”à运行命令:
gem install rails --include-dependencies
3. http server(mongrel)安装:
gem install win32-service (pick the most recent one)
gem install mongrel (pick the win32 pre-built)
gem install mongrel_service
升级:
gem update
4. Running The Service
After you do the gem install, find a Rails application you want to run and do:
mongrel_rails service::install -N myapp -c c:/my/path/to/myapp -p 4000 -e production
mongrel_rails service::start -N myapp
Now hit the port and poof, works (or should).
The application will stop if you use:
mongrel_rails service::stop -N myapp
NOTE: Stop reports an exception but does stop the service.
Now the really great thing is that you can just do all this from the Services control panel like your Rails application is a regular Windows service.
Even works in development mode, which is pretty nice. I use win32 at work now and what I have setup is three services: myapp_dev, myapp_stage, myapp_prod. I point dev and stage at the same directory but run dev in development mode and stage in production mode. Then I have myapp_prod in a separate directory and when I’m about to claim I’ve got something to release I’ll go simulate a subversion check-out and run my tests again.
Other Service Commands
There is a full set of service control commands in the mongrel_service plugin. This lets you use either the Services control panel or a command line script to manage your Rails applications. What’s also nice is that you can register as many applications as you want, and even the same one with different names.
service::install
If you want to run the same app in different modes then use the -N option to the install command:
mongrel_rails service::install -N myapp_dev -c c:/my/path/to/myapp -p 4000 -e development
mongrel_rails service::start -N myapp
You can also use the -D option to give the service a different display name in the Services console.
service::start
Pretty much just takes a service name to start up. It will run and print a message until the service finally starts, which sometimes can take 10-60 seconds.
service::stop
Sort of works right now and also only takes a -N parameter. It has a few errors when it tries to stop a service so we’re working on making it cleaner.
NOTE: since mongrel_service 0.3.1 , start and stop commands were removed. Use net start / net stop instead.
service::remove
Takes the name (-N) of the service to remove and then removes it from the list. This would be how you’d remove a service so you can change it’s start-up options.
CPU Affinity
Mongrel’s win32 support actually is able to set the CPU affinity of a running Mongrel service. This is pretty neat since it means if you’re running a fancy SMP machine or a dual core that pretends to be SMP, then you can force Mongrel onto one of them and get a nice little boost.
It’s pretty easy to use, just pass the -u or—cpu option to the install command and give a CPU of 1-X. That means if you have 4 CPUs and you want Mongrel on #4 then do:
mongrel_rails service::install -N myapp -c c:/my/path/to/myapp -p 4000 -e production -u 4
Pretty much the same command, just one more option and you’re done.
Making you Service autostart with Windows
By default, the new Mongrel service get installed to be run manually, using Mongrel’s commands or the Service Manager. You could tweak it to start automatically when Windows start, just use the Service Control command line tool:
sc config myapp start= auto
Also, you can configure the services that are neede to make it work, like database support:
sc config myapp start= auto dependency= MySql
The space after the equal sign is needed for the command to complete successfully.
5.补充一下:如果需要用数据库,可以到www.mysql.org下载mysql