Installing PHP and Apache module under /home

Let’s say you have your own Apache 2 setup in your home directory, and you want to build and install PHP as well, and set it up as an Apache module without root privileges (e.g. if you want to use a different PHP version than the one installed globally).

You may run into problems such as PHP’s configure script not detecting apxs2 (and thus not building an Apache module).

Or, if you specify --with-apxs2, the configure script may not find it:

checking for Apache 2.0 handler-module support via DSO through APXS...

Sorry, I cannot run apxs.  Possible reasons follow:

1. Perl is not installed
2. apxs was not found. Try to pass the path using --with-apxs2=/path/to/apxs
3. Apache was not built using --enable-so (the apxs usage page is displayed)

The output of apxs follows:
./configure: line 8374: apxs: command not found
configure: error: Aborting

Or installation might fail, despite that you’ve specified a --prefix parameter to configure:

Installing PHP SAPI module:       apache2handler
/usr/share/apache2/build/ SH_LIBTOOL='/usr/share/apr-1.0/build/libtool' /usr/lib/apache2/modules
/usr/share/apr-1.0/build/libtool --mode=install cp /usr/lib/apache2/modules/
libtool: install: cp .libs/ /usr/lib/apache2/modules/
cp: cannot create regular file `/usr/lib/apache2/modules/': Permission denied
apxs:Error: Command failed with rc=65536
make: *** [install-sapi] Error 1

Or another installation error:

Installing PHP SAPI module:       apache2handler
/usr/share/apache2/build/ SH_LIBTOOL='/usr/share/apr-1.0/build/libtool' /home/username/php/usr/lib/apache2/modules
/usr/share/apr-1.0/build/libtool --mode=install cp /home/username/php/usr/lib/apache2/modules/
libtool: install: cp .libs/ /home/username/php/usr/lib/apache2/modules/
libtool: install: cp .libs/libphp5.lai /home/username/php/usr/lib/apache2/modules/
libtool: install: warning: remember to run `libtool --finish /home/username/php/src/php-5.4.11/libs'
chmod 644 /home/username/php/usr/lib/apache2/modules/
apxs:Error: Config file /home/username/php/etc/apache2/mods-available not found.

Or another:

[preparing module `php5' in /home/username/php/etc/apache2/mods-available/php5.load]
Can't exec "a2enmod": No such file or directory at /usr/bin/apxs2 line 555.
'a2enmod php5' failed
make: *** [install-sapi] Error 2

Here’s what I had to do to get it working:

$ ./configure --prefix=/home/username/php --with-apxs2=/usr/bin/apxs2
$ mkdir /home/username/php/etc/apache2/mods-available 
$ make
$ INSTALL_ROOT=/home/username/php PATH=/usr/sbin:$PATH make install


  1. --prefix is necessary to install most of PHP under your home directory.
  2. --with-apxs2 is necessary to tell PHP where to find apxs2. For some reason (probably presence of --prefix) you must indicate this even if apxs2 is in your $PATH.
  3. The mkdir is necessary to create the directory where apxs2 will place the PHP module .load file.
  4. INSTALL_ROOT is an undocumented variable which overrides some install locations that for some reason do not conform to --prefix.
  5. Adding /usr/sbin to $PATH is necessary on systems where a2enmod is not in regular users’ $PATH.


  • I think the globally-installed Apache must already have the PHP module enabled, otherwise a2enmod will fail.
  • If you have a /home/username/etc/apache2/mods-available, you should be able to skip the mkdir and use /home/username as the INSTALL_ROOT.
  • It looks like some (or all) files will be installed to /home/username/php/home/username/php/. TODO: Find out if --prefix is needed at all if we’re using INSTALL_ROOT.

2 thoughts on “Installing PHP and Apache module under /home

  1. Pingback: Installing PHP in my home directory | BlogoSfera

Leave a Reply

Your email address will not be published. Required fields are marked *