Delicious Bookmark this on Delicious Share on Facebook SlashdotSlashdot It! Digg! Digg



PHP : Installation and Configuration : Installation on Unix systems : Apache 2.0 on Unix systems

Apache 2.0 on Unix systems

This section contains notes and hints specific to Apache 2.0 installs of PHP on Unix systems.

Warning:

We do not recommend using a threaded MPM in production with Apache2. Use the prefork MPM instead, or use Apache1. For information on why, read the related FAQ entry on using Apache2 with a threaded MPM

You are highly encouraged to take a look at the » Apache Documentation to get a basic understanding of the Apache 2.0 Server.

PHP and Apache 2.0.x compatibility notes:

The following versions of PHP are known to work with the most recent version of Apache 2.0.x:

These versions of PHP are compatible to Apache 2.0.40 and later.

Apache 2.0 SAPI-support started with PHP 4.2.0. PHP 4.2.3 works with Apache 2.0.39, don't use any other version of Apache with PHP 4.2.3. However, the recommended setup is to use PHP 4.3.0 or later with the most recent version of Apache2.

All mentioned versions of PHP will work still with Apache 1.3.x.

Download the most recent version of » Apache 2.0 and a fitting PHP version from the above mentioned places. This quick guide covers only the basics to get started with Apache 2.0 and PHP. For more information read the » Apache Documentation. The version numbers have been omitted here, to ensure the instructions are not incorrect. You will need to replace the 'NN' here with the correct values from your files.

Example 2.4.  Installation Instructions (Apache 2 Shared Module Version)

1.  gzip -d httpd-2_0_NN.tar.gz
2.  tar xvf httpd-2_0_NN.tar
3.  gunzip php-NN.tar.gz
4.  tar -xvf php-NN.tar
5.  cd httpd-2_0_NN
6.  ./configure --enable-so
7.  make
8.  make install

   Now you have Apache 2.0.NN available under /usr/local/apache2,
   configured with loadable module support and the standard MPM prefork.
   To test the installation use your normal procedure for starting
   the Apache server, e.g.:
   /usr/local/apache2/bin/apachectl start
   and stop the server to go on with the configuration for PHP:
   /usr/local/apache2/bin/apachectl stop.

9.  cd ../php-NN

10. Now, configure your PHP.  This is where you customize your PHP
   with various options, like which extensions will be enabled.  Do a
   ./configure --help for a list of available options.  In our example
   we'll do a simple configure with Apache 2 and MySQL support.  Your
   path to apxs may differ, in fact, the binary may even be named apxs2 on
   your system.
   
     ./configure --with-apxs2=/usr/local/apache2/bin/apxs --with-mysql

11. make
12. make install

   If you decide to change your configure options after installation,
   you only need to repeat the last three steps. You only need to
   restart apache for the new module to take effect. A recompile of
   Apache is not needed.
               
   Note that unless told otherwise, 'make install' will also install PEAR,
   various PHP tools such as phpize, install the PHP CLI, and more.
   
13. Setup your php.ini
   
   cp php.ini-dist /usr/local/lib/php.ini
         
   You may edit your .ini file to set PHP options.  If you prefer having
   php.ini in another location, use --with-config-file-path=/some/path in
   step 10.
   
   If you instead choose php.ini-recommended, be certain to read the list
   of changes within, as they affect how PHP behaves.

14. Edit your httpd.conf to load the PHP module.  The path on the right hand
   side of the LoadModule statement must point to the path of the PHP
   module on your system.  The make install from above may have already
   added this for you, but be sure to check.

   For PHP 4:
 
     LoadModule php4_module modules/libphp4.so
     
   For PHP 5:
   
     LoadModule php5_module modules/libphp5.so

15. Tell Apache to parse certain extensions as PHP.  For example,
   let's have Apache parse the .php extension as PHP.  You could
   have any extension(s) parse as PHP by simply adding more, with
   each separated by a space.  We'll add .phtml to demonstrate.
           
     AddType application/x-httpd-php .php .phtml
                 
   It's also common to setup the .phps extension to show highlighted PHP
   source, this can be done with:
   
     AddType application/x-httpd-php-source .phps

16. Use your normal procedure for starting the Apache server, e.g.:
 
     /usr/local/apache2/bin/apachectl start


Following the steps above you will have a running Apache 2.0 with support for PHP as SAPI module. Of course there are many more configuration options available for both, Apache and PHP. For more information use ./configure --help in the corresponding source tree. In case you wish to build a multithreaded version of Apache 2.0 you must overwrite the standard MPM-Module prefork either with worker or perchild. To do so append to your configure line in step 6 above either the option --with-mpm=worker or --with-mpm=perchild. Take care about the consequences and understand what you are doing. For more information read the Apache documentation about the » MPM-Modules.

