Adding Custom Apache Modules
To fulfill the specific needs of your application, you may find it necessary to add custom Apache modules. Some of these modules may not be included in the default list of Apache modules installed on the platform. You can enable your own Apache modules within your environment by following these instructions:
Let’s walk through setting up your environment:
Step 1. Sign in to your AccuWeb.Cloud PaaS account.
Step 2. Look for the “Create environment” option in the top left corner of the dashboard and click on it.
Step 3. In the wizard that appears, go to the PHP tab. Choose the Apache application server and specify the resources your application needs. Don’t forget to give your environment a name, like “apache modules,” then hit the “Create” button.
Step 4. Your environment will appear on the platform dashboard within a few minutes.
To build your Apache module, follow these steps:
Step 1. Download Apache httpd from apxs, ensuring it matches the version of your existing Apache server. For example, if you have Apache 2.4.59, download and install httpd 2.4.59.
Step 2. Obtain the source code for the required module from the Apache modules list. As an example, let’s use the mod_pony Apache module.
Step 3. Compile your Apache module.
Below is an example of how to compile the mod_pony module:
apxs -i -a -c mod_pony.c
/usr/lib64/apr-1/build/libtool --silent --mode=compile gcc -prefer-pic -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -Wformat-security -fno-strict-aliasing -DLINUX=2 -D_REENTRANT -D_GNU_SOURCE -pthread -I/usr/include/httpd -I/usr/include/apr-1 -I/usr/include/apr-1 -c -o mod_pony.lo mod_pony.c && touch mod_pony.slo
/usr/lib64/apr-1/build/libtool --silent --mode=link gcc -o mod_pony.la -rpath /usr/lib64/httpd/modules -module -avoid-version mod_pony.lo
/usr/lib64/httpd/build/instdso.sh SH_LIBTOOL='/usr/lib64/apr-1/build/libtool' mod_pony.la /usr/lib64/httpd/modules
/usr/lib64/apr-1/build/libtool --mode=install cp mod_pony.la /usr/lib64/httpd/modules/
libtool: install: cp .libs/mod_pony.so /usr/lib64/httpd/modules/mod_pony.so
libtool: install: cp .libs/mod_pony.lai /usr/lib64/httpd/modules/mod_pony.la
libtool: install: cp .libs/mod_pony.a /usr/lib64/httpd/modules/mod_pony.a
libtool: install: chmod 644 /usr/lib64/httpd/modules/mod_pony.a
libtool: install: ranlib /usr/lib64/httpd/modules/mod_pony.a
libtool: finish: PATH="/usr/local/sbin:/bin:/sbin:/usr/bin:/usr/sbin:/sbin" ldconfig -n /usr/lib64/httpd/modules
----------------------------------------------------------------------
Libraries have been installed in:
/usr/lib64/httpd/modules
If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
Specify the full pathname of the library, or use the -LLIBDIR flag during linking, and do at least one of the following:
- add LIBDIR to the `LD_LIBRARY_PATH' environment variable
during execution
- Add LIBDIR to the `LD_RUN_PATH` environment variable to include the directory in the library search path during runtime.
- use the `-Wl,-rpath -Wl,LIBDIR' linker flag
- have your system administrator add LIBDIR to `/etc/ld.so.conf'
Refer to your operating system's documentation for more details on shared libraries, including the ld(1) and ld.so(8) manual pages.
----------------------------------------------------------------------
chmod 755 /usr/lib64/httpd/modules/mod_pony.so
[activating module `pony' in /etc/httpd/conf/httpd.conf]
Step 4. After compiling, you will get a .so file of your Apache module. For instance, you will have a
Upload and Configure Your Module
Step 1. Navigate to your environment and click on the Config button for your Apache server.
Step 2. Upload the mod_pony.so file to the /usr/lib64/php/modules folder.
Step 3. Navigate to the /etc/httpd/conf folder and edit the httpd.conf file. Add the LoadModule directive in the following format:
LoadModule {module-name}_module /usr/lib64/php/modules/{file-name}.so
Example
LoadModule pony_module /usr/lib64/php/modules/mod_pony.so
Save the changes.
Step 4. Adjust the settings required for your Apache module.
For example, to further configure the mod_pony module:
- Navigate to the webroot > ROOT folder and create a .htaccess file.
- Include the following lines in the .htaccess file:
<Files pony>
SetHandler pony
</Files>
Save the changes.
Step 5. Restart the Apache server node to enable the module after applying all configuration changes.
Check the result
After setting up and configuring the mod_pony Apache module, click “Open in browser” for your environment to ensure the server is running properly.
Append “/pony” to the URL and refresh the page. If the module is functioning correctly, you should see your pony or the desired outcome based on the module’s functionality.
With these simple steps, you can easily confirm the functionality of your custom Apache module and start benefiting from its features.