Deploying your web application is very easy on TextDrive once you know what you are doing.
First, you need to have ssh access. There is a way to do it with webmin, but it is much harder. Put in a ticket for ssh access if you don’t already have it if you got your account recently you already have SSH access).
This article assumes that you have some experience with command line tools and editting configuration files.
1. Don’t forget to modify the shebang line (the first line holding the ruby path) in your railsapp/public/dispatch. files when moving from Windows to Linux. This will be the cause of an error (and many headaches) resembling: ”.... /public/dispatch.fcgi: not found
: (mod_fastcgi.c.851) child exited (is this a FastCGI? binary ?): 127
: (mod_fastcgi.c.1118) [ERROR]: spawning fcgi failed.
: (server.c.609) Configuration of plugins failed. Going down.”
The correct shebang line on TxD is: #!/usr/local/bin/ruby18
2. If you develop Rails in Windows, make sure to set your FTP transfer mode to ASCII, not Binary, as it will often insert many little strange characters like ’^M’, which will also spawn error messages like ”/public/dispatch.fcgi: not found” when you try to run lighttpd.
There now is a manual for setting up lighttpd over at TextDrive. This is () to be the authorative source for setting up lighttpd on TxD.
In a hurry? Don’t feel like mucking around with lighttpd? Try the shell script here. You’ll need your port number assigned to you by TxD before you start.
#This is my lighttpd config
server.port = 8830
#server.bind = "0.0.0.0"
server.modules = (
"mod_rewrite",
"mod_access",
"mod_fastcgi",
"mod_accesslog" )
server.indexfiles = ( "index.php", "index.html",
"index.htm", "default.htm")
server.pid-file = "/home/username/var/run/lighttpd.pid"
url.access-deny = ( "~", ".inc" )
#mime types clipped out
server.document-root = "/home/username/sites/railsapp/public/"
server.errorlog = "/home/username/sites/railsapp/log/lighttpd_error.log"
accesslog.filename = "/home/username/sites/railsapp/log/lighttpd_access.log"
server.error-handler-404 = "/dispatch.fcgi"
fastcgi.server = ( ".fcgi" =>
("rails" =>
( "socket" => "/home/username/var/lighttpd-fcgi.socket",
"bin-path" => "/home/username/sites/railsapp/public/dispatch.fcgi",
"bin-environment" => ("RAILS_ENV" => "production"),
"min-procs" => 2,
"max-procs" => 2
)
)
)
#This is my lighttpd config
server.port = 8830
#server.bind = "0.0.0.0"
server.modules = (
"mod_rewrite",
"mod_access",
"mod_fastcgi",
"mod_accesslog" )
server.indexfiles = ( "index.php", "index.html":http://blogpost.pbwiki.com/ ,
"index.htm", "default.htm")
server.pid-file = "/home/lamdor/var/run/lighttpd.pid"
url.access-deny = ( "~", ".inc" )
#mimetypes snipped out
# Defaults that will be overridden in the conditionals
server.document-root = "/home/lamdor/public_html"
server.errorlog = "/home/lamdor/logs/lighttpd-error.log"
accesslog.filename = "/home/lamdor/logs/lighttpd-access.log"
$HTTP["host"] =~ "((www\.)|(blog\.))?bitgoo\.net" {
server.document-root = "/home/lamdor/sites/typo_blog/public/"
server.errorlog = "/home/lamdor/sites/typo_blog/log/lighttpd_error.log"
accesslog.filename = "/home/lamdor/sites/typo_blog/log/lighttpd_access.log"
server.error-handler-404 = "/dispatch.fcgi"
fastcgi.server = ( ".fcgi" =>
("rails" =>
( "socket" => "/home/lamdor/var/lighttpd-fcgi.socket",
"bin-path" => "/home/lamdor/sites/typo_blog/public/dispatch.fcgi",
"bin-environment" => ("RAILS_ENV" => "production"),
"min-procs" => 2,
"max-procs" => 2
)
)
)
}
$HTTP["host"] =~ "(rubbish\.)bitgoo\.net" {
server.document-root = "/home/lamdor/sites/rubbish/public/"
server.errorlog = "/home/lamdor/sites/rubbish/log/lighttpd_error.log"
accesslog.filename = "/home/lamdor/sites/rubbish/log/lighttpd_access.log"
server.error-handler-404 = "/dispatch.fcgi"
fastcgi.server = ( ".fcgi" =>
("rubbish" =>
( "socket" => "/home/lamdor/var/lighttpd-fcgi-rubbish.socket",
"bin-path" => "/home/lamdor/sites/rubbish/public/dispatch.fcgi",
"bin-environment" => ("RAILS_ENV" => "development"),
"min-procs" => 2,
"max-procs" => 2
)
)
)
}
Luke Amdor
One difference to remember is that vhost ‘priority’ is the opposite in lighttpd than it is with Apache, so if you want different subdomain vhosts on a domain that is also a vhost, you should first put the main domain, then each subdomain in the configuration file.
LukeRandall (thanks to Jason at TxD for that knowledge)
Thanks to JustinFrench of TextDrive for helping me out.
I will use my webapplication as an example.
I created a new domain on textdrive and it is located at:
/usr/home/my\AccountUsername/domains/thedatingguy.com
You don’t put the rails application under public_html… you have to make another folder. So I create a folder called thedatingguy which resulted in the following file structure:
/usr/home/myAccountUsername/domains/thedatingguy.com/thedatingguy
Then I uploaded my rails webapplication into that directory.
To tell Apache to look into thedatingguy directory for the web application instead of public_html you have to do the following
/home/myAccountUsername/domains/thedatingguy.com/public_html to /home/myAccountUsername/domains/thedatingguy.com/thedatingguy/publicNow you should be able to go to your website and see your webapp.
So basically you are changing your Document Root Directory end part from /public_html to /where\YouHavrYoutApp/public
Do NOT delete your public_html directory!!!
And if you are on DAVIE (which uses the new /web structure instead of ~/public_html) Do NOT delete web
I hope this helps
Ok, something about config files gives me heart palpatations. I spent most of today piecing together information in order to get this working, so I wanted to share my process.
mkdir lighttpd
mkdir lighttpd/var
mkdir lighttpd/var/run
mkdir lighttpd/var/tmp
mkdir lighttpd/var/log
touch lighttpd/var/log/lighttpd.error.log
touch lighttpd/var/log/apache.log
Basically you are just making some directories and blank files that lighttpd is going to use to run. This is a good time to mention that I find it hard to type lighttpd without sounding it out in my head.
accesslog.filename = "/home/jcasimir/lighttpd/var/log/apache.log" url.access-deny = ( "~", ".inc" ) server.error-handler-404 = "/dispatch.fcgi" server.username = "jcasimir" server.groupname = "jcasimir" server.port = 1000 server.modules = ("mod_access", "mod_fastcgi", "mod_accesslog" ) server.errorlog = "/home/jcasimir/lighttpd/var/log/lighttpd.error.log" server.indexfiles = ( "index.php", "index.html", "index.htm", "default.htm", "dispatch.fcgi", "dispatch.cgi" ) server.document-root = "/home/jcasimir/domains/commonword.org/commonword/typo/public/" server.pid-file = "/home/jcasimir/lighttpd/var/run/lighttpd.pid" $HTTP["host"] =~ "commonurl.com" { server.document-root = "/home/jcasimir/domains/commonurl.com/commonurl/public/" fastcgi.server = ( ".fcgi" => ( "localhost" => ( "min-procs" => 2, "max-procs" => 2, "socket" => "/home/jcasimir/lighttpd/var/tmp/commonurl.socket", "bin-path" => "/home/jcasimir/domains/commonurl.com/commonurl/public/dispatch.fcgi", "bin-environment" => ( "RAILS_ENV" => "production" ) ) ) ) server.error-handler-500 = "/500.html" server.error-handler-404 = "/dispatch.fcgi" cgi.assign = ( ".rb" => "/usr/local/bin/ruby", ".cgi" => "/usr/local/bin/ruby" ) server.bind = "www.commonurl.com" } $HTTP["host"] =~ "commonword.org" { server.document-root = "/home/jcasimir/domains/commonword.org/commonword/public/" fastcgi.server = ( ".fcgi" => ( "localhost" => ( "min-procs" => 2, "max-procs" => 2, "socket" => "/home/jcasimir/lighttpd/var/tmp/commonword.socket", "bin-path" => "/home/jcasimir/domains/commonword.org/commonword/public/dispatch.fcgi", "bin-environment" => ( "RAILS_ENV" => "production" ) ) ) ) server.error-handler-500 = "/500.html" server.error-handler-404 = "/dispatch.fcgi" cgi.assign = ( ".rb" => "/usr/local/bin/ruby", ".cgi" => "/usr/local/bin/ruby" ) server.bind = "www.commonword.org" } $HTTP["host"] =~ "www.commontext.com" { server.document-root = "/home/jcasimir/domains/commontext.com/commontext/public/" fastcgi.server = ( ".fcgi" => ( "localhost" => ( "min-procs" => 2, "max-procs" => 2, "socket" => "/home/jcasimir/lighttpd/var/tmp/commontext.socket", "bin-path" => "/home/jcasimir/domains/commontext.com/commontext/public/dispatch.fcgi", "bin-environment" => ( "RAILS_ENV" => "production" ) ) ) ) server.error-handler-500 = "/500.html" server.error-handler-404 = "/dispatch.fcgi" cgi.assign = ( ".rb" => "/usr/local/bin/ruby", ".cgi" => "/usr/local/bin/ruby" ) server.bind = "www.commontext.com" } mimetype.assign = ( ".pdf" => "application/pdf", ".sig" => "application/pgp-signature", ".spl" => "application/futuresplash", ".class" => "application/octet-stream", ".ps" => "application/postscript", ".torrent" => "application/x-bittorrent", ".dvi" => "application/x-dvi", ".gz" => "application/x-gzip", ".pac" => "application/x-ns-proxy-autoconfig", ".swf" => "application/x-shockwave-flash", ".tar.gz" => "application/x-tgz", ".tgz" => "application/x-tgz", ".tar" => "application/x-tar", ".zip" => "application/zip", ".mp3" => "audio/mpeg", ".m3u" => "audio/x-mpegurl", ".wma" => "audio/x-ms-wma", ".wax" => "audio/x-ms-wax", ".ogg" => "audio/x-wav", ".wav" => "audio/x-wav", ".gif" => "image/gif", ".jpg" => "image/jpeg", ".jpeg" => "image/jpeg", ".png" => "image/png", ".xbm" => "image/x-xbitmap", ".xpm" => "image/x-xpixmap", ".xwd" => "image/x-xwindowdump", ".css" => "text/css", ".html" => "text/html", ".htm" => "text/html", ".js" => "text/javascript", ".asc" => "text/plain", ".c" => "text/plain", ".conf" => "text/plain", ".text" => "text/plain", ".txt" => "text/plain", ".dtd" => "text/xml", ".xml" => "text/xml", ".mpeg" => "video/mpeg", ".mpg" => "video/mpeg", ".mov" => "video/quicktime", ".qt" => "video/quicktime", ".avi" => "video/x-msvideo", ".asf" => "video/x-ms-asf", ".asx" => "video/x-ms-asf", ".wmv" => "video/x-ms-wmv" )
I am not claiming that I came up with these secret codes, I just mashed them together. One “gotcha” that I came across is that if I didn’t have a server.document-root outside of the individual virtual server sections, the server would refuse to load. I would guess that this document root is used in the case that none of the individual server “cases” is matched. BTW, this is a good time to mention that the $HTTP[“host”] line can take regular expressions. That junk is too complicated for me, though, so I am going the KISS route.
/usr/local/sbin/lighttpd -f /users/home/yourusername/lighttpd/lighttpd.conf/usr/local/sbin/lighttpd -f /home/yourusername/lighttpd/lighttpd.confWith your own username injected in there. The server should hopefully startup. If you get some errors, then grab a drink and enjoy debugging. If you get an error about the port, you probably didn’t specify the right port in the server.port line of the conf file. If you get path not found errors, well, the path probably doesn’t exist. Make sure that your apps actually exist and are in the right spots. You might consider using “rails myapp” to generate a placeholder rails app in the spot where you are going to eventually deploy your app. Something like that.
-Jeff Casimir
What about fastcgi, is there a trick to setting that up?
MikkelBruun no, just comment the dispatch.cgi rewrite in .htaccess and enable the dispatch.fcgi line below it (above it)?? Someties you need to kill the fcgi process. this can be dome from webmin → runninbg process and kill dispatch.fcgi
Does this take into consideration the new file structure that textdrive uses for virtual domains?
DickDavies it’s not related – lighttpd is running outside of apache. All apache needs is a mod_proxy to send requests over to lighttpds port.
ichigo would also be great to see something like a sort of howto do subversion with rails + txd…that might be pretty important for larger projects. unfortunately i have no clue how to do that. i just saw the weblog entry on the txd blog about the new version of svn and its ability to do fancy stuff in combination with webdav and also send mails with the changes and so on…i would really love to use these features…they really could improve development
I it possible to deploy a Rails app in a sub-folder or sub domain and still keep the main apache site intact? What parts of the configuration sample has to be changed?