Linux, FreeBSD, Juniper, Cisco / Network security articles and troubleshooting guides

FAQ
It is currently Fri Dec 09, 2016 6:45 pm


This forum is dedicated to Apache, Nginx, Lighttpd, Squid and other HTTP transport protocol related software

Author Message
debuser
  Post  Post subject: Apache 2.2 installation of mod_rewrite module without recompiling whole apache  |  Posted: Tue Mar 23, 2010 11:22 am

Joined: Thu Aug 06, 2009 2:48 am
Posts: 105

Offline
 

Apache 2.2 installation of mod_rewrite module without recompiling whole apache

Usually I keep my sources available at all times because apache or php could require a new module to be installed (sooner or later). I will post here how to install apache mod_rewrite module without recompiling whole apache from source.

Below is the source of the mod_rewrite apache module on my system.
Code:
# cd /usr/src/httpd-2.2/modules/mappers
#  ls *c | grep rewrite
mod_rewrite.c


I will be using the apache extension tool (apxs):
man apxs:
Quote:
APXS(8) apxs APXS(8)

NAME
apxs - APache eXtenSion tool

SYNOPSIS
apxs -g [ -S name=value ] -n modname

apxs -q [ -S name=value ] query ...

apxs -c [ -S name=value ] [ -o dsofile ] [ -I incdir ] [ -D name=value ] [ -L libdir ] [ -l libname ] [ -Wc,compiler-
flags ] [ -Wl,linker-flags ] files ...

apxs -i [ -S name=value ] [ -n modname ] [ -a ] [ -A ] dso-file ...

apxs -e [ -S name=value ] [ -n modname ] [ -a ] [ -A ] dso-file ...

SUMMARY
apxs is a tool for building and installing extension modules for the Apache HyperText Transfer Protocol (HTTP) server.
This is achieved by building a dynamic shared object (DSO) from one or more source or object files which then can be
loaded into the Apache server under runtime via the LoadModule directive from mod_so.

So to use this extension mechanism your platform has to support the DSO feature and your Apache httpd binary has to be
built with the mod_so module. The apxs tool automatically complains if this is not the case. You can check this yourself
by manually running the command

$ httpd -l

The module mod_so should be part of the displayed list. If these requirements are fulfilled you can easily extend your
Apache server's functionality by installing your own modules with the DSO mechanism by the help of this apxs tool:

$ apxs -i -a -c mod_foo.c
gcc -fpic -DSHARED_MODULE -I/path/to/apache/include -c mod_foo.c
ld -Bshareable -o mod_foo.so mod_foo.o
cp mod_foo.so /path/to/apache/modules/mod_foo.so
chmod 755 /path/to/apache/modules/mod_foo.so
[activating module `foo' in /path/to/apache/etc/httpd.conf]
$ apachectl restart
/path/to/apache/sbin/apachectl restart: httpd not running, trying to start
[Tue Mar 31 11:27:55 1998] [debug] mod_so.c(303): loaded module foo_module
/path/to/apache/sbin/apachectl restart: httpd started
$ _

The arguments files can be any C source file (.c), a object file (.o) or even a library archive (.a). The apxs tool
automatically recognizes these extensions and automatically used the C source files for compilation while just using the
object and archive files for the linking phase. But when using such pre-compiled objects make sure they are compiled for
position independent code (PIC) to be able to use them for a dynamically loaded shared object. For instance with GCC you
always just have to use -fpic. For other C compilers consult its manual page or at watch for the flags apxs uses to comâ
pile the object files.
...
DSO Compilation Options
-c This indicates the compilation operation. It first compiles the C source files (.c) of files into corresponding
object files (.o) and then builds a dynamically shared object in dsofile by linking these object files plus the
remaining object files (.o and .a) of files. If no -o option is specified the output file is guessed from the
first filename in files and thus usually defaults to mod_name.so.

...
DSO Installation and Configuration Options
-i This indicates the installation operation and installs one or more dynamically shared objects into the server's
modules directory.

-a This activates the module by automatically adding a corresponding LoadModule line to Apache's httpd.conf configuâ
ration file, or by enabling it if it already exists.


In my example below I will only compile and install the mod_rewrite apache module. I'm not interested about the -a switch of apxs which will also add the LoadModule line in apache configuration.

Code:
# /opt/apache/bin/apxs -c -i mod_rewrite.c
/opt/apache/build/libtool --silent --mode=compile gcc -prefer-pic -march=native -mfpmath=sse -msse2 -O2 -pipe -s -fomit-frame-pointer  -DLINUX=2 -D_REENTRANT -D_GNU_SOURCE -D_LARGEFILE64_SOURCE -pthread -I/opt/apache/include  -I/opt/apache/include   -I/opt/apache/include   -c -o mod_rewrite.lo mod_rewrite.c && touch mod_rewrite.slo
/opt/apache/build/libtool --silent --mode=link gcc -o mod_rewrite.la  -rpath /opt/apache/modules -module -avoid-version    mod_rewrite.lo
/opt/apache/build/instdso.sh SH_LIBTOOL='/opt/apache/build/libtool' mod_rewrite.la /opt/apache/modules
/opt/apache/build/libtool --mode=install cp mod_rewrite.la /opt/apache/modules/
cp .libs/mod_rewrite.so /opt/apache/modules/mod_rewrite.so
cp .libs/mod_rewrite.lai /opt/apache/modules/mod_rewrite.la
cp .libs/mod_rewrite.a /opt/apache/modules/mod_rewrite.a
chmod 644 /opt/apache/modules/mod_rewrite.a
ranlib /opt/apache/modules/mod_rewrite.a
PATH="$PATH:/sbin" ldconfig -n /opt/apache/modules
----------------------------------------------------------------------
Libraries have been installed in:
   /opt/apache/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
     during linking
   - use the `-Wl,--rpath -Wl,LIBDIR' linker flag
   - have your system administrator add LIBDIR to `/etc/ld.so.conf'

See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
----------------------------------------------------------------------
chmod 755 /opt/apache/modules/mod_rewrite.so


Now, all that remains to be done is to manually add the "LoadModule rewrite_module modules/mod_rewrite.so" line to the apache module section and check the configuration and restart apache:

Code:
# apachectl configtest
Syntax OK
# apachectl graceful


Always make sure that the apache extension tool apxs that you are using is the one from the already installed&working apache (this warning is retoric for most cases, but for those who have one apache instance installed from FreeBSD or Linux package system, which is inactive, and another apache customly compiled from source is essential) and also make sure that you are using the sources for the same version of apache, otherwise, you meight have error during compiling or, worse, a mod_rewrite module compiled from http-2.2.13 sources running a 2.2.11 apache, for example.





Top
Display posts from previous:  Sort by  
E-mail friendPrint view

Topics related to - "Apache 2.2 installation of mod_rewrite module without recompiling whole apache"
 Topics   Author   Replies   Views   Last post 
There are no new unread posts for this topic. Apache Invalid command 'AuthGroupFile', perhaps misspelled or defined by a module not included

LaR3

0

2345

Mon Sep 21, 2009 6:42 pm

LaR3 View the latest post

There are no new unread posts for this topic. php 5.4 Cannot load module 'memcached' because required module 'igbinary' is not loaded in Unknown

mandrei99

0

560

Wed Dec 11, 2013 11:10 am

mandrei99 View the latest post

There are no new unread posts for this topic. Apache: how to list virtual hosts that are currently configured on my Apache server ?

LaR3

0

1155

Sun Feb 07, 2010 10:04 am

LaR3 View the latest post

There are no new unread posts for this topic. Can't locate API module structure `mod_ssl' in file mod_ssl.so

LaR3

0

1301

Wed Sep 02, 2009 1:21 pm

LaR3 View the latest post

There are no new unread posts for this topic. Attachment(s) Nginx + apache (for PHP) with real IP addresses in logs

designeru

0

571

Tue May 18, 2010 9:49 am

designeru View the latest post

There are no new unread posts for this topic. How can I see what modules are loaded on my custom built Apache binary

LaR3

0

814

Sun Feb 07, 2010 9:54 am

LaR3 View the latest post

There are no new unread posts for this topic. Converting PhpBB-SEO Apache RewriteRule to Nginx rewrite

debuser

0

1650

Tue Feb 23, 2010 5:00 am

debuser View the latest post

There are no new unread posts for this topic. Apache to Nginx Server parameters translation with php function

debuser

0

49981

Thu Aug 26, 2010 7:47 am

debuser View the latest post

There are no new unread posts for this topic. How to test deflate/gzip compression on a HTTPS (HTTP over SSL) Apache server

debuser

0

1975

Tue Aug 03, 2010 3:30 am

debuser View the latest post

There are no new unread posts for this topic. Apache: access to /dir failed, reason: require directives present and no Authoritative handler

LaR3

0

1564

Mon Sep 21, 2009 6:48 pm

LaR3 View the latest post

 

Who is online
Users browsing this forum: No registered users and 0 guests
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum
Jump to:  
News News Site map Site map SitemapIndex SitemapIndex RSS Feed RSS Feed Channel list Channel list


Delete all board cookies | The team | All times are UTC - 5 hours [ DST ]



phpBB SEO