My First HelloWorld Module for Apache~
#include <httpd.h>
#include <http_protocol.h>
#include <http_config.h>
static int helloworld_handler( request_rec *r )
{
//Routine check
if( !r->handler || ( strcmp( r->handler, "helloworld" ) != 0 ) ) {
return DECLINED;
}
//Check the "HTTP GET" method
if( r->method_number != M_GET ) {
return HTTP_METHOD_NOT_ALLOWED;
}
ap_set_content_type( r, "text/html;charset=ascii" );
ap_rputs( "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\">\n", r );
ap_rputs( "<html><head><title>Apache Helloworld "
"Module</title></head>", r );
ap_rputs( "<body><h1>Hello World!</h1>", r );
ap_rputs( "<p>This is the Apache HelloWorld module!</p>", r );
ap_rputs( "</body></html>", r );
return OK;
}
static void helloworld_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,
helloworld_hooks
};
保存为mod_helloworld.c后上传到装有Apache的Linux服务器上。
按书中编译方法编译,发现不行:
[logs@dw208066 opt]$ apxs -c mod_helloworld.c
-bash: apxs: command not found
[logs@dw208066 opt]$ find -name apxs
想想就是apxs所在目录并没有列入到系统path中的原因,于是就改用绝对路径:
[logs@dw208066 opt]$ ./local/apache/bin/apxs -c mod_helloworld.c
/usr/lib64/apr-1/build/libtool --silent --mode=compile gcc -prefer-pic -DLINUX=2 -D_REENTRANT -D_GNU_SOURCE -pthread -I/opt/local/apache/include -I/usr/include/apr-1 -I/usr/include/apr-1 -c -o mod_helloworld.lo mod_helloworld.c && touch mod_helloworld.slo
mod_helloworld.c: In function 'helloworld_hooks':
mod_helloworld.c:29: error: 'APR_hook_MIDDLE' undeclared (first use in this function)
mod_helloworld.c:29: error: (Each undeclared identifier is reported only once
mod_helloworld.c:29: error: for each function it appears in.)
apxs:Error: Command failed with rc=65536
出现编译错误,提示APR_hook_MIDDLE未定义(我博文里的代码已经改过来了,不存在这个错误),然后去Google了一番,发现只能Google到APR_HOOK_MIDDLE,看样子是书里的排版错误,hook没有大写
遂用vi改了下代码(改后就是我上面贴的那份),然后同样的方法编译:
[logs@dw208066 opt]$ ./local/apache/bin/apxs -c mod_helloworld.c
/usr/lib64/apr-1/build/libtool --silent --mode=compile gcc -prefer-pic -DLINUX=2 -D_REENTRANT -D_GNU_SOURCE -pthread -I/opt/local/apache/include -I/usr/include/apr-1 -I/usr/include/apr-1 -c -o mod_helloworld.lo mod_helloworld.c && touch mod_helloworld.slo
/usr/lib64/apr-1/build/libtool --silent --mode=link gcc -o mod_helloworld.la -rpath /opt/local/apache/modules -module -avoid-version mod_helloworld.lo
ls后发现目录下的确多了几个文件,其中就有一个mod_helloworld.la的,于是再调用
[logs@dw208066 opt]$ ./local/apache/bin/apxs -i mod_helloworld.la
apache的Module目录下就多了一个mod_helloworld.so
再在httpd.conf中加入这一Module:
LoadModule helloworld_module modules/mod_helloworld.so
<Location /helloworld>
SetHandler helloworld
</Location>
再调用./apachectl restart
在客户机上敲入 http://192.168.208.66:8080/helloworld
//我在服务器上用的8080端口
显示:
Hello World!
This is the Apache HelloWorld module!
成!
转载于:https://www.cnblogs.com/DeadKnight/archive/2010/04/08/1707444.html
My First HelloWorld Module for Apache~相关推荐
- Apache模块开发helloworld无错版
环境:CentOS 5.4 第一步:安装Apache的apxs 首先来介绍下apache的一个工具apxs.apxs是一个为Apache HTTP服务器编译和安装扩展模块的工具,用于编译一个或多个源程 ...
- Create new module “HelloWorld” – in Magento
Do you want to create a new page in Magento ? or Do you want to create a new module in Magento ? If ...
- Apache模块开发
一.简介 Apache HTTP服务器是一个模块化的软件,使管理者可以选择核心中包含的模块以裁剪功能.可以在编译时选择被静态包含进httpd二进制映象的模块,也可以编译成独立于主httpd二进制映象的 ...
- C语言-apache mod(模块开发)-采用apxs开发实战(centos7.2 linux篇)
C语言-apache mod(模块开发)-采用apxs开发实战(centos7.2 linux篇) 名词解释:apxs apxs is a tool for building and installi ...
- Enable htaccess file work in Apache
1, Load LoadModule module in Apache 1) Find the "httpd.conf" file under the "conf&quo ...
- Apache 超详细编译参数解析
配置帮助表: -h, --help 显示帮助信息 display this help and exit --help=short 用short参数将只显示正在运行的当前脚本的选项,而不能列出适用于Ap ...
- 学习《apache源代码全景分析》之摘录
一.大纲 1.Web服务器概述 2.Apache体系结构 3.配置文件管理 4.Apache模块化体系结构 5.多任务并发处理 6.网络连接 7.过滤器 8.存储段和存储段组 9.常用过滤器 二.摘录 ...
- apache camel_在WildFly中将Apache Camel和Spring添加为jboss模块
apache camel 这些天,我在玩Wildfly , Apache Camel和Spring . 在EAR / WAR之间进行通信的一种简单方法是使用Camel的direct-vm组件. 有或没 ...
- 在WildFly中将Apache Camel和Spring添加为jboss模块
这些天,我在玩Wildfly , Apache Camel和Spring . 在EAR / WAR之间进行通信的一种简单方法是使用Camel的direct-vm组件. 有或没有骆驼,有很多方法可以实现 ...
- Storm入门(三)HelloWorld示例
一.配置开发环境 storm有两种操作模式: 本地模式和远程模式.使用本地模式的时候,你可以在你的本地机器上开发测试你的topology, 一切都在你的本地机器上模拟出来; 用远程模式的时候你提交的t ...
最新文章
- 平流式隔油池计算_广州隔油池清理公司讲述清理隔油池程序和标准_新闻中心...
- SQLAlchemy的使用---外键ForeignKey数据库创建与连接
- GridView绑定时间
- 065_const关键字
- 柳青:2017,滴滴实现规模增长和修炼内功的一年
- MongoDB最简单的入门教程之二 使用nodejs访问MongoDB
- oracle tns 代理配置_oracle数据库tns配置方法详解
- java如何写安卓接口文档_android、java制作sdk以及自动生成文档
- vim 插件cscope 使用
- duilib消息机制的介绍
- 【python零基础入门学习】Python入门,带你快速学习为什么那么多人想学 Python?
- 事业单位非编制值得去吗?
- php fmod小数位数_PHP取余函数介绍MOD(x,y)与x%y
- 余光中 听那冷冷的雨
- 我将进化成一条狗(10)——长寿秘诀
- android前台服务也被杀,android如何让后台服务service不被杀死(设置前台服务)
- php天籁吉他乐器介绍网站系统
- python泊松_python – 泊松过程的测试
- elementui表格隔行换色
- 计算机技术与软件专业技术和计算机二级,软考是什么,跟计算机二级的差别是什么? - 收获啦...
热门文章
- 计算机崩溃用英语怎么说,“我要崩溃了”英语怎么说?
- C/C++[codeup 1925]特殊排序
- 持续集成CI, 持续部署CD, 持续交付CD要点
- linux环境安装ffmepg,Linux centOS下安装FFmpeg
- Container With Most Water(C++)
- access怎么做批注_添加、编辑和删除记录的方法
- Servlet和JSP
- Python验证码识别处理实例
- AdaBoost中利用Haar特征进行人脸识别算法分析与总结2——级联分类器与检测过程
- 2d shader unity 阴影_Shader从入门到跑路(11):多Pass渲染