Newer Older

3 4
Installing PHP

6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
     * General Installation Considerations
     * Installation on Unix systems
          + Apache 1.3.x on Unix systems
          + Apache 2.x on Unix systems
          + Lighttpd 1.4 on Unix systems
          + 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
     * Installation on Mac OS X
          + Using Packages
          + Using the bundled PHP
          + Compiling PHP on Mac OS X
     * Installation of PECL extensions
          + Introduction to PECL Installations
          + Downloading PECL extensions
          + Installing a PHP extension on Windows
          + Compiling shared PECL extensions with the pecl command
          + Compiling shared PECL extensions with phpize
          + php-config
28 29 30 31 32 33 34 35 36 37 38 39
          + Compiling PECL extensions statically into PHP
     * Problems?
          + Read the FAQ
          + Other problems
          + Bug reports
     * Runtime Configuration
          + The configuration file
          + .user.ini files
          + Where a configuration setting may be set
          + How to change configuration settings
     * Installation

42 43 44


   These installation instructions were generated from the HTML version of
   the  PHP  Manual  so  formatting and linking have been altered. See the
   online and updated version at:

General Installation Considerations

52 53
   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 PHP, as
   described in the What can PHP do? section:
     * Websites and web applications (server-side scripting)
     * Command line scripting
     * Desktop (GUI) applications

59 60 61 62 63 64
   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
65 66
   the server you rent, and see the results in your browser.

67 68 69
   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
71 72 73 74
   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
79 80 81
   text  files  depending  on some arguments you pass to them), you always
   need  the  command  line  executable.  For  more  information, read the
   section  about writing command line PHP applications. In this case, you
   need no server and no browser.

84 85 86
   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
88 89
   site  dedicated  to  this  extension.  PHP-GTK  is  not included in the
   official PHP distribution.

   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
94 95
   following sections.

96 97 98
   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.

Installation on Unix systems

104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
Table of Contents

     * Apache 1.3.x on Unix systems
     * Apache 2.x on Unix systems
     * Lighttpd 1.4 on Unix systems
     * 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
119 120

121 122 123
   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
124 125
   as well.

126 127 128
   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
130 131
   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
133 134 135
   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.
137 138 139 140 141

   Prerequisite knowledge and software for compiling:
     * Basic Unix skills (being able to operate "make" and a C compiler)
     * An ANSI C compiler
     * A web server
142 143
     * Any module specific components (such as GD, PDF libs, etc.)

   When  building  directly from Git sources or after custom modifications
   you might also need:
     * autoconf: 2.13+ (for PHP < 5.4.0), 2.59+ (for PHP >= 5.4.0)
147 148 149 150 151 152 153 154 155 156 157 158
     * automake: 1.4+
     * libtool: 1.4.x+ (except 1.4.2)
     * re2c: Version 0.13.4 or newer
     * flex: Version 2.5.4 (for PHP <= 5.2)
     * bison: Version 1.28 (preferred), 1.35, or 1.75

   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
159 160

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

Apache 1.3.x on Unix systems

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

172 173 174 175 176
   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
177 178
   your files.

179 180
   Example #1 Installation Instructions (Apache Shared Module Version) for
181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211
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:

212 213
      cp php.ini-development /usr/local/lib/php.ini

214 215 216 217 218
    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-production, be certain to read the list
219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250
    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.

      LoadModule php5_module libexec/

15. And in the AddModule section of httpd.conf, somewhere under the
    ClearModuleList, add this:

      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
253 254 255 256 257
1.  gunzip -c apache_1.3.x.tar.gz | tar xf -
2.  cd apache_1.3.x
3.  ./configure
4.  cd ..

258 259
5.  gunzip -c php-5.x.y.tar.gz | tar xf -
6.  cd php-5.x.y
260 261 262 263 264 265
7.  ./configure --with-mysql --with-apache=../apache_1.3.x
8.  make
9.  make install

10. cd ../apache_1.3.x

266 267
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
268 269 270
    stage. It isn't supposed to. It will be created.)

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

13. cd ../php-5.x.y
14. cp php.ini-development /usr/local/lib/php.ini
277 278 279 280 281

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

282 283 284 285
   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
286 287
   applications on your systems.

   Example #3 Example commands for restarting Apache
289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304
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

305 306
   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
307 308 309
   you in finding your server control programs.

   Different examples of compiling PHP for apache are as follows:
./configure --with-apxs --with-pgsql

312 313 314
   This will create a 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 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
321 322
   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
327 328 329 330 331 332
   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.  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 dl().

340 341 342 343 344 345
   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.

347 348 349 350

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

User nobody
Group "#-1"

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

359 360 361 362 363 364 365

     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.

Apache 2.x on Unix systems

   This  section  contains notes and hints specific to Apache 2.x installs
371 372 373
   of PHP on Unix systems.

374 375 376 377 378
   We  do  not recommend using a threaded MPM in production with Apache 2.
   Use  the prefork MPM, which is the default MPM with Apache 2.0 and 2.2.
   For  information  on  why,  read the related FAQ entry on using Apache2
   with a threaded MPM

   The   » Apache  Documentation  is  the  most  authoritative  source  of
380 381 382
   information   on   the   Apache  2.x  server.  More  information  about
   installation options for Apache may be found there.

383 384
   The  most  recent  version  of  Apache HTTP Server may be obtained from
   » Apache  download  site,  and  a  fitting  PHP  version from the above
