Php Support

Jul 8, 2012 at 12:00 AM

ok so trying to embed this into one of my applications. everything works great except that Php does not work

i added wo80's httpserver.addons and followed instructions to get php support. however i either get a 403 forbidden file type or by adding the mime type to the code i get prompted to download the php file, or a third is there is no errors, but all it does in load a blank page and have the php source code viewable by using 'view source' in the browser. html documents and such all work fine, server is running, ect ...

i verified pathing to the php-cgi.exe, no go. Thought it might be a bit depth issue so i switched to a 32bit debug build but still no go. just getting 403 forbidden file type.

anyone have any ideas? or is there another solution to get php support?

Jul 8, 2012 at 9:45 AM
Edited Jul 8, 2012 at 9:49 AM

Go to CgiHandler.cs, line 96. There's a TODO. Change the line

response.Add(new StringHeader(name, val));
if (name.ToLowerInvariant() == "content-type")
    response.ContentType.Value = val;
    response.Add(new StringHeader(name, val));
and let me know if it solves the issue.

Jul 8, 2012 at 4:05 PM

no go. maybe i am doing something wrong, here is my server class (VB.NET). 

Imports System
Imports System.IO
Imports System.Net
Imports HttpServer
Imports HttpServer.Addons
Imports HttpServer.Addons.Resources
Public Class vwdWebServer
    Dim listner As HttpServer.HttpListener
    Dim _server As Server
    Dim _resource As FileResources
    Dim _router As DefaultIndexRouter
    Dim _fileModule As FileModule
    Dim dirModule As DirectoryModule
    Dim fcgi As FastCgiApp
    Dim fcgiModule As FastCgiModule
    Dim cgiModule As CgiModule
    Dim _parent As MainForm
    Dim port As Integer
    Dim rootPath As String
    Public Sub New(ByVal root As StringByVal p As Form)
        _parent = DirectCast(p, MainForm)
        port = My.Settings.webserverport
            rootPath = root
            listner = HttpServer.HttpListener.Create(IPAddress.Loopback, port)
            _server = New Server()
            _server.MaxContentSize = 1024
            _resource = New FileResources("/", root)
            _router = New DefaultIndexRouter()
            _router.ServeDefaultIndex = True
            _fileModule = New FileModule()
            _fileModule.EnableCompression = True
            dirModule = New DirectoryModule()
            Dim phppath As String = Application.StartupPath & "\data\php"
            cgiModule = New CgiModule()
            cgiModule.AddCgiApplication("php", phppath & "\php-cgi.exe")
            'fcgi = New FastCgiApp(phppath & "\\php-cgi.exe", "-b {endpoint}", New IPEndPoint(IPAddress.Any, 8129))
            'fcgiModule = New FastCgiModule()
            'fcgiModule.AddFastCgiApplication("php", fcgi)
        Catch ex As Exception
            _parent.appconsole.consolertf.AppendText("Error Starting Development Server: " & ex.Message & vbNewLine)
        End Try
    End Sub
    Public Sub StartServer()
        If (_server IsNot NothingThen
            _parent.appconsole.consolertf.AppendText("Development Server Started at: http://" & listner.Address.ToString & ":" & port & ", On Path: " & rootPath & vbNewLine)
        End If
    End Sub
    Public Sub StopServer()
        If (_server IsNot NothingThen
            _parent.appconsole.consolertf.AppendText("Development Server Has been Stopped" & vbNewLine)
        End If
    End Sub
End Class
Jul 8, 2012 at 7:16 PM

Ok, my stupid fault. In HttpServer.Addons, FileModule.cs, line 138, change

if (!ContentTypes.TryGetValue(fileExtension, out header))
    throw new ForbiddenException("Forbidden file type: " + fileExtension);


if (!ContentTypes.TryGetValue(fileExtension, out header))
    return ProcessingResult.Continue;
This should be it ...

Jul 8, 2012 at 7:30 PM

brilliant!! now it works. Now i am getting the response (or one of them) that i was expecting (which is a php error). Brilliant mate. Thanks a ton.

oh and one more question, is mysql support possible with this addon?

Jul 8, 2012 at 8:06 PM

Using mysql from php should be no problem. It's a matter of configuring php right and doesn't affect the webserver itself.

Jul 8, 2012 at 8:21 PM

good to know. thank you for your help mate. :) mez iz a happy developer now :P

Jul 8, 2012 at 9:37 PM

sorry for being a pain, but another thing i have found with php support.

does this not support things like CodeIgniter Php Framework or the like? (IE: Zend, FuelPHP, ect ...)

because with CI for example it has a permitted_uri_chars config item, when this has any value (ie, default is: a-z 0-9~%.:_\-) a server url of: produces invalid uri characters, leaving this empty produces a 404 error, while on IIS for example it works perfectly no matter what this variable has in it. should i be using one of the MVC servers in the framework?I don't see why though, it should work should it not?

Jul 8, 2012 at 11:07 PM
Edited Jul 8, 2012 at 11:39 PM

You won't need the webserver mvc stuff to use php frameworks.

I haven't worked with CodeIgniter, but it seems you might have to add more allowed characters. Try adding a directory seperator 'a-z 0-9~%.:_\-\\' or disable the filtering completly to see if it works.

EDIT: Just watched the video tutorial. I think the webserver won't understand CodeIgniters way of handling URIs. Having an uri like '' the server will always look for a directory and won't load the index.php with appropriate path info. But it should be easy enough to write a router for this. Though I'm not sure if that solves the problem, it would be a start ...

EDIT 2: I think the cgi module should take care of that. Will work on it next week.

Jul 8, 2012 at 11:58 PM

ok so that little addition for dir seperator cured that issue, but still having 404.


for CI the url's are structured like: (when mod_rewrite is not used in a .htaccess or iis equiv) or (with mod_rewrite or iis equiv)

so using : or: produces the CI 404 error page but using: (which should show the CI default welcome page through the controller: welcome) produces the HttpServer.HttpException 404 error. what it is doing i believe is looking for a default document under directory path: index.php/home
and not actually passing the routing control to CI like it should.

Jul 9, 2012 at 6:55 AM

New version online:

Jul 9, 2012 at 5:01 PM

:P that is superb. Works a treat now. Awesome work. :)