I created an hello world module on ubuntu 16.04
#include <httpd.h>
#include <http_protocol.h>
#include <http_config.h>
static int helloworld_handler(request_rec* r)
{
if (!r->handler || strcmp(r->handler, "helloworld"))
return DECLINED;
if (r->method_number != M_GET)
return HTTP_METHOD_NOT_ALLOWED;
ap_set_content_type(r, "text/html");
ap_rprintf(r, "Hello, world!");
return OK;
}
static void register_hooks(apr_pool_t* pool)
{
ap_hook_handler(helloworld_handler, NULL, NULL, APR_HOOK_MIDDLE);
}
module AP_MODULE_DECLARE_DATA helloworld_module = {
STANDARD20_MODULE_STUFF,
NULL,
NULL,
NULL,
NULL,
NULL,
register_hooks
};
compiling it with this command:
apxs -iac mod_helloworld.c
I can see the module launching it
apache2ctl -M
and
a2enmod
if I run
sudo a2enmod helloworld
I can see that this module is already enabled
I also inserted this helloworld.conf in the folder mods-available
<Location /helloworld>
SetHandler helloworld_handler
</Location>
and the file helloworld.load contains
LoadModule helloworld_module /usr/lib/apache2/modules/mod_helloworld.so
How should I configure it to see the output calling in the browser for instance
http://localhost/helloworld
mod_helloworld.so is under /usr/lib/apache2/modules
if I root@ubuntu:/var/log/apache2# tail -f access.log
I am getting this
127.0.0.1 - - [03/Aug/2017:03:18:14 -0700] "GET /helloworld HTTP/1.1" 404 500 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:54.0) Gecko/20100101 Firefox/54.0"
How to solve it?
You're checking "helloworld" in the C code, but setting "helloworld_handler" w/ SetHandler. You'd need to change to "SetHandler helloworld" to get your module to not DECLINE.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With