| WeOnlyDo! COM Web Server ActiveX - Setting up PHP to run as CGI module |
| ® WeOnlyDo! COM (2002-2004) |
|
General information This tutorial will show step by step how to setup PHP to work with wodWebServer, running as external CGI module. It assumes you have installed wodWebServer to your local folder, and tested it so it works with provided samples. Step 1 - installing PHP You should download PHP installation from http://www.php.net, and install it
into C:\PHP folder. PHP.EXE should exist in that
folder. Step 2 - using PHP from VB (similar approach is needed for any other language) Fire up new VB project, and add wodWebServer to it. Start it so it listens and accepts incoming connections. Typically, code will look like this
Now server will accept connections, but we need to catch them and redirect to PHP processor. The most convenient place to so that is RequestDone event, so you can do this:
Above code is self-explanatory. It calls PHP.EXE file with one argument that contains path of the document user tried to access (actually, only it's name). Although some CGI modules will not require argument to be presented through command line, using PHP this way will allow wodWebServer to parse CGIExecute command line, and use argument for PATH_TRANSLATED environment variable, so you don't need to set it up later on in CGIStart event. If you run above code, it will immediately work - except PHP will return an error 'Input file not found.' This is normal - it's part of security protection PHP has so it cannot be misused and cause potential security breach. But, since in your code YOU define file that will be retrieved (and not the client), we don't have to worry about this security, so we can safely add one more line to RequestDone event:
Setting StatusCode property to '200 OK' is needed because PHP itself does not return it - so we have to help a bit. We assume you add a bit more code to RequestDone event that will actually check if requested file exists, if it is a PHP script etc.. IIS, Apache and other webservers would do this automatically - since wodWebServer is a component, you need to add that code so it suits your needs. Step 3 - prepare environment Look at CGIStart event - it is called just before PHP script is to be executed. At this point, among other things, environment variables are set that will PHP see when running. Most important are PATH_INFO and PATH_TRANSLATED variables. If you used above code in RequestDone, wodWebServer will fill up these values for you - feel free to check that by doing this:
You can change Environment variables the way you want. Some CGI modules will require additional variables to be set, such as CERT_SUBJECT, CERT_ISSUER, HTTPS.... which you can add manually in CGIStart event. But, for PHP, it is important to add this:
Why is REDIRECT_STATUS environment important? As explained above, it is part of PHP security measures. It means that it is OK to execute the script, and that webserver has taken care of security measures for the script. If you don't use it, you would need to open PHP.INI file and change cgi.force_redirect = 1 value to 0. We used safer approach with REDIRECT_STATUS environment. Conslusion That should be it! If you point your browser to local instance of wodWebServer, you will see PHP running there. There is one thing to do - from within CGIStart event you should add environment variables for temporary folders. If you plan to use sessions integrated into PHP, this will be important, so add these two lines too:
|