Note:

If you want to use content negotiation, read the Apache MultiViews FAQ.

Note:

To build a multithreaded version of Apache your system must support threads. This also implies to build PHP with experimental Zend Thread Safety (ZTS). Therefore not all extensions might be available. The recommended setup is to build Apache with the standard prefork MPM-Module.

Code Examples / Notes » install.unix.apache2

cdivitotawela

While I was installing PHP-5.2.2 in Fedora Core 5, I ran into a problem indicating php cannot find libxml2 during the configuration. Tried to find the what is this and realized after some serach in Google that libxml2-devel is required. Installed the libxml2 with yum as follows. Hope this will help someone.
> yum install libxml2-devel


payne747

When compiling php 5.1.2 on Debian 3.1 (Sarge) with Apache 2.2.0, I ran into problems with libxml2 and libxml2-config not found errors. After checking the base install, Debian leaves out the libxml2 headers, they can be downloaded using apt-get:
apt-get install libxml2 libxml2-dev
PHP should then compile fine.


jmartinno

Well I was getting the following error when trying to run make (shared module for Apache 2.0.52)
*** Warning: inter-library dependencies are not known to be supported.
*** All declared inter-library dependencies are being dropped.
(Then of course 'make install' would puke on itself not having what it needs.)
Soo, after some time looking I found that using:  
libtoolize --force
and following the instructions to add the contents of 1 file to the local file
cat /some/dir/file1 >> localfile
Would produce the desired results when you run:
make clean
make


jon drukman

We have been running Apache 2 Prefork + PHP 4 (many different versions) for well over a year now, serving 10's of millions of pages per day on dozens of servers.  It is completely stable and reliable.

frank@ethisoft

Using Apache2 & PHP5 work perfectly fine & safe together.
- all core modules are safe in Zend Engine 2
- third-party-libraries should be avoided
- semaphores and shared memory enables you to ensure yourself that your application/website is thread-safe also with non-thread-safe PHP modules!


neil

To install mysql and mysqli with PHP5 do the following:
after doing:
./configure --with-mysql=/path/to/mysql_config --with-mysqli=/path/to/mysql_config
do this:
"
   if you want to use both the old mysql and the new mysqli interface, load the Makefile into your editor and search for the line beginning with EXTRA_LIBS; it includes -lmysqlclient twice; remove the second instance
"
then you can:
make
make install
.....
Pleasse note: you must have mysql-dev installed (RPM or source) or you will not have the mysql_config file at all.  The standard, server, and client installations of MySQL do not include it.  I read somewhere that the mysql and mysqli paths must be identical.
Quoted from Michael Kofler at the following link:
http://www.kofler.cc/forum/forumthread.php?rootID=3571


jaya

PHP 5.1.4 INSTALLATION on Solaris 9 (Sparc)
Solaris9 Packages Installed:
Verify required package installation:
root# pkginfo SUNWbtool SUNWsprot SUNWtoo SUNWhea SUNWarc \
SUNWlibm SUNWlibms SUNWdfbh SUNWxglh SUNWcg6h
Uninstall Default Apache Packages:
root# /etc/init.d/apache stop
root# pkginfo |grep Apache
root# pkgrm SUNWaclg SUNWapchd SUNWapchr SUNWapchu
Create installation Directory:
root# mkdir /phpdata/
Download Required Packages from Sunfreeware:
Install libiconv-1.8 and gcc3.3.2 packages
root# pkgadd -d ./libiconv-1.8-sol9-sparc-local
root# pkgadd -d ./gcc-3.3.2-sol9-sparc-local
set LD_LIBRARY_PATH, CC and PATH variables
root# LD_LIBRARY_PATH=/usr/local/lib:/usr/local/lib/sparcv9/:\
/usr/lib:/usr/openwin/lib:/opt/local/lib:/usr/local/ssl/lib:\
/usr/local/apr/lib:/opt/mysql/mysql/lib
root# CC=gcc
root# PATH=$PATH:/usr/ucb:/usr/local/bin/
root# export LD_LIBRARY_PATH CC PATH