385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501
   mentioned  places.  This  quick  guide  covers  only  the basics to get
   started with Apache 2.x and PHP. For more information read the » Apache
   Documentation.  The  version  numbers have been omitted here, to ensure
   the  instructions are not incorrect. In the examples below, 'NN' should
   be replaced with the specific version of Apache being used.

   There  are  currently two versions of Apache 2.x - there's 2.0 and 2.2.
   While  there  are various reasons for choosing each, 2.2 is the current
   latest  version,  and  the  one  that is recommended, if that option is
   available  to  you. However, the instructions here will work for either
   2.0 or 2.2.
    1. Obtain  the  Apache HTTP server from the location listed above, and
       unpack it:
gzip -d httpd-2_x_NN.tar.gz
tar -xf httpd-2_x_NN.tar

    2. Likewise, obtain and unpack the PHP source:
gunzip php-NN.tar.gz
tar -xf php-NN.tar

    3. Build  and install Apache. Consult the Apache install documentation
       for more details on building Apache.
cd httpd-2_x_NN
./configure --enable-so
make install

    4. Now  you  have  Apache  2.x.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

    5. Now,  configure and build PHP. This is where you customize PHP with
       various  options,  like  which  extensions  will  be  enabled.  Run
       ./configure  --help for a list of available options. In our example
       we'll do a simple configure with Apache 2 and MySQL support.
       If  you  built  Apache  from  source, as described above, the below
       example  will match your path for apxs, but if you installed Apache
       some other way, you'll need to adjust the path to apxs accordingly.
       Note that some distros may rename apxs to apxs2.
cd ../php-NN
./configure --with-apxs2=/usr/local/apache2/bin/apxs --with-mysql
make install

       If  you decide to change your configure options after installation,
       you'll  need to re-run the configure, make, and make install 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
    6. Setup your php.ini
cp php.ini-development /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 5.
       If  you  instead  choose php.ini-production, be certain to read the
       list of changes within, as they affect how PHP behaves.
    7. 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.
LoadModule php5_module modules/
    8. Tell  Apache to parse certain extensions as PHP. For example, let's
       have  Apache  parse  .php  files  as PHP. Instead of only using the
       Apache  AddType  directive,  we want to avoid potentially dangerous
       uploads  and  created  files  such  as  exploit.php.jpg  from being
       executed   as   PHP.   Using  this  example,  you  could  have  any
       extension(s)  parse as PHP by simply adding them. We'll add .php to
<FilesMatch \.php$>
    SetHandler application/x-httpd-php
       Or,  if we wanted to allow .php, .php2, .php3, .php4, .php5, .php6,
       and  .phtml files to be executed as PHP, but nothing else, we'd use
<FilesMatch "\.ph(p[2-6]?|tml)$">
    SetHandler application/x-httpd-php
       And  to  allow  .phps files to be handled by the php source filter,
       and displayed as syntax-highlighted source code, use this:
<FilesMatch "\.phps$">
    SetHandler application/x-httpd-php-source
       mod_rewrite  may  be  used  To  allow any arbitrary .php file to be
       displayed  as  syntax-highlighted  source  code,  without having to
       rename or copy it to a .phps file:
RewriteEngine On
RewriteRule (.*\.php)s$ $1 [H=application/x-httpd-php-source]
       The  php source filter should not be enabled on production systems,
       where it may expose confidential or otherwise sensitive information
       embedded in source code.
    9. Use your normal procedure for starting the Apache server, e.g.:
/usr/local/apache2/bin/apachectl start

service httpd restart

   Following  the  steps  above you will have a running Apache2 web server
   with  support  for  PHP as a SAPI module. Of course there are many more
   configuration  options  available  Apache and PHP. For more information
   type ./configure --help in the corresponding source tree.

   Apache  may  be built multithreaded by selecting the worker MPM, rather
   than  the  standard  prefork MPM, when Apache is built. This is done by
   adding  the  following option to the argument passed to ./configure, in
   step 3 above:

   This  should  not be undertaken without being aware of the consequences
   of  this  decision,  and  having  at  least a fair understanding of the
   implications.   The   Apache   documentation   regarding  » MPM-Modules
503 504 505 506 507 508 509 510 511 512 513 514 515 516 517
   discusses MPMs in a great deal more detail.


     The Apache MultiViews FAQ discusses using multiviews with PHP.


     To  build  a multithreaded version of Apache, the target system must
     support  threads.  In  this  case,  PHP  should  also  be built with
     experimental Zend Thread Safety (ZTS). Under this configuration, not
     all  extensions will be available. The recommended setup is to build
     Apache with the default prefork MPM-Module.

Lighttpd 1.4 on Unix systems

521 522
   This section contains notes and hints specific to Lighttpd 1.4 installs
   of PHP on Unix systems.

   Please  use  the  » Lighttpd  trac  to  learn  how  to install Lighttpd
525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616
   properly before continuing.

   Fastcgi  is  the preferred SAPI to connect PHP and Lighttpd. Fastcgi is
   automagically  enabled  in  php-cgi  in PHP 5.3, but for older versions
   configure  PHP  with  --enable-fastcgi. To confirm that PHP has fastcgi
   enabled,  php  -v should contain PHP 5.2.5 (cgi-fcgi) Before PHP 5.2.3,
   fastcgi was enabled on the php binary (there was no php-cgi).

Letting Lighttpd spawn php processes

   To  configure  Lighttpd  to connect to php and spawn fastcgi processes,
   edit  lighttpd.conf.  Sockets  are  preferred  to  connect  to  fastcgi
   processes on the local system.

   Example #1 Partial lighttpd.conf
server.modules += ( "mod_fastcgi" )

