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/instdso.sh SH_LIBTOOL='/usr/share/apr-1.0/build/libtool' libphp5.la /usr/lib/apache2/modules
/usr/share/apr-1.0/build/libtool --mode=install cp libphp5.la /usr/lib/apache2/modules/
libtool: install: cp .libs/libphp5.so /usr/lib/apache2/modules/libphp5.so
cp: cannot create regular file `/usr/lib/apache2/modules/libphp5.so': 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/instdso.sh SH_LIBTOOL='/usr/share/apr-1.0/build/libtool' libphp5.la /home/username/php/usr/lib/apache2/modules
/usr/share/apr-1.0/build/libtool --mode=install cp libphp5.la /home/username/php/usr/lib/apache2/modules/
libtool: install: cp .libs/libphp5.so /home/username/php/usr/lib/apache2/modules/libphp5.so
libtool: install: cp .libs/libphp5.lai /home/username/php/usr/lib/apache2/modules/libphp5.la
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/libphp5.so
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
Breakdown:
--prefix
is necessary to install most of PHP under your home directory.--with-apxs2
is necessary to tell PHP where to findapxs2
. For some reason (probably presence of--prefix
) you must indicate this even ifapxs2
is in your$PATH
.- The
mkdir
is necessary to create the directory whereapxs2
will place the PHP module.load
file. INSTALL_ROOT
is an undocumented variable which overrides some install locations that for some reason do not conform to--prefix
.- Adding
/usr/sbin
to$PATH
is necessary on systems wherea2enmod
is not in regular users’$PATH
.
Notes:
- 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 themkdir
and use/home/username
as theINSTALL_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 usingINSTALL_ROOT
.