subscribe: Posts | Comments

PHP Installation and Configuration on Different Platform


PHP Installation Considerations

Before starting the installation, first you need to know what
do you want to use PHP for. There are three main fields you can use

  • Websites and web applications
    (server-side scripting)
  • Command line scripting.
  • Desktop (GUI) applications.


For the first and most common form, you need three things: PHP
itself, a web server and a web browser. You probably already have a web
browser, and depending on your operating system setup, you may also have a web
server (e.g. Apache on Linux and MacOS X; IIS on Windows). You may also rent
webspace at a company. This way, you don’t need to set up anything on your
own, only write your PHP scripts, upload it to the server you rent, and see
the results in your browser.

In case of setting up the server and PHP on your own, you have
two choices for the method of connecting PHP to the server. For many servers
PHP has a direct module interface (also called SAPI). These servers include
Apache, Microsoft Internet Information Server, Netscape and iPlanet servers.
Many other servers have support for ISAPI, the Microsoft module interface (OmniHTTPd
for example). If PHP has no module support for your web server, you can always
use it as a CGI or FastCGI processor. This means you set up your server to use
the CGI executable of PHP to process all PHP file requests on the server.

If you are also interested to use PHP for command line
scripting (e.g. write scripts autogenerating some images for you offline, or
processing text files depending on some arguments you pass to them), you
always need the command line executable.

With PHP you can also write desktop GUI applications using the
PHP-GTK extension. This is a completely different approach than writing web
pages, as you do not output any HTML, but manage windows and objects within
them. For more information about PHP-GTK, please
» visit the site dedicated
to this extension
. PHP-GTK is not included in the official PHP

From now on, this section deals with setting up PHP for web
servers on Unix and Windows with server module interfaces and CGI executables.
You will also find information on the command line executable in the following

PHP source code and binary distributions for Windows can be
found at »
. We recommend you to choose a
» mirror
nearest to you for downloading the distributions.

PHP  on Unix systems

Table of Contents

  • Apache 2.0 on Unix systems
  • Lighttpd 1.4 on Unix systems
  • Caudium
  • fhttpd related notes
  • Sun, iPlanet and Netscape servers on Sun Solaris
  • CGI and command line setups
  • HP-UX specific installation notes
  • OpenBSD installation notes
  • Solaris specific installation tips
  • Debian GNU/Linux installation notes

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 " PHP 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.

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
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 #1 Installation Instructions (Apache Shared Module Version) for

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/
For PHP 5:
LoadModule php5_module libexec/
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 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
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 #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 (or in PHP 4) shared library that is loaded
into Apache using a LoadModule line in Apache’s
file. The PostgreSQL support is embedded into this library.

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

This will create a
shared library for Apache, but it will also create a
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 shared library that you can load into PHP
from either the php.ini file or directly using

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


PHP on Mac OS X

Table of Contents

  • Using the bundled PHP
  • Compiling for OS X Server
  • Compiling for MacOS X Client

This section contains notes and hints specific to installing
PHP on Mac OS X. There are two slightly different versions of Mac OS X, Client
and Server, our manual deals with installing PHP on both systems. Note that
PHP is not available for MacOS 9 and earlier versions.

Using Packages

There are a few pre-packaged and pre-compiled versions of
PHP for Mac OS X. This can help 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 yourself. If you are unfamiliar with building and compiling your own
software, it’s worth checking whether somebody has already built a packaged
version of PHP with the features you need.

The following resources offer easy to install packages
and precompiled binaries for PHP on Mac OS:


PHP on Windows systems

Table of Contents

  • Windows Installer (PHP 5.1.0 and earlier)
  • Manual Installation Steps
  • ActiveScript
  • Microsoft IIS / PWS
  • Apache 1.3.x on Microsoft Windows
  • Apache 2.0.x on Microsoft Windows
  • Sun, iPlanet and Netscape servers on Microsoft Windows
  • OmniHTTPd Server
  • Sambar Server on Microsoft Windows
  • Xitami on Microsoft Windows
  • Building from source
  • Installation of extensions on Windows

This section applies to Windows 98/Me and Windows
NT/2000/XP/2003. PHP will not work on 16 bit platforms such as Windows 3.1 and
sometimes we refer to the supported Windows platforms as Win32. Windows 95 is
no longer supported as of PHP 4.3.0.

There are two main ways to install PHP for Windows: either
manually or by using the installer.

If you have Microsoft Visual Studio, you can also build PHP
from the original source code.

Once you have PHP installed on your Windows system, you may
also want to load various extensions for added functionality.


There are several all-in-one installers over the Internet,
but none of those are endorsed by, as we believe that using one of
the official windows packages from
is the best choice to have your system secure and optimised.

Windows Installer (PHP 5.2 and later)

The Windows PHP installer for later versions of PHP is built
using MSI technology using the Wix Toolkit (»
). It will install and configure PHP and all
the built-in and
extensions, as well as configure many of the popular web
servers such as IIS, Apache, and Xitami.

First, install your selected
HTTP (web) server on
your system, and make sure that it works. Then proceed with one of the
following install types.

Normal Install

Run the MSI installer and follow the instructions provided
by the installation wizard. You will be prompted to select the Web Server
you wish to configure first, along with any configuration details needed.

You will then be prompted to select which features and
extensions you wish to install and enable. By selecting "Will be installed
on local hard drive" in the drop-down menu for each item you can trigger
whether to install the feature or not. By selecting "Entire feature will
be installed on local hard drive", you will be able to install all
sub-features of the included feature ( for example by selecting this
options for the feature "PDO" you will install all PDO Drivers ).