fastcgi.server = ( ".php" =>
    "socket" => "/tmp/php.socket",
    "bin-path" => "/usr/local/bin/php-cgi",
    "bin-environment" => (
      "PHP_FCGI_CHILDREN" => "16",
      "PHP_FCGI_MAX_REQUESTS" => "10000"
    "min-procs" => 1,
    "max-procs" => 1,
    "idle-timeout" => 20

   The  bin-path  directive  allows  lighttpd  to  spawn fastcgi processes
   dynamically. PHP will spawn children according to the PHP_FCGI_CHILDREN
   environment   variable.   The   "bin-environment"  directive  sets  the
   environment  for  the  spawned processes. PHP will kill a child process
   after  the  number  of  requests  specified by PHP_FCGI_MAX_REQUESTS is
   reached. The directives "min-procs" and "max-procs" should generally be
   avoided  with  PHP. PHP manages its own children and opcode caches like
   APC  will  only  share among children managed by PHP. If "min-procs" is
   set  to  something  greater  than 1, the total number of php responders
   will  be  multiplied PHP_FCGI_CHILDREN (2 min-procs * 16 children gives
   32 responders).

Spawning with spawn-fcgi

   Lighttpd  provides  a  program called spawn-fcgi to ease the process of
   spawning fastcgi processes easier.

Spawning php-cgi

   It  is  possible to spawn processes without spawn-fcgi, though a bit of
   heavy-lifting  is  required.  Setting the PHP_FCGI_CHILDREN environment
   var  controls  how  many  children  PHP  will  spawn to handle incoming
   requests.  Setting  PHP_FCGI_MAX_REQUESTS  will  determine how long (in
   requests)  each  child  will  live. Here's a simple bash script to help
   spawn php responders.

   Example #2 Spawning FastCGI Responders

# Location of the php-cgi binary

# PID File location

# Binding to an address
# Binding to a domain socket



echo $! > "$PHP_PID"

Connecting to remote FCGI instances

   Fastcgi  instances  can be spawned on multiple remote machines in order
   to scale applications.

   Example #3 Connecting to remote php-fastcgi instances
fastcgi.server = ( ".php" =>
   (( "host" => "", "port" => 1030 ),
    ( "host" => "", "port" => 1030 ))
618 619 620

Sun, iPlanet and Netscape servers on Sun Solaris

   This  section  contains notes and hints specific to Sun Java System Web
622 623
   Server, Sun ONE Web Server, iPlanet and Netscape server installs of PHP
   on Sun Solaris.

625 626 627
   From  PHP  4.3.3  on  you  can use PHP scripts with the NSAPI module to
   generate   custom   directory  listings  and  error  pages.  Additional
   functions  for  Apache compatibility are also available. For support in
   current web servers read the note about subrequests.

   You  can  find  more  information about setting up PHP for the Netscape
631 632
   Enterprise Server (NES) here:

634 635 636
   To  build  PHP  with  Sun JSWS/Sun ONE WS/iPlanet/Netscape web servers,
   enter  the  proper install directory for the --with-nsapi=[DIR] option.
   The  default directory is usually /opt/netscape/suitespot/. Please also
637 638
   read /php-xxx-version/sapi/nsapi/nsapi-readme.txt.

    1. Install  the following packages from »
640 641 642 643 644 645 646 647 648 649 650 651 652 653
       or another download site:
          + autoconf-2.13
          + automake-1.4
          + bison-1_25-sol26-sparc-local
          + flex-2_5_4a-sol26-sparc-local
          + gcc-2_95_2-sol26-sparc-local
          + gzip-1.2.4-sol26-sparc-local
          + m4-1_4-sol26-sparc-local
          + make-3_76_1-sol26-sparc-local
          + mysql-3.23.24-beta (if you want mysql support)
          + perl-5_005_03-sol26-sparc-local
          + tar-1.13 (GNU tar)
    2. Make    sure    your   path   includes   the   proper   directories
       PATH=.:/usr/local/bin:/usr/sbin:/usr/bin:/usr/ccs/bin  and  make it
       available to your system export PATH.
    3. gunzip  php-x.x.x.tar.gz  (if  you have a .gz dist, otherwise go to
656 657 658
    4. tar xvf php-x.x.x.tar
    5. Change to your extracted PHP directory: cd ../php-x.x.x
659 660 661
    6. For the following step, make sure /opt/netscape/suitespot/ is where
       your netscape server is installed. Otherwise, change to the correct
       path and run:
662 663 664 665 666
./configure --with-mysql=/usr/local/mysql \
--with-nsapi=/opt/netscape/suitespot/ \
    7. Run make followed by make install.

   After  performing  the  base install and reading the appropriate readme
668 669
   file, you may need to perform some additional configuration steps.

Configuration Instructions for Sun/iPlanet/Netscape

672 673 674 675 676 677 678
   Firstly  you  may  need  to  add  some  paths  to  the  LD_LIBRARY_PATH
   environment  for  the server to find all the shared libs. This can best
   done in the start script for your web server. The start script is often
   located  in:  /path/to/server/https-servername/start. You may also need
   to    edit    the    configuration   files   that   are   located   in:
    1. Add  the  following  line  to  mime.types  (you  can do that by the
679 680 681
       administration server):
type=magnus-internal/x-httpd-php exts=php

    2. Edit  magnus.conf  (for servers >= 6) or obj.conf (for servers < 6)
       and add the following, shlib will vary depending on your system, it
       will  be something like /opt/netscape/suitespot/bin/ You
685 686 687 688 689
       should place the following lines after mime types init.
Init fn="load-modules" funcs="php4_init,php4_execute,php4_auth_trans" shlib="/op
Init fn="php4_init" LateInit="yes" errorString="Failed to initialize PHP!" [php_

       (PHP  >=  4.3.3)  The php_ini parameter is optional but with it you
       can place your php.ini in your web server config directory.
    3. Configure  the  default  object  in  obj.conf  (for  virtual server
694 695 696 697 698
       classes [version 6.0+] in their vserver.obj.conf):
<Object name="default">
699 700 701 702
.#NOTE this next line should happen after all 'ObjectType' and before all 'AddLo
g' lines
Service fn="php4_execute" type="magnus-internal/x-httpd-php" [inikey=value inike
y=value ...]
703 704 705 706

       (PHP  >=  4.3.3)  As additional parameters you can add some special
       php.ini-values, for example you can set a
709 710 711
       docroot="/path/to/docroot"  specific to the context php4_execute is
       called.   For  boolean  ini-keys  please  use  0/1  as  value,  not
       "On","Off",...    (this    will    not    work   correctly),   e.g.
       zlib.output_compression=1 instead of zlib.output_compression="On"
    4. This  is only needed if you want to configure a directory that only
714 715 716 717 718 719
       consists of PHP scripts (same like a cgi-bin directory):
<Object name="x-httpd-php">
ObjectType fn="force-type" type="magnus-internal/x-httpd-php"
Service fn=php4_execute [inikey=value inikey=value ...]

720 721 722
       After  that  you  can  configure  a directory in the Administration
       server  and  assign  it the style x-httpd-php. All files in it will
       get  executed  as  PHP.  This is nice to hide PHP usage by renaming
       files to .html.
    5. Setup of authentication: PHP authentication cannot be used with any
725 726
       other  authentication.  ALL  AUTHENTICATION  IS  PASSED TO YOUR PHP
       SCRIPT.  To configure PHP Authentication for the entire server, add
727 728 729 730 731 732 733 734
       the following line to your default object:
<Object name="default">
AuthTrans fn=php4_auth_trans

    6. To use PHP Authentication on a single directory, add the following:
736 737 738 739
<Object ppath="d:\path\to\authenticated\dir\*">
AuthTrans fn=php4_auth_trans

740 741 742 743 744

     The  stacksize that PHP uses depends on the configuration of the web
     server.  If  you  get  crashes  with  very  large PHP scripts, it is
     recommended  to  raise  it  with  the  Admin  Server (in the section
745 746 747 748

CGI environment and recommended modifications in php.ini

749 750 751 752 753 754 755
   Important  when  writing  PHP scripts is the fact that Sun JSWS/Sun ONE
   WS/iPlanet/Netscape  is a multithreaded web server. Because of that all
   requests  are  running  in the same process space (the space of the web
   server  itself) and this space has only one environment. If you want to
   get  CGI variables like PATH_INFO, HTTP_HOST etc. it is not the correct
   way  to  try  this  in  the  old PHP way with getenv() or a similar way
   (register  globals  to  environment,  $_ENV).  You  would  only get the
   environment of the running web server without any valid CGI variables!


760 761 762 763 764 765 766 767 768
     Why are there (invalid) CGI variables in the environment?

     Answer:  This is because you started the web server process from the
     admin  server  which  runs the startup script of the web server, you
     wanted  to  start, as a CGI script (a CGI script inside of the admin
     server!).  This is why the environment of the started web server has
     some  CGI environment variables in it. You can test this by starting
     the  web  server not from the administration server. Use the command
     line  as root user and start it manually - you will see there are no
769 770
     CGI-like environment variables.

771 772 773 774
   Simply  change your scripts to get CGI variables in the correct way for
   PHP  4.x  by  using the superglobal $_SERVER. If you have older scripts
   which  use  $HTTP_HOST,  etc.,  you  should turn on register_globals in
   php.ini  and  change the variable order too (important: remove "E" from
775 776 777 778 779 780
   it, because you do not need the environment here):
variables_order = "GPCS"
register_globals = On

Special use for error pages or self-made directory listings (PHP >= 4.3.3)

781 782
   You  can  use  PHP  to  generate the error pages for "404 Not Found" or
   similar.  Add  the  following  line to the object in obj.conf for every
   error page you want to overwrite:
784 785
Error fn="php4_execute" code=XXX script="/path/to/script.php" [inikey=value inik

787 788 789
   where  XXX  is  the  HTTP  error  code.  Please  delete any other Error
   directives  which  could  interfere  with yours. If you want to place a
   page  for  all  errors  that could exist, leave the code parameter out.
790 791
   Your script can get the HTTP status code with $_SERVER['ERROR_TYPE'].

792 793
   Another  possibility  is to generate self-made directory listings. Just
   create  a PHP script which displays a directory listing and replace the
794 795 796 797
   corresponding default Service line for type="magnus-internal/directory"
   in obj.conf with the following:
Service fn="php4_execute" type="magnus-internal/directory" script="/path/to/scri
pt.php" [inikey=value inikey=value...]

799 800
   For  both  error  and  directory  listing  pages  the  original URI and
   translated   URI   are   in  the  variables  $_SERVER['PATH_INFO']  and
801 802 803 804

Note about nsapi_virtual() and subrequests (PHP >= 4.3.3)

805 806
   The  NSAPI  module  now  supports  the nsapi_virtual() function (alias:
   virtual())  to make subrequests on the web server and insert the result
   in the web page. This function uses some undocumented features from the
808 809
   NSAPI  library.  On  Unix the module automatically looks for the needed
   functions  and  uses  them  if  available.  If  not, nsapi_virtual() is
810 811

812 813 814 815

     But be warned: Support for nsapi_virtual() is EXPERIMENTAL!!!

CGI and command line setups

820 821 822 823
   By  default,  PHP  is built as both a CLI and CGI program, which can be
   used  for  CGI processing. If you are running a web server that PHP has
   module  support  for,  you  should  generally  go for that solution for
   performance  reasons.  However,  the  CGI  version enables users to run
824 825 826
   different PHP-enabled pages under different user-ids.

827 828 829
   A   server   deployed   in   CGI  mode  is  open  to  several  possible
   vulnerabilities.  Please  read our CGI security section to learn how to
   defend yourself from such attacks.
830 831 832


   If  you  have  built  PHP  as a CGI program, you may test your build by
   typing make test. It is always a good idea to test your build. This way
   you  may  catch  a  problem  with PHP on your platform early instead of
836 837 838 839
   having to struggle with it later.

Using Variables

   Some  server  supplied  environment  variables  are  not defined in the
   current  » CGI/1.1  specification.  Only  the  following  variables are
842 843 844 845 846 847 848
   defined     there:     AUTH_TYPE,     CONTENT_LENGTH,     CONTENT_TYPE,
   SERVER_SOFTWARE.   Everything   else   should  be  treated  as  'vendor
850 851 852

HP-UX specific installation notes

   This  section  contains  notes  and hints specific to installing PHP on
   HP-UX systems.

   There  are two main options for installing PHP on HP-UX systems. Either
   compile it, or install a pre-compiled binary.

859 860
   Official      pre-compiled      packages      are     located     here:

862 863
   Until  this  manual  section  is  rewritten,  the  documentation  about
   compiling  PHP  (and  related  extensions)  on  HP-UX  systems has been
864 865
   removed.  For  now,  consider  reading the following external resource:
   » Building Apache and PHP on HP-UX 11.11
868 869 870

OpenBSD installation notes

871 872
   This  section  contains  notes  and hints specific to installing PHP on
   » OpenBSD 3.6.
873 874 875

Using Binary Packages

876 877 878 879
   Using  binary packages to install PHP on OpenBSD is the recommended and
   simplest  method.  The core package has been separated from the various
   modules,  and  each can be installed and removed independently from the
   others.  The  files  you need can be found on your OpenBSD CD or on the
880 881
   FTP site.

882 883 884 885
   The  main  package  you  need  to install is php4-core-4.3.8.tgz, which
   contains  the  basic engine (plus gettext and iconv). Next, take a look
   at    the    module   packages,   such   as   php4-mysql-4.3.8.tgz   or
   php4-imap-4.3.8.tgz.  You need to use the phpxs command to activate and
886 887
   deactivate these modules in your php.ini.

   Example #1 OpenBSD Package Install Example
889 890
# pkg_add php4-core-4.3.8.tgz
# /usr/local/sbin/phpxs -s
# cp /usr/local/share/doc/php4/php.ini-recommended /var/www/conf/php.ini
892 893 894 895 896 897 898 899 900 901 902 903
  (add in mysql)
# pkg_add php4-mysql-4.3.8.tgz
# /usr/local/sbin/phpxs -a mysql
  (add in imap)
# pkg_add php4-imap-4.3.8.tgz
# /usr/local/sbin/phpxs -a imap
  (remove mysql as a test)
# pkg_delete php4-mysql-4.3.8
# /usr/local/sbin/phpxs -r mysql
  (install the PEAR libraries)
# pkg_add php4-pear-4.3.8.tgz

   Read  the  » packages(7)  manual page for more information about binary
905 906 907 908
   packages on OpenBSD.

Using Ports

   You  can  also  compile  up  PHP  from  source  using the » ports tree.
910 911 912 913 914
   However,  this is only recommended for users familiar with OpenBSD. The
   PHP  4 port is split into two sub-directories: core and extensions. The
   extensions  directory  generates  sub-packages for all of the supported
   PHP  modules.  If  you  find  you  do  not want to create some of these
   modules,  use  the  no_* FLAVOR. For example, to skip building the imap
915 916 917 918
   module, set the FLAVOR to no_imap.

Common Problems

919 920 921 922 923 924 925 926 927 928 929
     * The default install of Apache runs inside a » chroot(2) jail, which
       will  restrict  PHP  scripts to accessing files under /var/www. You
       will  therefore  need  to  create  a /var/www/tmp directory for PHP
       session  files to be stored, or use an alternative session backend.
       In  addition, database sockets need to be placed inside the jail or
       listen  on  the  localhost interface. If you use network functions,
       some  files  from  /etc  such as /etc/resolv.conf and /etc/services
       will  need  to be moved into /var/www/etc. The OpenBSD PEAR package
       automatically  installs  into the correct chroot directories, so no
       special  modification  is  needed  there.  More  information on the
       OpenBSD Apache is available in the » OpenBSD FAQ.
     * The  OpenBSD 3.6 package for the » gd extension requires XFree86 to
931 932 933
       be  installed.  If you do not wish to use some of the font features
       that  require  X11,  install  the  php4-gd-4.3.8-no_x11.tgz package
934 935 936

Older Releases

937 938 939
   Older  releases  of  OpenBSD  used  the  FLAVORS system to compile up a
   statically  linked  PHP.  Since  it is hard to generate binary packages
   using  this  method,  it  is  now deprecated. You can still use the old
   stable ports trees if you wish, but they are unsupported by the OpenBSD
   team.  If  you have any comments about this, the current maintainer for
942 943
   the port is Anil Madhavapeddy (avsm at openbsd dot org).
945 946 947

Solaris specific installation tips

   This  section  contains  notes  and hints specific to installing PHP on
949 950 951 952
   Solaris systems.

Required software

953 954
   Solaris  installs  often lack C compilers and their related tools. Read
   this  FAQ  for  information on why using GNU versions for some of these
955 956 957 958 959 960 961 962
   tools is necessary.

   For unpacking the PHP distribution you need
     * tar
     * gzip or
     * bzip2

   For compiling PHP you need
963 964
     * gcc (recommended, other C compilers may work)
     * make
965 966 967 968 969 970
     * GNU sed

   For building extra extensions or hacking the code of PHP you might also
     * flex (up to PHP 5.2)
     * re2c
971 972 973 974 975
     * bison
     * m4
     * autoconf
     * automake

976 977
   In  addition,  you  will  need  to  install  (and possibly compile) any
   additional  software  specific to your configuration, such as Oracle or
978 979 980 981

Using Packages

   You can simplify the Solaris install process by using pkgadd to install
983 984 985
   most  of  your  needed components. The Image Packaging System (IPS) for
   Solaris  11  Express  also contains most of the required components for
   installation using the pkg command.

989 990
Debian GNU/Linux installation notes

991 992
   This  section  contains  notes  and hints specific to installing PHP on
   » Debian GNU/Linux.

995 996 997
   Unofficial  builds  from third-parties are not supported here. Any bugs
   should  be  reported  to  the Debian team unless they can be reproduced
   using the latest builds from our » download area.

999 1000 1001 1002
   While  the  instructions  for  building  PHP on Unix apply to Debian as
   well, this manual page contains specific information for other options,
   such as using either the apt-get or aptitude commands. This manual page
   uses these two commands interchangeably.

Using APT

1006 1007
   First,   note   that   other  related  packages  may  be  desired  like
   libapache2-mod-php5 to integrate with Apache 2, and php-pear for PEAR.

1009 1010 1011
   Second,  before  installing  a package, it's wise to ensure the package
   list  is  up  to  date.  Typically, this is done by running the command
   apt-get update.

1013 1014
   Example #1 Debian Install Example with Apache 2
# apt-get install php5-common libapache2-mod-php5 php5-cli

1016 1017 1018
   APT will automatically install the PHP 5 module for Apache 2 and all of
   its  dependencies,  and then activate it. Apache should be restarted in
   order for the changes take place. For example:

1020 1021 1022
   Example #2 Stopping and starting Apache once PHP is installed
# /etc/init.d/apache2 stop
# /etc/init.d/apache2 start

Better control of configuration

1026 1027 1028
   In  the  last  section,  PHP was installed with only core modules. It's
   very  likely  that  additional  modules will be desired, such as MySQL,
   cURL, GD, etc. These may also be installed via the apt-get command.

1030 1031 1032 1033
   Example #3 Methods for listing additional PHP 5 packages
# apt-cache search php5
# aptitude search php5
# aptitude search php5 |grep -i mysql

1035 1036 1037 1038 1039
   The examples will show a lot of packages including several PHP specific
   ones  like  php5-cgi, php5-cli and php5-dev. Determine which are needed
   and  install  them  like any other with either apt-get or aptitude. And
   because  Debian  performs  dependency checks, it'll prompt for those so
   for example to install MySQL and cURL:

1041 1042
   Example #4 Install PHP with MySQL, cURL
# apt-get install php5-mysql php5-curl

1044 1045 1046 1047 1048
   APT  will  automatically  add  the  appropriate  lines to the different
   php.ini      related      files     like     /etc/php5/apache2/php.ini,
   /etc/php5/conf.d/pdo.ini,  etc. and depending on the extension will add
   entries similar to However, restarting the web server
   (like Apache) is required before these changes take affect.
1049 1050 1051

Common Problems

1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065
     * If  the  PHP  scripts are not parsing via the web server, then it's
       likely  that  PHP  was  not added to the web server's configuration
       file,  which on Debian may be /etc/apache2/apache2.conf or similar.
       See the Debian manual for further details.
     * If  an  extension  was  seemingly  installed  yet the functions are
       undefined,  be  sure  that the appropriate ini file is being loaded
       and/or the web server was restarted after installation.
     * There are two basic commands for installing packages on Debian (and
       other  linux  variants):  apt-get and aptitude. However, explaining
       the subtle differences between these commands goes beyond the scope
       of this manual.

Installation on Mac OS X

Table of Contents

1071 1072 1073
     * Using Packages
     * Using the bundled PHP
     * Compiling PHP on Mac OS X

   This section contains notes and hints specific to installing PHP on Mac
1076 1077
   OS  X.  PHP  is bundled with Macs, and compiling is similar to the Unix
   installation guide.
1079 1080 1081

Using Packages

1082 1083
   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
1088 1089
   packaged version of PHP with the features you need.

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

1093 1094 1095 1096 1097
     * MacPorts: »
     * Entropy: »
     * Fink: »
     * Homebrew: »
1098 1099 1100 1101 1102

Using the bundled PHP

   PHP has come standard with Macs since OS X version 10.0.0. Enabling PHP
1103 1104
   with  the  default  web server requires uncommenting a few lines in the
   Apache  configuration  file  httpd.conf  whereas the CGI and/or CLI are
1105 1106
   enabled by default (easily accessible via the Terminal program).

1107 1108 1109 1110 1111 1112
   Enabling  PHP using the instructions below is meant for quickly setting
   up  a  local development environment. It's highly recommended to always
   upgrade  PHP  to  the  newest  version.  Like most live software, newer
   versions  are  created to fix bugs and add features and PHP being is no
   different.  See the appropriate MAC OS X installation documentation for
   further  details.  The  following  instructions  are  geared  towards a
1113 1114 1115
   beginner with details provided for getting a default setup to work. All
   users are encouraged to compile, or install a new packaged version.

1116 1117 1118
   The  standard  installation  type  is  using  mod_php, and enabling the
   bundled  mod_php on Mac OS X for the Apache web server (the default web
   server,  that  is  accessible  via  System  Preferences)  involves  the
1119 1120
   following steps:

1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131
    1. Locate  and  open  the  Apache  configuration file. By default, the
       location   is  as  follows:  /private/etc/apache2/httpd.conf  Using
       Finder  or  Spotlight  to  find this file may prove difficult as by
       default it's private and owned by the root user.

     Note:  One  way to open this is by using a Unix based text editor in
     the  Terminal,  for  example  nano, and because the file is owned by
     root  we'll use the sudo command to open it (as root) so for example
     type  the  following  into  the Terminal Application (after, it will
     prompt  for  a  password): sudo nano /private/etc/apache2/httpd.conf
     Noteworthy  nano  commands:  ^w  (search),  ^o (save), and ^x (exit)
1132 1133
     where ^ represents the Ctrl key.

1134 1135 1136 1137 1138 1139 1140
     Note:  Versions  of  Mac  OS X prior to 10.5 were bundled with older
     versions  of  PHP and Apache. As such, the Apache configuration file
     on legacy machines may be /etc/httpd/httpd.conf.
    2. With  a  text  editor, uncomment the lines (by removing the #) that
       look  similar  to  the  following  (these  two  lines are often not
       together, locate them both in the file):
# LoadModule php5_module libexec/httpd/

# AddModule mod_php5.c

       Notice  the  location/path.  When  building  PHP in the future, the
       above files should be replaced or commented out.
    3. Be  sure  the  desired extensions will parse as PHP (examples: .php
       .html and .inc)
1148 1149
       Due  to  the following statement already existing in httpd.conf (as
       of   Mac  Panther),  once  PHP  is  enabled  the  .php  files  will
       automatically parse as PHP.
<IfModule mod_php5.c>
1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162
    # If php is turned on, we respect .php and .phps files.
    AddType application/x-httpd-php .php
    AddType application/x-httpd-php-source .phps

    # Since most users will want index.php to work we
    # also automatically enable index.php
    <IfModule mod_dir.c>
        DirectoryIndex index.html index.php

1163 1164 1165 1166 1167 1168 1169
     Before  OS  X  10.5 (Leopard), PHP 4 was bundled instead of PHP 5 in
     which  case  the above instructions will differ slightly by changing
     5's to 4's.
    4. Be  sure  the  DirectoryIndex  loads the desired default index file
       This  is also set in httpd.conf. Typically index.php and index.html
       are  used. By default index.php is enabled because it's also in the
       PHP check shown above. Adjust accordingly.
1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182
    5. Set  the  php.ini  location  or  use  the default A typical default
       location  on  Mac  OS  X  is  /usr/local/php/php.ini  and a call to
       phpinfo()  will  reveal this information. If a php.ini is not used,
       PHP  will  use  all  default  values.  See  also the related FAQ on
       finding php.ini.
    6. Locate  or  set the DocumentRoot This is the root directory for all
       the  web  files.  Files  in  this directory are served from the web
       server so the PHP files will parse as PHP before outputting them to
       the browser. A typical default path is /Library/WebServer/Documents
       but  this  can be set to anything in httpd.conf. Alternatively, the
       default      DocumentRoot      for      individual     users     is
1183 1184 1185
    7. Create a phpinfo() file
       The phpinfo() function will display information about PHP. Consider
       creating a file in the DocumentRoot with the following PHP code:
1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198
       <?php phpinfo(); ?>
    8. Restart  Apache,  and  load  the PHP file created above To restart,
       either  execute  sudo apachectl graceful in the shell or stop/start
       the "Personal Web Server" option in the OS X System Preferences. By
       default,  loading  local files in the browser will have an URL like
       so: http://localhost/info.php Or using the DocumentRoot in the user
       directory  is  another  option  and  would  end  up  looking  like:

   The  CLI  (or  CGI  in  older  versions) is appropriately named php and
   likely  exists  as /usr/bin/php. Open up the terminal, read the command
   line  section  of  the  PHP manual, and execute php -v to check the PHP
   version  of  this PHP binary. A call to phpinfo() will also reveal this
1199 1200

Compiling PHP on Mac OS X

1205 1206 1207 1208
   Use the Unix installation guide to compile PHP on Mac OS X.

Installation of PECL extensions

Table of Contents

1214 1215 1216 1217 1218
     * Introduction to PECL Installations
     * Downloading PECL extensions
     * Installing a PHP extension on Windows
     * Compiling shared PECL extensions with the pecl command
     * Compiling shared PECL extensions with phpize
     * php-config
     * Compiling PECL extensions statically into PHP
1222 1223 1224

Introduction to PECL Installations

1225 1226
   » PECL 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.

1229 1230 1231 1232
   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.

1235 1236 1237 1238
   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 extension directive.
1239 1240
   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
1242 1243
   of  the  required  tools  (autoconf,  automake,  libtool, etc.) See the
   » Anonymous  Git  Instructions  for  details on the required tools, and
1244 1245
   required versions.
1247 1248 1249 1250

Downloading PECL extensions

   There are several options for downloading PECL extensions, such as:
1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261
     * The  pecl  install  extname  command  downloads the extensions code
       automatically,  so  in  this  case  there is no need for a separate
     * » The PECL web site contains information about
       the  different  extensions  that are offered by the PHP Development
       Team.  The  information available here includes: ChangeLog, release
       notes, requirements and other similar details.
     * pecl  download extname PECL extensions that have releases listed on
       the PECL web site are available for download and installation using
       the » pecl command. Specific revisions may also be specified.
     * SVN  Most  PECL extensions also reside in SVN. A web-based view may
       be  seen at » To download straight
1263 1264 1265 1266 1267 1268 1269 1270
       from SVN, the following sequence of commands may be used:
       $   svn  checkout
     * Windows  downloads  At  this  time the PHP project does not compile
       Windows binaries for PECL extensions. However, to compile PHP under
       Windows see the chapter titled building PHP for Windows.

Installing a PHP extension on Windows

1274 1275 1276
   On  Windows,  you have two ways to load a PHP extension: either compile
   it  into  PHP, or load the DLL. Loading a pre-compiled extension is the
   easiest and preferred way.

1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293
   To load an extension, you need to have it available as a ".dll" file on
   your  system.  All  the  extensions  are automatically and periodically
   compiled by the PHP Group (see next section for the download).

   To  compile an extension into PHP, please refer to building from source

   To  compile  a  standalone  extension (aka a DLL file), please refer to
   building  from  source  documentation.  If  the  DLL  file is available
   neither with your PHP distribution nor in PECL, you may have to compile
   it before you can start using the extension.

Where to find an extension?

   PHP   extensions   are  usually  called  "php_*.dll"  (where  the  star
   represents  the  name  of the extension) and they are located under the
   "PHP\ext" ("PHP\extensions" in PHP 4) folder.
1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329

   PHP   ships  with  the  extensions  most  useful  to  the  majority  of
   developers. They are called "core" extensions.

   However,  if you need functionality not provided by any core extension,
   you  may still be able to find one in PECL. The PHP Extension Community
   Library  (PECL)  is  a  repository  for  PHP  Extensions,  providing  a
   directory   of   all   known  extensions  and  hosting  facilities  for
   downloading and development of PHP extensions.

   If you have developed an extension for your own uses, you might want to
   think  about  hosting it on PECL so that others with the same needs can
   benefit from your time. A nice side effect is that you give them a good
   chance  to  give you feedback, (hopefully) thanks, bug reports and even
   fixes/patches.  Before  you  submit your extension for hosting on PECL,
   please read

Which extension to download?

   Many times, you will find several versions of each DLL:
     * Different  version  numbers  (at least the first two numbers should
     * Different thread safety settings
     * Different processor architecture (x86, x64, ...)
     * Different debugging settings
     * etc.

   You  should  keep in mind that your extension settings should match all
   the  settings  of  the  PHP executable you are using. The following PHP
   script will tell you all about your PHP settings:

   Example #1 phpinfo() call

1331 1332
   Or from the command line, run:
drive:\\path\to\php\executable\php.exe -i

Loading an extension

1336 1337 1338 1339 1340
   The  most  common  way to load a PHP extension is to include it in your
   php.ini  configuration  file.  Please  note  that  many  extensions are
   already  present  in  your php.ini and that you only need to remove the
   semicolon to activate them.

1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375

   However,  some  web  servers  are confusing because they do not use the
   php.ini  located  alongside your PHP executable. To find out where your
   actual php.ini resides, look for its path in phpinfo():
Configuration File (php.ini) Path  C:\WINDOWS

Loaded Configuration File   C:\Program Files\PHP\5.2\php.ini

   After activating an extension, save php.ini, restart the web server and
   check  phpinfo()  again.  The  new  extension  should  now have its own

Resolving problems

   If  the  extension  does not appear in phpinfo(), you should check your
   logs to learn where the problem comes from.

   If you are using PHP from the command line (CLI), the extension loading
   error can be read directly on screen.

   If  you are using PHP with a web server, the location and format of the
   logs  vary  depending  on  your  software.  Please read your web server
   documentation  to  locate  the logs, as it does not have anything to do
   with PHP itself.

   Common  problems  are  the  location  of  the  DLL,  the value of the "
   extension_dir"   setting   inside   php.ini  and  compile-time  setting

   If  the  problem  lies in a compile-time setting mismatch, you probably
   didn't download the right DLL. Try downloading again the extension with
   the right settings. Again, phpinfo() can be of great help.

Compiling shared PECL extensions with the pecl command

   PECL  makes  it  easy to create shared PHP extensions. Using the » pecl
1381 1382
   command, do the following:

   $ pecl install extname

1385 1386
   This  will  download  the  source  for  extname,  compile,  and install  into  your extension_dir. may then be loaded via

1389 1390
   By  default, the pecl command will not install packages that are marked
   with  the alpha or beta state. If no stable packages are available, you
   may install a beta package using the following command:

   $ pecl install extname-beta

1395 1396
   You may also install a specific version using this variant:

   $ pecl install extname-0.1
1398 1399 1400 1401 1402 1403


     After  enabling the extension in php.ini, restarting the web service
     is required for the changes to be picked up.
1405 1406 1407

Compiling shared PECL extensions with phpize

1408 1409
   Sometimes,  using  the  pecl  installer is not an option. This could be
   because  you're behind a firewall, or it could be because the extension
   you want to install is not available as a PECL compatible package, such
   as  unreleased  extensions  from  SVN.  If  you  need  to build such an
1412 1413
   extension, you can use the lower-level build tools to perform the build

   The  phpize  command is used to prepare the build environment for a PHP
1416 1417
   extension. In the following sample, the sources for an extension are in
   a directory named extname:
1418 1419 1420

$ cd extname
$ phpize
1421 1422 1423
$ ./configure
$ make
# make install

1425 1426
   A  successful  install will have created and put it into the
   PHP  extensions directory. You'll need to and adjust php.ini and add an
1427 line before you can use the extension.

1429 1430 1431 1432
   If  the  system is missing the phpize command, and precompiled packages
   (like  RPM's)  are  used, be sure to also install the appropriate devel
   version  of  the  PHP  package as they often include the phpize command
   along   with  the  appropriate  header  files  to  build  PHP  and  its
1433 1434 1435

   Execute phpize --help to display additional usage information.