Install apr-1.2.2 and aprutil-1.2.2 packages
root# gzcat apr-1.2.2.tar.gz |tar xvf -
root# cd apr-1.2.2
root# ./configure
root# make
root# make install
root# cd ..
root# gzcat aprutil-1.2.2.tar.gz |tar xvf -
root# cd apr-util-1.2.2/
root# ./configure --with-apr=/usr/local/apr/
root# make
root# make install
Install gawk-3.1.4, expat-1.95.5, db-4.2.52.NC,
gdbm-1.8.3, libgcc-3.3 and libxml2-2.6.16 packages
root# cd ..
root# pkgadd -d ./gawk-3.1.4-sol9-sparc-local
root# pkgadd -d ./expat-1.95.5-sol9-sparc-local
root# pkgadd -d ./db-4.2.52.NC-sol9-sparc-local
root# pkgadd -d ./gdbm-1.8.3-sol9-sparc-local
root# pkgadd -d ./libgcc-3.3-sol9-sparc-local
root# pkgadd -d ./libxml2-2.6.16-sol9-sparc-local
Install GNU make package
root# gzcat make-3.81.tar.gz |tar xvf -
root# cd make-3.81
root# ./configure
root# make
root# make install
root# cd ..
Install mysql-standard-5.0.22 package
Search for user mysql
root# grep mysql /etc/passwd
root# grep mysql /etc/group
If not found create user and group mysql
root# groupadd mysql
root# useradd -G mysql mysql
root# pkgadd -d ./mysql-standard-5.0.22-solaris9-sparc.pkg.gz
Install openssl-0.9.7g package
root# gzcat openssl-0.9.7g.tar.gz |tar xvf -
root# cd openssl-0.9.7g
root# ./config shared
root# make
root# make install
root# cd ..
Install Apache2 package
root# gzcat httpd-2.2.0.tar.gz |tar xvf -
root# cd httpd-2.2.0
root# ./configure --enable-so
root# /usr/local/bin/make
root# /usr/local/bin/make install
root# cd ..
Install php-5.1.4 package
root# gzcat php-5.1.4.tar.gz |tar xvf -
root# cd php-5.1.4
root# ./configure --with-apxs2=/usr/local/apache2/bin/apxs\
--with-ldap --with-mysql=/opt/mysql/mysql/
root# /usr/local/bin/make
root# /usr/local/bin/make install
root# cp php.ini-dist /usr/local/lib/php.ini
Edit httpd.conf to load the PHP module
and to parse certain extensions as PHP
root# vi /usr/local/apache2/conf/httpd.conf
LoadModule php5_module modules/libphp5.so
AddType application/x-httpd-php .php .phtml
Start Apache
root# /usr/local/apache2/bin/apachectl start

Add environmental variables below HTTPD
root# vi /usr/local/apache2/bin/apachectl
LD_LIBRARY_PATH=/usr/local/lib:/usr/local/lib/sparcv9/:
/usr/lib:/usr/openwin/lib:/opt/local/lib:/usr/local/ssl/lib:
/usr/local/apr/lib:/opt/mysql/mysql/lib
PATH=/bin:/sbin:/usr/ccs/bin:/usr/sbin:/usr/openwin/bin:\
/usr/ucb:/usr/local/bin/
export LD_LIBRARY_PATH PATH
Create Apache Startup Script


chris@gerlt -dot- net

Install issues on Redhat, specifically RHEL4 with php4 already installed:  
I discovered that there was an issue caused by redhat loading php4 in another file seperate from the httpd.conf file!  This took me hours to discover.  Make sure you know if the apache config file (httpd.conf) is loading configurations from a directory (or another file(s)) as well.  If so, look in there for any php module loading which could conflict with the new module you are compiling/installing.


nospam-1

If you're trying to get PHP and Multiviews to work properly, try this page:
http://tranchant.plus.com/notes/multiviews
(In brief, a request for the URL http://example.net/thing, where there are possible matches thing.php and thing.pdf, returns a 406 with many browsers because of the application/x-httpd-php MIME type set above. The link above gives a better method for using php, instead using these directives:
AddHandler php5-script php [or php-script for php4]
AddType text/html php
For more info see the link.)


packard_bell_nec

If you install PHP as an Apache module, you can consider the following. Instead of adding:
application/x-httpd-php php
application/x-httpd-php-source phps
into Apache mime.types, you can add:
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
into Apache httpd.conf, OR you can add:
AddHandler application/x-httpd-php .php
AddHandler application/x-httpd-php-source .phps
into Apache httpd.conf. The last one is the preferred way of configuration, but it does not work in previous Apache versions.


me

If you can't find the "apxs" file on Debian 4 (etch) or a previous Debian version (which is still supported), you need to install the package "apache2-prefork-dev" (if you use Apache-Prefork).

v_santhanam

if you are getting the following error : "Cannot load /usr/local/apache2/modules/libphp4.so into server: /usr/local/apache2/
modules/libphp4.so: undefined symbol: compress" , you have to add --with-zlib to php config


felixcca

I've (painfully) discovered that installing PHP5 with "make install" under SuSe 9.2 is NOT a good idea.
http://www.aditus.nu/jpgraph/apache2suse.php
This page explains how to install it without breaking everything that's php-related in the Apache2 configuration. Its first purpose, though, is to show how to have php 4 and 5 to cohabit properly.


