SkillAgentSearch skills...

WEBrickPHPHandler

This is a PHPHandler for the ruby WEBrick minimal webserver. With an PHP installation the webserver can process php files and serve php websites.

Install / Use

/learn @questmaster/WEBrickPHPHandler
About this skill

Quality Score

0/100

Supported Platforms

Universal

README

WEBrick - PHPHandler

In this project a PHPHandler for the ruby WEBrick minimal webserver was created. With an PHP installation the webserver can process php files and serve php websites.

Files

  • docroot => example webserver root directory
  • main.rb => example webserver start script
  • phphandler.rb => PHPHandler for WEBrick

Prerequisites

  • Ruby with WEBrick
  • The handler supports PHP 5 and needs a PHP 5 installation.
  • The WEBrick configuration :DocumentRoot has to be set
  • The new WEBrick configuration :PHPPath has to be set

It is assumed that all php files are accessible from the :DocumentRoot path.

Usage

With the mount() method the PHPHandler can be registered for files with the .php file extension in the :HandlerTable. Additionally :DocumentRoot has to be set to be able to resolve the local path of the files to be processed. Also the :PHPPath variable has to be set to the location of the PHP 5 'php-cgi.exe' location.

require 'webrick'
require_relative 'phphandler'
include WEBrick

# fill config vars
dir = File.join(File.dirname(__FILE__), "docroot")
port = 8080
phppath = File.join(File.dirname(__FILE__), "php-5.4.9-Win32-VC9-x86").gsub("/", "\\")

# create new server with config from vars
server = HTTPServer.new(
    :Port => port,
    :DocumentRoot => dir,
    :PHPPath => phppath
)

# mount document root again to set new options (add PHPHandler for .php files)
server.mount("/", HTTPServlet::FileHandler, dir,
    {:FancyIndexing => true, :HandlerTable => {"php" => HTTPServlet::PHPHandler}})

# start server / prepare shutdown
trap("INT") { server.shutdown }
server.start
View on GitHub
GitHub Stars12
CategoryDevelopment
Updated3y ago
Forks0

Languages

Ruby

Security Score

60/100

Audited on Mar 22, 2023

No findings