Launching Rails at the Speed of Lite with LiteSpeed Webserver 2
A walkthrough of how to configure Rails on the LiteSpeed Webserver.
A relatively unknown webserver from LiteSpeed Technologies claims to be six times faster than Apache with a PHP interface that is 50% faster than mod_php. Bold claims, but in my testing, they are not too far from the truth. Lets get started...
T minus 10
Litespeed webserver is available in 3 editions, the standard edition being free (for both personal and commercial use). You can download the latest free version for your platform here. At the time of this writing, 2.1.9 is the current release and there is no windows version (which is a shame because we all know windows needs a fast webserver).T minus 9
Installing Litespeed is what you would expect for a commercial product.
Extract the tar ball.
# tar xf lsws-2.1.9.tar.gzRun the installation
# cd lsws-2.1.9# ./install.sh
This begins the installation process. Take notice that the EULA forbids using it to serve or even affiliate with what they consider to be "illegal" content, even for their paid versions. Interesting concept, nice to see people with the balls to stand up for what they believe, although I don't think the license would hold up in a court of law.
You may want to write down the port you choose to run the administration interface on. I choose 81 because I never write these things down and end up forgetting what I chose.
If you get lost trying to install it then you probably shouldn't attempt the rest of this walkthrough, but if you are a trooper, you can refer to the official documentation.
T minus 8
From this point, I am going to assume you have Ruby and Rails installed already and that you have a Rails project created. If not, you can follow some excellent tutorials here.
T minus 7
Fire up your favorite web browser and login to the LiteSpeed Service Manager. You didn't forget what port you put it on did you? Yea, I thought so, the default port is 7080.
http://mywebserver.com:7080
T minus 6 and counting
All server administration is done through this Service Manager. Click the Server Configuration button on the left and lets get started on the fun part.
- Create a new virtual host by clicking 'Virtual Host' in the left navbar.
- This brings up a list of Virtual Hosts. Click Add to add a new one.
- Give your VH a name. This is an identifer only so call it whatever you want.
- For the Virtual Host root, make it the root of your Rails project you are going to use for this walkthrough. You'll see why in a minute.
- In the Config File textbox, enter $VH_ROOT/config/vh_conf.xml. This will store the Virtual Host configuration in your Rails Project config directory.
- Turn on Follow Symbolic Links
- Select Yes for Enable Script and Yes for Restrained
- Save your changes. It may give an error that the config file doesnt exist. Click the CLICK TO CREATE link to create it. Read the warning below first. Now save your changes again. A bit clumsy, but I'm sure they have a reason to do it like that.
I'll leave the rest of the options for you to figure out, none are required to get Rails running. If you need more information on a particular setting, click the Help link in the top banner.
WARNING: Make sure the permissions on your Rails Project config and log directory allow the webserver user write access.
STRONGER WARNING: The service manager has a very short login timeout. Don't be idle for too long without saving or you may lose all your hard work.
T minus 5
Time to buckle in and get ready for to launch. If you successfully saved your Virtual Host, it will be listed in the left navbar under Virtual Hosts. Click on it and lets configure it.
T minus 4
On the General tab, edit the following sections:
General
- Set Document Root to $VH_ROOT/public
- For fun, enter your email address so LiteSpeed can send you Cease and Desist letters when your advertising provider let's a porn ad sneak into the mix (yes it does happen and yes you would be violating the EULA).
- Save your changes
Virtual Host Log
- Edit the Virtual Host Log section now
- Choose No on Server Logs
- Enter $VH_ROOT/log/lsws.log
- Leave Log Level at Error and set Rolling Size to something like 10M
T minus 3 - We're a GO for launch
On the External Apps tab, click Add and prepare to fire the auxillary boosters:
- Select Fast CGI App for the type and click Next
- Give this Fast CGI Instance a unique name
- For the address, this can be a socket or unix domain socket. We will use a uds here. Enter something like: uds://tmp/lshttpd/myrailsapp.sock
- Enter something modest for the Max Connections, 20 is good. Make sure you enter the same number in the Instances field
- Important step: In the Environment setting enter: RAILS_ENV=production
- Initial Request Timeout => 60
- Retry Timeout => 0
- Persistent Connection => NO - Rails will not work if persistent connection is on
- Auto Start => Yes
- Heres the big one. $VH_ROOT/public/dispatch.fcgi
- Backlog => 100
- Instances - Should match Max Connections
- Memory Soft Limit => 80M
- Memory Hard Limit => 100M
- Process Soft Limit => 200
- Process Hard Limit => 200
T minus 2 - Fire the boosters
Back on the General tab, you will need to add a Script Handler for fcgi to the External App you just created. In the Suffixes field, enter fcgi, Handler Type to Fast CGI and Handler Name, whatever you just named your Handler. Get ready for liftoff!
T minus 1
Now its time to tell LiteSpeed how to handle Pretty URLs. This is done on the Rewrite tab.
- Enable Rewrite to on
- Log Level to 9
RewriteRule ^$ index.html [QSA]
RewriteRule ^([^.]+)$ $1.html [QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ dispatch.fcgi [QSA,L]
Save your changes and we are almost there.
Back at the front of the Server Configuration page, select the Default listener under the Listeners on the left navbar. For Virtual Host Mappings, add a mapping to your new Virtual Host by entering the domain name you will use to access it.
The final step will be to apply your changes to the webserver. In the top banner bar, click Apply Changes, then Graceful Restart.
WE HAVE LIFTOFF
Load up your browser again and enter your servers url and off you go! (Assuming again that you have a valid Rails Project)
If everything went as planned, you should be moving at the Speed of Lite on Rails. Otherwise, you may be fish bait, its not pretty when these launches go bad.
This is the first blog entry/tutorial I have ever written so it will be a little rough around the edges. I hope to refine my skills by writing more helpful tutorials. Feel free to tell me if it helped or was totally useless.
Sírkő Urnasír | Józsa Kft. Cserkeszőlő