Running Rails and PHP on Lighttpd on Linux
Asked Answered
H

3

6

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 :)

Hammel answered 8/2, 2011 at 10:15 Comment(0)
M
3

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...

Morphophonemics answered 10/2, 2011 at 4:37 Comment(2)
$HTTP["host"] =~ "my.ror.site" -- The =~ means it's doing a regular expression comparison, which may not be needed. Use == when you want to do a normal string comparison. More info. Other than that, thanks for the sample!Storfer
@Garret: Good point. I actually use regex in mine (because there are more than one domains that point to it, for a few reasons). I just stripped it out (sanitized) for posting here. But that's something worth mentioning...Morphophonemics
S
1

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.

Storfer answered 9/2, 2011 at 1:8 Comment(0)
F
-2

I don't use Lighty. Rails is best served with Passenger and Apache, considering the power of Passenger add-on to Apache. I served Wordpress (PHP) in the same domain as my Rails app by pointing its path to somewhere else. Here's an article to follow. HTH.

Forgetmenot answered 8/2, 2011 at 10:53 Comment(1)
Thanks for the reply, but I asked for help with configuring it to run on lighty, not apache. Specifically not Apache.Hammel

© 2022 - 2024 — McMap. All rights reserved.