Delphi - Linux load apache module

Delphi Tokyo 10.2 has an awesome feature: Linux support! From now we are able to deploy our applications into a linux server. A very nice set-up guide for the linux environment can he found here; instead if you want to be able to use firemonkey and target a linux dekstop client (Ubuntu 16.04 LTS for example) check the FmxLinux project.

With Delphi 10.2 we can create a REST Server (or simply a WebServer based on Indy) and export it as stand-alone console app or as apache module. For example, let's create a basic webserver:

  1. Go on File > New > Other > WebBroker > WebBroker Application. Select Linux and then Apache module. In the last page we are asked to input the module name, which is very important.

  2. We want to keep things very easy, so I won't focus on the WebModule (with Actions) and other things, you can find a lot of information on the doc. First of all start your linux server (hosted on Ubunutu, Virtualbox or whatever) and run the PAServer. Select Linux as target platform, give a build and then Deploy the project to the server.

  3. Now move on linux (I assume that you already have Apache installed). Using cd go to the PAServer folder and reach the library; in my case I am going to /home/albertodev/PAServer/scratch-dir/{yourname}/projname/ . Of course replace {yourname} with what you have on your machine :)

  4. Now use cd /etc/apache2/mods-available and create 2 new files that will load our module into apache. The command touch creates new files on Linux so type touch myfirstmodule.load and touch myfirstmodule.conf. Now if you type ls you will see that those 2 file have been added in the folder!

  5. Now type sudo nano myfirstmodule.load and you'll open a text editor. I really like this but you can use whatever you want. Now let's type this:

    LoadModule moduleName /home/albertodev/PAServer/scratch-dir/albertodev-linux_server/projname/

    Instead moduleName you have to type the name of your module. How to do it? Simple!

    Double click the .so file in the project manager, right click, click on "View source" and copy the string value next to GModuleData name 'webbroker_module';. In my case the full path is:

    LoadModule webbroker_module /home/albertodev/PAServer/scratch-dir/albdev-linux_server/projname/

    Save all and close

  6. Now type sudo nano myfirstmodule.conf
  7. and save the file with the following content:

    <Location /delphi/great/test/>
    SetHandler myDelphiApacheLib-handler

    The /delphi/great/test/ means that we will be able to reach our project at Then after the SetHandler type the library name and append the -handler. Save all and close.

  8. We have almost finished! You just have to type on linux sudo a2enmod myfirstmodule (same name as myfirstmodule.conf), then sudo apache2ctl stop and finally sudo apache2ctl stop. My linux server is running on so when I type I can see this:

    Really awesome!


Popular posts from this blog

Delphi - Android full screen splash

Delphi - TLanguage localizaton tool

Delphi - monetize Android/iOS applications step-by-step