Deploying a WebBroker Apache Module on CentOS 7
This article assumes you can add CentOS 7 as target platform in a Delphi project. If you want to know how to do this, please check this post.
Contents
Introduction
All the videos and tutorials I could find demonstrate how to deploy a webbroker module on Ubuntu or RedHat Linux distributions. This is understandable as these two flavors of Linux are officially supported by Embarcadero.
At the same time, this is unfortunate for me as it posed a problem because I have a VPS running CentOS and I really wanted to take advantage of the ability to build projects for Linux.
To be honest, it took me a while to figure out how to make Apache in CentOS recognise a Delphi webbroker module. It looks like names play a very important role here (as they do in the Linux world in general).
Let’s get started.
The WebBroker Project
For this article, I do not do anything fancy in Delphi; I just created a simple webbroker project using the wizard from the IDE. I did not change the name of the module and I added CentOS as the selected target platform. Then, I built the project and Delphi generated a Linux dynamic library named libmod_webbroker.so
For the Apache configuration, we need to pay attention to two names we use in the project. The name of the binary file (1) and the exported name (2) by the binary.
Figure 1: Naming of webbroker apache module
Uploading the Module File
The location for the modules files is /etc/apache2/modules
(which maps to /usr/lib64/apache2/modules
). Therefore, you can upload the libmod_webbroker.so
file to that location but, strictly speaking, this is not necessary. You can store your files in any location you prefer (as long as the user that executes apache has rights to access the file).
Loading the Module File
Then, we need to let Apache know that our module exists and has to be loaded. In CentOS, we do this by creating a configuration file in /etc/apache2/conf.modules.d
Create a new text file named webbroker_mod.conf
and add the following line in it:
LoadModule webbroker_module modules/libmod_webbroker.so
If you place the module file in a different directory than the default one, you need to provide the full path instead of just modules/
Note the use of the names from Figure 1 in the script.
Restart Apache in order to load the module:
systemctl restart httpd.service
You can confirm that the module is loaded by getting a list of all the modules using the following command and verifying that webbroker_module
appears in the list:
apachectl -M | sort
Linking the Module to a URI Resource
When we setup a webbroker module we, basically, set up a web server. This web server needs to respond to an address (or to a resource to use the jargon of web programming). In our example, we’ll make the server reply to /api
url resource.
The difference between Ubuntu and CentOS file structure is that in Ubuntu you store the load
and conf
files in the same location. In CentOS, the conf
file to setup a URL location is stored in /etc/apache2/conf.d/userdata/std/<version tag>/<user name>/example.com
In the above path the std
tag indicates that this configuration file is for accessing the server using http
protocol. If you want to configure the server for https
access, you should add a conf
file in /etc/apache2/conf.d/userdata/ssl/<version tag>/<user name>/example.com
The configuration file links the URL location to our apache module. Name the file example_std.conf
and add the following lines:
<IfModule webbroker_module> <Location /api> SetHandler libmod_webbroker-Handler </Location> </IfModule>
This took me lots of time to realise: the name in SetHandler
has to be the same as the name of the binary filename; and you need the dash and the Handler
keyword (-Handler
); but, ironically, you can have the word Handler
with either small or capital H (that’s Linux world—go figure…). On the contrary, you don’t need the <IfModule></IfModule>
block but it is good practice to check if the module is loaded first.
Restart Apache as before and visit www.example.com/api
in your browser. Hopefully, our webbroker
server responds.
This information is very usefull.
Thank for published.
What version of Apache are you using for this? I’m assuming it is one of the 2.4 versions, right?
Hi,
I think it was 2.4. I don’t have access to that server anymore so can’t confirm.