Using WEBrick to Serve PHP Web Applications

I am a PHP developer who started learning Ruby on Rails. I love how easy it is to get up and running Rails applications. One of the things I like best is WEBrick. This makes it so that you do not need to configure Apache and Virtual Hosts for each small project you are working on. WEBrick makes it easy to start and stop the server so you can click on the web application.

I don’t always like working with Ruby on Rails, so I was wondering how I can configure (or change) WEBrick to be able to use it for my PHP projects and Zend Framework applications.

Have you tried to do this? What would be the necessary steps to achieve this?

+5
source share
4 answers

To get php support in webrick, you can use a handler for php files. To do this, you need to expand HttpServlet::AbstractServletand implement the methods do_GETand do_POST. These methods are called for GET and POST requests from the browser. There you just need to file an incoming request at php-cgi.

For PHPHandler to process php files, you must add it to a HandlerTablespecific mount. You can do it as follows:

s = HTTPServer.new(
    :Port => port,
    :DocumentRoot => dir,
    :PHPPath => phppath
)
s.mount("/", HTTPServlet::FileHandler, dir, 
    {:FancyIndexing => true, :HandlerTable => {"php" => HTTPServlet::PHPHandler}})

The first statement initializes the server. The second adds mounting options DocumentRoot. Here it allows you to list directories and process php files with PHPHandler. After that, the server can be started with s.start().

PHPHandler , - . webricks CGIHandler, , php-cgi. PHPHandler GitHub:

https://github.com/questmaster/WEBrickPHPHandler

+6

nginx lighttpd

lighttpd.

  • PHP FastCGI "bin-path" . MacPorts sudo port install php5 +fastcgi
  • lighttpd.conf
  • lighttpd -f lighttpd.conf , .
  • - localhost: 8000

lighttpd.conf:

server.bind = "0.0.0.0"
server.port = 8000
server.document-root = CWD
server.errorlog          = CWD + "/lighttpd.error.log"
accesslog.filename       = CWD + "/lighttpd.access.log"

index-file.names = ( "index.php", "index.html",
                    "index.htm", "default.htm" )

server.modules = ("mod_fastcgi", "mod_accesslog")

fastcgi.server = ( ".php" => (( 
  "bin-path" => "/opt/local/bin/php-cgi",
  "socket" => CWD + "/php5.socket",
)))

mimetype.assign = (  
  ".css"        =>  "text/css",
  ".gif"        =>  "image/gif",
  ".htm"        =>  "text/html",
  ".html"       =>  "text/html",
  ".jpeg"       =>  "image/jpeg",
  ".jpg"        =>  "image/jpeg",
  ".js"         =>  "text/javascript",
  ".png"        =>  "image/png",
  ".swf"        =>  "application/x-shockwave-flash",
  ".txt"        =>  "text/plain"
)

# Making sure file uploads above 64k always work when using IE or Safari
# For more information, see http://trac.lighttpd.net/trac/ticket/360
$HTTP["useragent"] =~ "^(.*MSIE.*)|(.*AppleWebKit.*)$" {
  server.max-keep-alive-requests = 0
}

php.ini, bin :

"bin-path" => "/opt/local/bin/php-fcgi -c" + CWD + "/php.ini",

nginx, , .

+3

, , . ( ), ? , , PHP, , script, , , webrick.

0

, WEBrick CGI, , PHP, CGI script. #! php-cgi.exe.

It is worth noting that you need to delete the line #!when moving the file to any other server that does not consider PHP as a CGI script, which will be ... uh ... all this.

0
source

All Articles