This project is read-only.

PHP support

Dec 2, 2010 at 7:23 PM

Has anyone managed to add PHP support to this webserver?  I am trying to embed a webserver into my project and this project looks like one of the most complete embeddable webservers out there, but I would just need to add PHP support.


Dec 5, 2010 at 12:07 PM
Edited Dec 5, 2010 at 12:09 PM

I wrote a module for that a while ago. It's supposed to replace the FileModule class. So, instead of adding FileModule to the server modules, add my AdvancedFileModule class. Then add your php cgi by calling AddCgiApplication("php", @"C:\Path\To\PHP\php-cgi.exe") and it should work.

The above link will expire in 10 days (on 12/15/2010).

By the way: does anyone know a working C# code for FastCGI?

Dec 5, 2010 at 1:29 PM
I thought I added FastCGI support a long time ago. I'll check my drive if it isnt checked in.

Dec 6, 2010 at 5:55 AM

wo80 -

Thanks so much for your response.  I could use a little help add your code to the source.  I grabbed the source for the web server from the trunk of the SVN.  I created a new class file in the Modules folder of the HttpServer project and copied the code you posted into it.  The problem I have is in these lines in your class:

using HttpServer.Exceptions;
using HttpServer.Sessions;

Those namespaces are unknown.  Is there something I need to add to the project that I am missing?


Dec 6, 2010 at 10:00 AM

@bwoodworth: I wrote the module for version 1.1 of the server. You probably checked out version 2.0.


@jgauffin: There's a scgi module. I haven't tried it because I don't think php supports scgi. If there's a fcgi module, it would be great if you share it.

Dec 6, 2010 at 4:01 PM


Thanks.  I am now able to compile the Sample program after removing the original FileModule and replacing it with this:

AdvancedFileModule afm = new AdvancedFileModule("/", Environment.CurrentDirectory);
afm.AddCgiApplication("php", @"C:\Path\To\php-cgi.exe");

Problem I have now is when I run the server and browse to localhost:8081/index.php (i created that with just phpinfo() in it), i get the following error saying php is a forbidden file type:

HttpServer.Exceptions.ForbiddenException: Forbidden: Forbidden file type: php
at HttpServer.HttpModules.AdvancedFileModule.Process(IHttpRequest request, IHttpResponse response, IHttpSession session) in C:\Users\Brian\Development\WebServer\HttpServer\HttpModules\AdvancedFileModule.cs:line 386
at HttpServer.HttpServer.HandleRequest(IHttpClientContext context, IHttpRequest request, IHttpResponse response, IHttpSession session) in C:\Users\Brian\Development\WebServer\HttpServer\HttpServer.cs:line 406
Do I need to specify somewhere to allow php file type and if so, where?

Dec 6, 2010 at 4:10 PM


I made a little progress by adding the following:

afm.ServeUnknownTypes(true, "php");

I no longer get any exceptions, but instead it just shows the contents of index.php instead of processing it and displaying the resulting html.

Any ideas?

Dec 6, 2010 at 4:12 PM

Well, you have to use the right path to your php cgi executable. I guess it's not C:\Path\To\php-cgi.exe ...

Dec 6, 2010 at 4:29 PM


Yeah, looks like I had the path to the cgi wrong.  I am now getting the proper output for phpinfo().  Thanks so much for your help.  It is working splendidly.

Jan 10, 2011 at 3:16 PM



I have been able to get php working, but the main thing I want to use PHP with is to connect to a mysql DB.  I am having trouble getting getting mysql to work.  I am trying to open a connection to my mysql serer and get the following error:

Fatal error: Call to undefined function mysql_connect()

I think there is a problem loading a mysql library, but I can't figure out how to fix it.  Are you able to get mysql loaded?  Is there a special place I need to put the ini, dlls, etc?

Jan 18, 2011 at 12:23 AM

I was able to get mysql fully working.  took a lot of trial and error with where all the proper dlls needed to be along with the ini, but it is working.

I now am noticing that navigating to any page that in not in the root directory (i.e. a subdirectory -  'root/sub/index.php') defined in AdvancedFileModule produces some interesting results.  If the file name is completely unique and there isn't a file in the root with the same name it just not find it.  If the file has the same name as a file in the root directory, it will load the one in the root and not the one in the subdirectory.  very strange.  I can include files in subdirectories in a page in the root, but browsing directly to it produces this weird behavior.  My guess is there is something wrong with the AdvancedFileModule you wrote?  Any help would be greatly appreciated.

Jan 18, 2011 at 10:25 AM

Sorry, I can't reproduce that behaviour. All files are served just fine on my machine. Anyway, if you want to see what's going wrong there, just start the debugger and step through the Process(...) method of the http module.

Jan 18, 2011 at 5:11 PM

It looks like it is working in the sample program, but not when I start the server from my own code.  I noticed the sample program has some stuff about a TemplateManager and ControllerModule.  Are these necessary?  I am simply doing this from my code:


HttpServer.HttpServer server = new HttpServer.HttpServer();
AdvancedFileModule afm = new AdvancedFileModule("/", @"C:\wwwroot");

afm.ServeUnknownTypes(true, "php");
afm.AddCgiApplication("php", @"C:\php\php-cgi.exe");
server.Start(IPAddress.Any, port);
Could leaving out the TemplateManager or ControllerModule have anything to do with this problem?

Jan 18, 2011 at 8:01 PM
Edited Jan 18, 2011 at 8:02 PM

No, I'm not using the template and controller stuff either. The above code works fine for me.

By the way: I recognized that I haven't documented the ServeUnknownTypes method correctly. It's really just for serving types, that are not in the servers mimetype list (otherwise you would get a ForbiddenException). The second argument is the mimetype, the unknown files should be served as (application/octet-stream would make sense). But this won't make a differnce for your current problem...

Jan 20, 2011 at 10:44 AM

wo80: could you post a fresh link to your AdvancedFileModule please?

Jan 21, 2011 at 5:26 PM

@jonnie: here you go

May 26, 2013 at 7:50 AM
WO80: Can you please refresh the link..?
May 26, 2013 at 1:43 PM
You can find the latest version at