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



PHP : Installation and Configuration : Installation on Unix systems

Chapter 2. Installation on Unix systems

This section will guide you through the general configuration and installation of PHP on Unix systems. Be sure to investigate any sections specific to your platform or web server before you begin the process.

As our manual outlines in the General Installation Considerations section, we are mainly dealing with web centric setups of PHP in this section, although we will cover setting up PHP for command line usage as well.

There are several ways to install PHP for the Unix platform, either with a compile and configure process, or through various pre-packaged methods. This documentation is mainly focused around the process of compiling and configuring PHP. Many Unix like systems have some sort of package installation system. This can assist in setting up a standard configuration, but if you need to have a different set of features (such as a secure server, or a different database driver), you may need to build PHP and/or your web server. If you are unfamiliar with building and compiling your own software, it is worth checking to see whether somebody has already built a packaged version of PHP with the features you need.

Prerequisite knowledge and software for compiling:

  • Basic Unix skills (being able to operate "make" and a C compiler)
  • An ANSI C compiler
  • flex: Version 2.5.4
  • bison: Version 1.28 (preferred), 1.35, or 1.75
  • A web server
  • Any module specific components (such as gd, pdf libs, etc.)

The initial PHP setup and configuration process is controlled by the use of the command line options of the configure script. You could get a list of all available options along with short explanations running ./configure --help. Our manual documents the different options separately. You will find the core options in the appendix, while the different extension specific options are descibed on the reference pages.

When PHP is configured, you are ready to build the module and/or executables. The command make should take care of this. If it fails and you can't figure out why, see the Problems section.

Apache 1.3.x on Unix systems

This section contains notes and hints specific to Apache installs of PHP on Unix platforms. We also have instructions and notes for Apache 2 on a separate page.

You can select arguments to add to the configure on line 10 below from the list of core configure options and from extension specific options described at the respective places in the manual. The version numbers have been omitted here, to ensure the instructions are not incorrect. You will need to replace the 'xxx' here with the correct values from your files.

Example 2.1.  Installation Instructions (Apache Shared Module Version) for PHP

1.  gunzip apache_xxx.tar.gz
2.  tar -xvf apache_xxx.tar
3.  gunzip php-xxx.tar.gz
4.  tar -xvf php-xxx.tar
5.  cd apache_xxx
6.  ./configure --prefix=/www --enable-module=so
7.  make
8.  make install
9.  cd ../php-xxx

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 1 and MySQL support.  Your
   path to apxs may differ from our example.

     ./configure --with-mysql --with-apxs=/www/bin/apxs

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 file:

     cp php.ini-dist /usr/local/lib/php.ini

   You may edit your .ini file to set PHP options.  If you prefer your
   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 libexec/libphp4.so

   For PHP 5:
                     
     LoadModule php5_module libexec/libphp5.so
     
15. And in the AddModule section of httpd.conf, somewhere under the
   ClearModuleList, add this:
   
   For PHP 4:
   
     AddModule mod_php4.c
     
   For PHP 5:
   
     AddModule mod_php5.c

16. 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

17. Use your normal procedure for starting the Apache server. (You must
   stop and restart the server, not just cause the server to reload by
   using a HUP or USR1 signal.)


Alternatively, to install PHP as a static object:

Example 2.2.  Installation Instructions (Static Module Installation for Apache) for PHP

1.  gunzip -c apache_1.3.x.tar.gz | tar xf -
2.  cd apache_1.3.x
3.  ./configure
4.  cd ..

5.  gunzip -c php-5.x.y.tar.gz | tar xf -
6.  cd php-5.x.y
7.  ./configure --with-mysql --with-apache=../apache_1.3.x
8.  make
9.  make install

10. cd ../apache_1.3.x

