Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running Rails and PHP on Lighttpd on Linux

Well, I'm wondering if theres a way to run both rails and PHP on Lighty, on Ubuntu. I want to run both my PHP projects and Rails projects on the one server/domain.

I have little experience with Linux really, so forgive my naivety.

If theres a way of doing this please let me know :)

like image 363
Zen Avatar asked Feb 08 '11 10:02

Zen


2 Answers

It's really quite simple to run them both. I do it all the time (ROR to run Redmine, and PHP for the rest).

You have 2 real options for ROR. Either serve it from FastCGI (what I do), or run it with a standalone server (like Mongrel, etc) and proxy to it. Both have advantages. FastCGI has the advantage that it's self-contained (no secondary server to run). The standalone has the advantage that it's easier to configure.

If you have specific questions, I can guide, but there are guides on the internet on how to do this.

My lighttpd.conf:

$HTTP["host"] =~ "my.ror.site" {
    server.error-handler-404="/dispatch.fcgi"
    fastcgi.server = (".fcgi" => ("ror_1" => (
            "min-procs"=>8,
            "max-procs" => 8,
            "socket" => "/tmp/myrorlock.fastcgi",
            "bin-path"=> "/path/to/ror/site/public/dispatch.fcgi",
            "kill-signal" => 9,
            "bin-environment" => ( "RAILS_ENV" => "production" )
    )))
}

fastcgi.server = ( ".php" =>
    (
        (
            "socket" => "/tmp/php-fastcgi.socket",
            "bin-path" => "/usr/bin/php-cgi -c /etc/php.ini",
            "min-procs" => 1,
            "disable-time" => 1,
            "max-procs" => 1,
            "idle-timeout" => 20,
            "broken-scriptfilename" => "enable",
            "bin-copy-environment"=> (
                "PATH", "SHELL", "USER"
            ),
            "bin-environment" => (
                "PHP_FCGI_CHILDREN" => "40",
                "PHP_FCGI_MAX_REQUEST" => "50000"
            )
        )
    )
)

And that's it. Note the kill-signal option. that's important, otherwise you'll wind up with zombie processes everywhere every time you restart the server...

like image 50
ircmaxell Avatar answered Oct 30 '22 15:10

ircmaxell


Check out fastcgi.conf in the conf.d subdirectory of Lighty's configuration directory (not sure where it's located on Ubuntu, but a quick search suggests /etc/lighttpd). There are commented-out examples for both PHP and Rails; by combining the two, you should be able to get the set-up you're looking for (though I'd suggest getting one working first and then setting up the other).

FastCGI is the method by which Lighty can communicate with runtimes like Ruby or PHP. Lighty can also use SCGI, though I've never use it myself and am not sure how well it works (last I heard it was still experimental-ish).

You may also find the Optimizing FastCGI page on Lighty's documentation wiki helpful, though it's fairly PHP/MySQL-specific.

like image 28
Garrett Albright Avatar answered Oct 30 '22 16:10

Garrett Albright