转自:https://blog.youkuaiyun.com/hxsstar/article/details/19820029
1,windows下安装apache
地址:http://apache.dataguru.cn//httpd/binaries/win32/
一定要custom全部安装,否则就不会有include和lib目录
2,安装Perl
我们将要使用的apx包要用到perl解析编译,所以,需先安装perl。
安装perl过程略(下载地址:http://www.activestate.com/activeperl/),只需下载安装即可。
3,安装apxs
(1)地址:http://www.apachelounge.com/download/apxs_win32.zip
下载后,解压到C:\apxs。
(2)打开命令提示符,定位到C:\apxs,执行命令
perl Configure.pl --with-apache2=\Path\to\Apache2 --with-apache-prog=httpd.exe
其中\Path\to\Apache2需要替换为Apache的实际安装路径,示例输出如下:
- c:\apxs>perl Configure.pl --with-apache2=D:\xampp\apache --with-apache-prog=httpd.exe
- apxs.bat has been created under D:\xampp\apache\bin.
- apr-1-config.pl.bat has been created under D:\xampp\apache\bin.
- apu-1-config.pl.bat has been created under D:\xampp\apache\bin.
(3)切换到Apache安装目录下的bin文件夹,执行:
apxs
如有帮助信息出现则表明安装完成。
(4)将apxs所在的目录设置加入系统环境变量PATH。
apxs编译时还需用到C/C++编译器,一般有两种选择,一种是使用VC(Visual Studio)自带的编译器,还有一种就是自行安装,比如minGW等。
对使用VS编译的,可尝试修改apache下的build目录中config_vars.mk配置文件:
- CC = gcc 的gcc改为cl.exe
- LD = g++的g++改为link.exe
- CPP = gcc-E的gcc-E删掉
(1)运行Visual Studio 2008 命令提示(在开始的Microsoft Visual Studio 2008下可以找到)
(2)运行apxs -g -n helloworld(helloworld为模块名),会生成一个叫helloworld的目录和模板代码(一般放在user目录下)
(3)进入helloworld目录,编辑mod_helloworld.c(这就是我们要开发的内容)
(4)运行apxs -c -i -a mod_helloworld.c libapr-1.lib libaprutil-1.lib libapriconv-1.lib libhttpd.lib,生成mod_helloworld.so
(5)将mod_helloworld.so拷贝到Apache2.2\modules下
(6)修改Apache2.2\conf\httpd.conf,在末尾加上
- LoadModule helloworld_module modules/mod_helloworld.so
- <Location /helloworld>
- setHandler helloworld
- </Location>