Show/Hide Toolbars

TMS Sparkle Documentation

Navigation: Http Server

Apache-based Server

Scroll Prev Top Next More

Apache web server is another platform you can use to run your HTTP server, in addition to Http.Sys-based Server. If the Http.sys-based server is the recommended way to build Sparkle HTTP server on Microsoft Windows, Apache is the way to go if you want to run it on Linux (although you can also use it on Windows as well).


Apache support on Sparkle is based on built-in Web Broker technology available in Delphi. You create an Apache module using Web Broker and then deploy the module to an Apache web server using standard procedures. Here are the steps:


1. Create an Apache module using Web Broker


Basically, go to File > New > Other, then Delphi Projects > WebBroker > Web Server Application and then choose "Apache dynamic link module". This will create the default Apache module library.


2. In WebModuleUnit1 unit, add the units Sparkle.WebBroker.Server and Sparkle.WebBroker.Adapter to the uses clause:


uses {...},
  Sparkle.HttpServer.Module; // just for the anonymous module example


3. Declare a global TWebBrokerServer instance:


  Server: TWebBrokerServer;


4. Create the instance in the initialization of the unit, and add your desired Sparkle modules (XData, RemoteDB, etc.) to its Dispatcher:


  Server := TWebBrokerServer.Create;
  // add modules you want to use. This example assumes a simple Sparkle module,
  // but you can add your XData, RemoteDB or any other Sparkle module
    procedure(const C: THttpServerContext)
      C.Response.StatusCode := 200;
      C.Response.ContentType := 'text/html';
      C.Response.Close(TEncoding.UTF8.GetBytes('<h1>Hello, World!</h1>'));


5. Replace the WebModule1DefaultHandlerAction event handler with the code below to dispatch the requests:


procedure TWebModule1.WebModule1DefaultHandlerAction(Sender: TObject;
  Request: TWebRequest; Response: TWebResponse; var Handled: Boolean);
  Adapter: IWebBrokerAdapter;
  Adapter := TWebBrokerAdapter.Create(Request, Response);


That's it, your Apache module is done. You can now just build it and deploy to your Apache server. This is just WebBroker and Apache knowledege, here are some links to videos and/or articles about how to do it:


Building and Deploying a Linux Apache Module with Delphi WebBroker (Youtube video)

Delphi for Linux Database and Web Development (Blog post)