It is not recommended to install all extensions by
default, since many other them require dependencies from outside PHP in
order to function properly. Instead, use the Installation Repair Mode
that can be triggered thru the ‘Add/Remove Programs’ control panel to
enable or disable extensions and features after installation.

The installer then sets up PHP to be used in Windows and
the php.ini file, and configures certain web
servers to use PHP. The installer will currently configure IIS, Apache,
Xitami, and Sambar Server; if you are using a different web server you’ll
need to configure it manually.

Silent Install

The installer also supports a silent mode, which is
helpful for Systems Administrators to deploy PHP easily. To use silent

msiexec.exe /i php-VERSION-win32-install.msi /q

You can control the install directory by passing it as a
parameter to the install. For example, to install to e:php:

msiexec.exe /i php-VERSION-win32-install.msi /q INSTALLDIR=e:php

You can also use the same syntax to specify the Apache Configuration
Directory (APACHEDIR), the Sambar Server directory (SAMBARDIR), and the
Xitami Server directory (XITAMIDIR).

You can also specify what features to install. For
example, to install the mysqli extension and the CGI executable:

msiexec.exe /i php-VERSION-win32-install.msi /q ADDLOCAL=cgi,ext_php_mysqli

The current list of Features to install is as follows:

MainExecutable - php.exe executable
ScriptExecutable - php-win.exe executable
ext_php_* - the various extensions ( for example: ext_php_mysql for MySQL )
apache13 - Apache 1.3 module
apache20 - Apache 2.0 module
apache22 - Apache 2,2 module
apacheCGI - Apache CGI executable
iis4ISAPI - IIS ISAPI module
iis4CGI - IIS CGI executable
NSAPI - Sun/iPlanet/Netscape server module
Xitami - Xitami CGI executable
Sambar - Sambar Server ISAPI module
CGI - php-cgi.exe executable
PEAR - PEAR installer
Manual - PHP Manual in CHM Format

For more information on installing MSI installers from the
command line, visit


Upgrading PHP with the Install

To upgrade, run the installer either graphically or from
the command line as normal. The installer will read your current install
options, remove your old installation, and reinstall PHP with the same
options as before. It is recommended that you use this method of keeping
PHP updated instead of manually replacing the files in the installation


Installation of PECL extensions

Table of Contents

  • Downloading PECL extensions
  • PECL for Windows users
  • Compiling shared PECL extensions with the pecl command
  • Compiling shared PECL extensions with phpize
  • Compiling PECL extensions statically into PHP

Introduction to PECL Installations

is a repository of PHP extensions that are made available to you
via the » PEAR
packaging system. This section of the manual is intended to demonstrate how
to obtain and install PECL extensions.

These instructions assume /your/phpsrcdir/ is the
path to the PHP source distribution, and that extname is the name of
the PECL extension. Adjust accordingly. These instructions also assume a
familiarity with the

» pear command
. The information in the PEAR manual for the pear
command also applies to the pecl command.

To be useful, a shared extension must be built,
installed, and loaded. The methods described below provide you with various
instructions on how to build and install the extensions, but they do not
automatically load them. Extensions can be loaded by adding an

directive. To this php.ini file,
or through the use of the dl() function.

When building PHP modules, it’s important to have
known-good versions of the required tools (autoconf, automake, libtool,
etc.) See the
» Anonymous CVS Instructions
for details on the required tools, and
required versions.


Runtime Configuration

Table of Contents

  • How to change configuration settings

The configuration file

The configuration file (php.ini)
is read when PHP starts up. For the server module versions of PHP, this
happens only once when the web server is started. For the
CGI and
CLI version,
it happens on every invocation.

php.ini is searched in these
locations (in order):

  • SAPI module specific location (PHPIniDir directive
    in Apache 2, -c command line option in CGI and CLI, php_ini
    parameter in NSAPI, PHP_INI_PATH environment variable in THTTPD)

  • The PHPRC environment variable.
    Before PHP 5.2.0 this was checked after the registry key mentioned below.

  • As of PHP 5.2.0, the following registry locations are
    searched in order: HKEY_LOCAL_MACHINESOFTWAREPHPx.y.zIniFilePath,
    , where x, y and z mean
    the PHP major, minor and release versions.

    (Windows Registry location)

  • Current working directory (except CLI)

  • The web server’s directory (for SAPI modules), or
    directory of PHP (otherwise in Windows)

  • Windows directory (C:windows
    or C:winnt) (for Windows), or –with-config-file-path
    compile time option


If php-SAPI.ini exists (where
SAPI is used SAPI, so the filename is e.g. php-cli.ini
or php-apache.ini), it’s used instead of
php.ini. SAPI name can be determined by

Note: The Apache web server changes the directory
to root at startup causing PHP to attempt to read
from the root filesystem if it exists.

The php.ini directives handled
by extensions are documented respectively on the pages of the extensions
themselves. The list of the core directives is available in the appendix.
Probably not all PHP directives are documented in the manual though. For a
complete list of directives available in your PHP version, please read your
well commented php.ini file. Alternatively, you
may find the

» the latest php.ini
from CVS helpful too.

Example #1 php.ini example

; any text on a line after an unquoted semicolon (;) is ignored
[php] ; section markers (text within square brackets) are also ignored
; Boolean values can be set to either:
;    true, on, yes
; or false, off, no, none
register_globals = off
track_errors = yes
; you can enclose strings in double-quotes
include_path = ".:/usr/local/lib/php"
; backslashes are treated the same as any other character
include_path = ".;c:phplib"

Since PHP 5.1.0, it is possible to refer to existing .ini
variables from within .ini files. Example: open_basedir = ${open_basedir}