Today I'm giving a Developer Skill Sprint on Apache support in RAD Studio XE6 (I already gave the first session live, the recording will be replayed), and I'd like to complement the session with this blog post, showing some of the code and providing the same hints and suggestions.

First of all, the Apache support is part of WebBroker foundations, and so it can be used for direct WebBroker applications, DataSnap applications based on WebBroker, SAOP servers, and many other scenarios. In a simple WebBroker application, you now have the following options:

If you pick Apache, you'll see a second rather useless page asking for VCL or FMX compatibility (for the generated data module), while the third page has the Apache specific options:

Here you can set the version of Apache (this results in a specific unit being referenced, displayed in the third box, which you can easily change later) and the module name (which is also the project name). As you finish, you'll get a project made of a standard WebBroker data module plus a specific library project file.

Remember that depending if you have a 32 bit or 64 bit version of Apache, you'll have to compile the module as a Win32 or Win64 Delphi (or C++Builder) project.

This generated file includes, as comments, the Apache configuration. So if you go with all default, you'll have the following configuration suggestion:

 LoadModule webbroker_module modules/mod_webbroker.dll
 <Location /xyz>
    SetHandler mod_webbroker-handler

In the LoadModule directive the first element is the internal module name, which is the name of the exported configuration data:

  GModuleData: TApacheModuleData;
  GModuleData name 'webbroker_module';

You can easily change that string and update the configuration accordingly. The second parameter of LoadLibrary is the DLL name.

The Location directive, instead, indicate the virtual URL the module is mapped to (/xyz in the demo) and the "handler" that is going to be processed. The module, in fact, registers a handler with Apache, and everything meant for that handler will be passed to the module. The default handler name is generated automatically form the project name, like  mod_webbroker-handler . If you want to use a custom handler name, you'll have to take the second line of the project initialization code,


and change it by adding a second parameter to InitApplication, which is exactly the handler name. So you could change this to:

  Web.ApacheApp.InitApplication(@GModuleData, 'myhandler');

and update the configuration accordingly as:

 <Location /myurl>
    SetHandler myhandler
That's it. In the actual skill sprint I also discussed how to configure Apache as a proxy server to connect to a stand alone HTTP server executable. This is the relevant code snippet for reference:
  ProxyPass /another http://localhost:9099
  ProxyPassReverse /another http://localhost:9099
  ProxyPreserveHost On 
There are two more editions of the skill sprint today, and the replay will soon be available as well. I'll add a comment to this blog post when I'll have the replay URL.