11. ./configure --prefix=/www --activate-module=src/modules/php5/libphp5.a
   (The above line is correct! Yes, we know libphp5.a does not exist at this
   stage. It isn't supposed to. It will be created.)

12. make
   (you should now have an httpd binary which you can copy to your Apache bin dir if
   it is your first install then you need to "make install" as well)

13. cd ../php-5.x.y
14. cp php.ini-dist /usr/local/lib/php.ini

15. You can edit /usr/local/lib/php.ini file to set PHP options.
   Edit your httpd.conf or srm.conf file and add:
   AddType application/x-httpd-php .php


Note:

Replace php-5 by php-4 and php5 by php4 in PHP 4.

Depending on your Apache install and Unix variant, there are many possible ways to stop and restart the server. Below are some typical lines used in restarting the server, for different apache/unix installations. You should replace /path/to/ with the path to these applications on your systems.

Example 2.3. Example commands for restarting Apache

1. Several Linux and SysV variants:
/etc/rc.d/init.d/httpd restart

2. Using apachectl scripts:
/path/to/apachectl stop
/path/to/apachectl start

3. httpdctl and httpsdctl (Using OpenSSL), similar to apachectl:
/path/to/httpsdctl stop
/path/to/httpsdctl start

4. Using mod_ssl, or another SSL server, you may want to manually
stop and start:
/path/to/apachectl stop
/path/to/apachectl startssl


The locations of the apachectl and http(s)dctl binaries often vary. If your system has locate or whereis or which commands, these can assist you in finding your server control programs.

Different examples of compiling PHP for apache are as follows:

./configure --with-apxs --with-pgsql

This will create a libphp5.so (or libphp4.so in PHP 4) shared library that is loaded into Apache using a LoadModule line in Apache's httpd.conf file. The PostgreSQL support is embedded into this library.

./configure --with-apxs --with-pgsql=shared

This will create a libphp4.so shared library for Apache, but it will also create a pgsql.so shared library that is loaded into PHP either by using the extension directive in php.ini file or by loading it explicitly in a script using the dl() function.

./configure --with-apache=/path/to/apache_source --with-pgsql

This will create a libmodphp5.a library, a mod_php5.c and some accompanying files and copy this into the src/modules/php5 directory in the Apache source tree. Then you compile Apache using --activate-module=src/modules/php5/libphp5.a and the Apache build system will create libphp5.a and link it statically into the httpd binary (replace php5 by php4 in PHP 4). The PostgreSQL support is included directly into this httpd binary, so the final result here is a single httpd binary that includes all of Apache and all of PHP.

./configure --with-apache=/path/to/apache_source --with-pgsql=shared

Same as before, except instead of including PostgreSQL support directly into the final httpd you will get a pgsql.so shared library that you can load into PHP from either the php.ini file or directly using dl().

When choosing to build PHP in different ways, you should consider the advantages and drawbacks of each method. Building as a shared object will mean that you can compile apache separately, and don't have to recompile everything as you add to, or change, PHP. Building PHP into apache (static method) means that PHP will load and run faster. For more information, see the Apache » web page on DSO support.

Note:

Apache's default httpd.conf currently ships with a section that looks like this:

User nobody
Group "#-1"

Unless you change that to "Group nogroup" or something like that ("Group daemon" is also very common) PHP will not be able to open files.

Note:

Make sure you specify the installed version of apxs when using --with-apxs=/path/to/apxs. You must NOT use the apxs version that is in the apache sources but the one that is actually installed on your system.

Code Examples / Notes » install.unix

arjan van bentem

When using Red Hat Fedora, beware of Security Enhanced Linux, SELinux.
Quoted from Red Hat: "The security goal is to make sure that Apache HTTP is only reading the static Web content, and not doing anything else such as writing to the content, connecting to database sockets, reading user home directories, etc."
These limitations include, among many other things, using mkdir to create directories, using fopen to access files, using fopen or get_headers to read URLs, or using exec to run external applications that happen to use sockets (or maybe access some files, but which will run fine when executed from the command line as Unix user apache or httpd -- such as HylaFAX "faxstat" as invoked from nweb2fax recvq.php and sendq.php).
See /var/log/messages for any denials due to the SELinux policy. To disable it:
- System, Administration, Security Level and Firewall
- open the SELinux tab
- click the Transition tree
- check Disable SELinux protection for Apache HTTP
- execute /etc/init.d/httpd restart
See also http://fedora.redhat.com/docs/selinux-faq/ and http://php.net/results.php?q=selinux&p=wholesite


dimaberastau

when installing with mysql support (--with-mysql=<path/to/your/mysql>) via Apache APXS you'll probably get something like 'can't load libmysqlclient.so' when you try to start up apache. There are 2 solutions to this problem. First, (as documented in INSTALL file of the php4 distribution) you can modify /etc/ld.so.conf to contain the directory name where libmysqlclient.so is (so if your mysql is installed in /usr/local, you want to add something like /usr/local/lib/mysql into /etc/ld.so.conf), else (and particularly if you haven't got the super-user on the system) you can modify (or create if it isn't defined already) LD_LIBRARY_PATH shell variable to reflect the changes you would have otherwise made to /etc/ld.so.conf (again if mysql is /usr/local LD_LIBRARY_PATH=/usr/local/lib/mysql). Either one of these methods will get the problem sorted. Just remember to run ldconfig (so that /etc/ld.so.cache is updated) if you chose to modify /etc/ld.so.conf

doug

Users compiling under some versions of Solaris/SunOS may encounter the following error.
  symbol ap_block_alarms: referenced symbol not found
To address this problem, add the following additional flag to the Apache build configure line:
  --enable-rule=SHARED_CORE
So, adding this to the original instructions, you'd configure your Apache build like so:
  ./configure --prefix=/www --enable-module=so --enable-rule=SHARED_CORE
Doug


karthik dot k

This is regarding the post down below about the problem with openssl on RH9. Openssl on RH9 is built with kerberos. To get PHP to build correctly you need the output of these commands when you make.
[root@graf-spee local]# pkg-config --cflags openssl
-I/usr/kerberos/include  
[root@graf-spee local]# pkg-config --libs openssl
-L/usr/kerberos/lib -lssl -lcrypto -lresolv -lgssapi_krb5 -lkrb5 -lk5crypto -lcom_err -ldl -lz  
These could be added to your make command thus. I have not tested it out, but should work with some tweaking
make EXTRA_LDFLAGS=`pkg-config --libs openssl` EXTRA_CFLAGS=`pkg-config --cflags openssl`


moonlightcheese

There is little or no documentation regarding the fact that MySQL Client Library isn't bundled with PHP anymore.  The installation instructions need to be changed with, at the very least, some instructions for how to get PHP to recognize that the client library is installed.  I realize that this may be a problem with licensing and as such, it's not possible to document too much regarding MySQL...
I personally fumbled around with PHPNuke for a day or two before realizing that I was getting blank pages due to database problems.  It would be nice to have a ./config option like --with-mysql-client-library='/path/to/libmysqlclient.so' at the very least... i still can't get PHP to recognize where the mysql client library is and MySQL's documentation is jumbled at best...


alexander justadot henry

The system at my workplace has a need for apache/php with all static compilation.  In order to save time adminning our systems, I decided to make my own RPM of php/apache with mod_ssl support.  I had always installed by hand with the instructions on this page, but when buiding the RPM way, came upon the following error when apache was compiling:
===> src/modules/php4
make[4]: *** No rule to make target `all'. Stop.
Ordinarily this is because one did not do a 'make install' in php before the second apache configure, or somehow the make install failed.  But the way rpm's work, the make install must be in the %install portion of the spec file, after all makes are completed.
make install-sapi
This line will copy relevant files to the directory specified in --with-apache


thansen

The configure directives --with-apxs2 and --with-apxs2filter are not compatible one with other, even though the configure script will not complain about that. Each one affect the way Apache will call the php parser: If you choose the first one, you must use the traditional include:
AddType application/x-httpd-php php
at httpd.conf, to call the parser. If you use the --with-apxs2filter, the include will be:
<Files *.php>
       SetOutputFilter PHP
       SetInputFilter  PHP
</Files>
, and php will be called as a filter to .php files.
If you use both together, you will get compilation errors (duplicate symbols while linking libphp4).


mbabcock-php

The best configuration guide I've found for Apache with PHP (and PERL, mod_ssl, etc.) is Apacompile.  Its home site is
http://www.delouw.ch/linux/apache.phtml


squeegee

regarding the note by phptard at gmail dot com:
This was a good starting point to get php built against the Intel-compiled mysql, but in my case, there were still errors. It wasn't until I also added LIBS="-lirc" to the beginning of the configure line that it would configure without errors. It also compiled fine after that. So the start of my configure line looked like this:
LDFLAGS="-lirc" LIBS="-lirc" EXTRA_LIBS="-lirc" ./configure


samael99

Quick hint for people using RH8:
if make gives you this error
FT_ENCODING_MS_SYMBOL undeclared
change on line in this file
/usr/include/freetype2/freetype/freetype.h
Search for ft_encoding_symbol - change it to
ft_encoding_ms_symbol
Now this problem is dealt with, go ahead with make.
Good Luck !


alex

In response to the guy who posted about the SELinux:
I am new to linux/apache/php (coming from server 2003/IIS/Asp.Net), so i was stumped as to why php/apache could only use static content. Also, it couldn't access some documents that you created somewhere else, and then dragged into the HTML directory.
After some research, i found the problem was the SELinux context of the files. It took me forever to find the Proper command to use to change that, as all the examples on the net were out dated using old commands:
# chcon "user_u:object_r:httpd_sys_content_t" /var/www/html -Rc
This will change the SELinux context of all the documents under the /var/www/html directory (which is the web directory under Fedora), to allow the httpd process to access them, and the '-Rc' flag will make the changes Recursive, and will output it's progress for each file that it sucessfully changes.


diemuzi

In reference to van [at] webfreshener [dot] com to fix the krb5 problems. An easier fix is to do the following:
ln -s /usr/kerberos/include/krb5.h /usr/include/krb5.h
ln -s /usr/kerberos/include/profile.h /usr/include/profile.h
ln -s /usr/kerberos/include/com_err.h /usr/include/com_err.h
This will help solve some deps. in the future incase a situation with another compilation occurs.


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.


robert_sgi

If you install php 4 on SGI IRIX 6.5 (in my case it was php 4.3.6 on Silicon Graphics O2 IRIX 6.5.22 machine) and you're building it with:
--with-gettext=/usr/freeware
then you need to manually edit the file named "configure" (from the php source directory) and change the line# 36739
from:
GETTEXT_LIBDIR=$GETTEXT_DIR/lib
to:
GETTEXT_LIBDIR=$GETTEXT_DIR/lib32
If you have problems in locating the line, search the text for "bindtextdomain", and look several (4) lines above.


aaronmorris

If you have the libphp4.a instead of libphp4.so on AIX, you can extract the .so file from the .a file by running "ar -x libphp4.a".

phpnet

If you get an apache failing to start message with SElinux enabled.
The error in var/log/messages is:
Oct 17 10:41:49 nwn kernel: audit(1192635709.825:37936): avc:  denied  { execmod } for  pid=23189 comm="httpd" name="libphp5.so" dev=hda3 ino=4980740 scontext=user_u:system_r:unconfined_t:s0 tcontext=user_u:object_r:usr_t:s0 tclass=file
See the following page:
http://danwalsh.livejournal.com/6117.html?thread=23525
Basically do a chcon -t textrel_shlib_t libphp5.so
It does not sound like it is too dangerous.


marshalm

HP-UX 11.X PA-RISC installation with oracle (oci8). You need to install the HP-UX patch PHSS_22514 patch (updated libdld.sl), otherwise you will get errors with dlopen() and dlclose() not found during the apache integration stage.

philip

HOWTO: Installation on Cobalt RaQ  (RaQ3 or RaQ4) :
http://marc.theaimsgroup.com/?l=php-general&m=98039640119670&w=2


dpresley4

Hi,
PROBLEM:  ./configure PHP --with-oci8
fails with unresolved references such as __rpc_thread_destroy@GLIBC_2_2_3_...
ONE SOLUTOIN
FOR SOLVING PHP ./configure RESULTING IN  __rcp_thread_destroy@GLIBC_2_2_3_... AND
UNRESOLVED REFERENCES WITH ORACLE OCI8
KEYWORDS: PHP OCI OCI8 NET8 ./configure __rpc_thred_destroy UNRESOLVED REFERENCES
For building php-4.4.1 or later with oci8, make sure your LD_LIBARRY_PATH has at a minimum the following directories in its path for Oracle8i 8.1.5 or later, Oracle9i 9.0.2 or later, and Oracle9i Release 2: 9.2.0.4 or later, do the following:
Note:  We are not using the Oracle Instant Client here.  This assumes you have an actual Oracle Installation.
1. Set ORACLE_HOME
Example using Oracle 9i Relase 2 -- 9.2.0.5:
ORACLE_HOME=/opt/app/oracle/product/9iR2
2. Set LD_LIBRARY_PATH with:
LD_LIBRARY_PATH=$ORACLE_HOME/lib: \
   $ORACLE_HOME/rdbms/lib:\
   $LD_LIBRARY_PATH
3. On Unix / Linux, don't forget to export these environment variables:
export ORACLE_HOME LD_LIBRARY_PATH
4. Now, build PHP with the following:
./configure --with-apxs2=<path to Apache 2.0/bin/apxs> --with-oci8=$ORACLE_HOME --enable-sigchild
It should now build correctly. The key with Oracle is to ensure that you pick up the libclntX.so (client librariess) where X is the Oracle version associated with the version your using for instance, in the above example, libclnt9.so
Also note that if your using Oracle 9iAS Release 2 v9.0.2, Oracle 10g iAS Release 1 v9.0.4.1, the above steps will work because ORACLE_HOME will containe all of the libraries necessary.  Simply point ORACLE_HOME to the top level directory of these installations and set LD_LIBRARY_PATH as described above.
Hope this helps.


phpnet

Further down in the links it talks about using the fPIC option in the compiler to fix the SElinux error.  I messed around with it and adding --with-pic to the configure will also allow the module to load.  I have not done more testing with it but apache at least starts.  If you have already compiled you will need to do a make clean before recompiling.

aryeh dot friedman

For all multi-core processors (not just Sun as noted above) you need to add --enable-shared-core to the apache config

flconseil

Building Apache 2 and PHP 5.1.2 :
On AIX 5.2 : http://flaupretre.free.fr/redir.php?key=build_apa_aix
On HP-UX 11i (11.11) : http://flaupretre.free.fr/redir.php?key=build_apa_hpux
These documents are complete step-by-step howtos, and describe how to buid a self-sufficient package, including every software it depends on (zlib, SSL, LDAP, iconv, expat, xml, xslt, gd, png, Xpm, jpeg, freetype, bzip2, curl, MySQL, PostgreSQL, Oracle, AdoDB).


phptard

after a long night of wrestling with mysql4.0 under linux compiled with the intel compiler, i've gotten php5.0.3 to compile with mysql libraries for this flavor of mysql:
1: download the mysql for linux/intel compiler and install
2: download the rpm for the intel compiler libraries and install
3: configure php with LDFLAGS="-lirc -lgcc_s" and EXTRA_LIBS="-lirc -lgcc_s"
Example:
LDFLAGS="-lirc -lgcc_s" LD_LIBRARY_PATH="-L/usr/lib64" LD_PATH="-L/usr/lib64" LDPATH="-L/usr/lib64" EXTRA_LIBS="-lirc -lgcc_s" ./configure --with-apxs2=/usr/local/apache/bin/apxs --with-ssl=/usr/local/ssl --without-sqlite --with-zlib-dir=/usr --with-mysql=/usr/local/mysql
of course this is on a xeon system that has half of its modules in the /usr/lib64 directory, so on a normal system, without the other kruft, it would look something more like this:
LDFLAGS="-lirc -lgcc_s" EXTRA_LIBS="-lirc -lgcc_s" ./configure --with-apxs2=/usr/local/apache/bin/apxs --with-mysql=/usr/local/mysql
Hopefully this will save someone the 6 hour headache it caused me..


jazee_at_bigfoot.com

http://dan.drydog.com/apache2php.html has a nice set of instructions for Apache2 + php

Change Language


Follow Navioo On Twitter
General Installation Considerations
Installation on Unix systems
Installation on Mac OS X
Installation on Windows systems
Installation of PECL extensions
Problems?
Runtime Configuration
eXTReMe Tracker