fggarcia

I think that it's important says that the option --with-apxs2=/usr/local/apache2/bin/apxs in the configure script it's necesary to build the libphp5.so (in PHP5). Then in the make install command, this .so module will be installed in the modules directory of Apache home
I see on the Web a lot of persons with the trouble of missing the libphp5.so and this is the solution.
Regards,
Frank.


praveen dot k

Hi too had same problem with multiview like when i execute http://huey/admin/test.php it used to compile but when i use http://huey/admin/test it wouldnt recognise it as php file... i worked it out with the addhandler method and AddType in different line and setting multiview for directive
"multiviews Options Indexes FollowSymLinks MultiViews"
the directives u can set it to root directory so now when u type pn test it will search in precendence for test.php, test.html if any .....
its working for me with apache2.0.47 and php 4.3.9 on solaris
praveen


pillepop2003

For unix (especially opensuse 10.0) you can find bison and flex here:
ftp.gnu.org/non-gnu/flex
ftp.gnu.org/pub/gnu/bison
Peace ;-)


mihai dot sandu

For the SuSE9.2 install of PHP5.
First:
If building on a x64 platform, please set LDFLAGS="-L/usr/lib64" before configure.
As for install, it suffices to go to /etc/apache2 and:
ln -s sysconfig.d/loadmodule.conf httpd2-prefork.conf
and then make install


susie91

for slackware 10.2 users with apache2, mysql5, and trying to install php5:
when following the directions above, after this step:
./configure --with-apxs2=/usr/local/apache2/bin/apxs --with-mysql
i kept getting this error:
"Unable to find MySql header files...."
the only way i could get php5 with mysql support was to compile MySql5 from source, and not use the binary as the mysql site recommends.
then i was able to ./configure successfully, but for some reason php was configured to compile the CGI version.
so, had to use this ./configure line:
./configure --with-apxs2=/usr/local/apache2/bin/apxs --with-mysql=/usr/local/mysql  --disable-cgi
alternatively, you could install php4 which does bundle the MySql client files.


sukhruprai

For good step by step instructions read Compiling PHP and Apache 2 from source on Linux OS:
http://www10.brinkster.com/ssruprai/comphp.asp


stoopbrain

Following on from Chris' comment (22-Sept-2006), my RHEL4 PHP4 rpm added a php.conf file at:
/etc/httpd/conf.d/php.conf
This was referenced in the httpd.conf by it's Include directive:
Include conf.d/*.conf


happyboy

FILE TRUNCATED!!
during the make process should u receive an error declaring ext/ctype/ctype.lo (or another file) is truncated then you need to 'make clean' prior to a healthy 'make' and 'make install.'
looking into your ext/ directory you may find the offensive file to be 1 byte long.


dan scott dan dot scott

Building PHP 5.x with Apache2 on SuSE Professional 9.1/9.2
SuSE uses a rather fragmented set of Apache configuration files stored in /etc/apache2/. When you configure PHP 5.x with:
$ ./configure --with-apxs2=/usr/sbin/apxs2
$ make
everything builds just fine; but when you issue:
$ su -c "make install"
the unconventional Apache conf file layout confuses the install-sapi section of the Makefile and the process halts with the following error:
apxs:Error: Config file /etc/apache2/httpd2-prefork.conf not found.
make: *** [install-sapi] Error 1
At this point only the PHP SAPI library has been copied into place; the rest of the files (like PEAR scripts, PHP-CLI, etc) have not been installed. But never fear! You can overcome this problem with the following steps:
1. Edit Makefile and change the following line to remove "install-sapi":
install_targets = install-sapi install-cli install-pear install-build install-headers install-programs
2. Issue the make install command again:
$ su -c "make install"
3. Add the PHP module & type instructions to the Apache configuration. As root, create a new file, /etc/apache2/conf.d/php5.conf that contains the following lines:
LoadModule php5_module /usr/lib/apache2/libphp5.so
AddType application/x-httpd-php php
--- And that's it. Everything else is just as the documentation suggests it should be.


paul dot mcgurn

apxs/apxs2 aren't installed by default on some distributions (mine is CentOS 5 server).  To resolve this, install the package httpd-devel .

sukhruprai

A good introduction to compiling PHP and Apache 2 on Linux System. Beginners may find it very useful.
http://www.web-tech-india.com/articles/php/compiling_php_apache/


Change Language


Follow Navioo On Twitter
Apache 1.3.x on Unix systems
Apache 2.0 on Unix systems
Caudium
fhttpd related notes
Sun
CGI and command line setups
HP-UX specific installation notes
OpenBSD installation notes
Solaris specific installation tips
Debian GNU/Linux installation notes
eXTReMe Tracker