PHP installation manual

Author: Nediam <javier@nediam.com.mx>
Publication date: 2006-01-15


Note: The operating system we used for testing was Debian GNU/Linux, and the webserver was Apache.

  1. Download the sources from the official PHP site http://www.php.net/downloads.php. At the time of this writing, the most recent version of PHP 4 is 4.4.2 and for PHP 5 is 5.1.2.

  2. PHP can be compiled either as a static or shared module for Apache. Currently, shared libraries are much more frequently used than static libraries (if you wish to know more about libraries in Linux check out this page. For PHP in particular, the decision to compile it as a static or shared module for Apache depends on individual necessities, although for small websites will not show a difference. In this document I will explain how to compile PHP as a shared module. Supposing that the file *.tar.bz2 was downloaded to /usr/local/, extract it and decompress it:
    SERVER:~# cd /usr/local
    SERVER:/usr/local# bzcat php-5.1.2.tar.bz2 | tar -xvf -


  3. Before configuring PHP we need to know which characteristics of it we will use. For example, if we will not be executing PHP scripts from the command line, then there is no need to enable that option. Supposing that what we need is to have PostgreSQL support within our PHP scripts and that we will only use it through the web, then we would pass the following options to the configure script:

    SERVER:/usr/local/php-5.1.2# ./configure --disable-cli --disable-cgi --without-pear --with-pgsql --with-apxs2=/usr/local/apache2/bin/apxs --enable-memory-limit

    Note: It's advisable to check the file INSTALL that comes in the root of the directory where the .tar.bz2 was decompressed (in this case it would be /usr/local/php-5.1.2/).

    Tip 1: To know all configuration options, execute /configure --help | more.
    Tip 2: If you are using Apache 1.x, then you'll need to use --with-apxs instead of --with-apxs2.


    If no errors ocurred, compile and copy the executables to the appropriate locations:
    SERVER:/usr/local/php-5.1.2# make
    SERVER:/usr/local/php-5.1.2# make install

  4. Copy the php.ini file to /usr/local/lib (or to the directory you specified in configure):
    SERVER:/usr/local/php-5.1.2# cp php.ini-dist /usr/local/lib/php.ini

    Tip: It is advisable to read carefully the php.ini-recommended file in order to use it instead of php.ini-dist.

    The php.ini file contains configuration options such as the maximum execution time for scripts, whether errors will be displayed on screen and be saved to a file, and aspects related to DBMSs with which PHP will interact, among others. It is very important to check this file and understand the directives it contains so we can adapt it to our necessities. If any option in this file is changed, then the web server must be restarted.

  5. Edit the Apache configuration file httpd.conf (if you're using Apache 2.x, this file is usually located in /usr/local/apache2/conf/) and verify that it contains the following lines, and if any are missing add them manually:

    LoadModule php5_module modules/libphp5.so
    AddType application/x-httpd-php .php
    AddType application/x-httpd-php-source .phps

    Tip: The last line is optional. It is for showing the source code of files with .phps extension with color syntax.

    Note 1: If you are configuring PHP 4 with Apache 2, the first line would be:
    LoadModule php4_module modules/libphp4.so

    Note 2: For Apache 1.3.x these would be the lines that should be present in the httpd.conf:
    LoadModule php5_module /usr/lib/apache/1.3.x/libphp5.so
    AddModule mod_php5.c
    AddType application/x-httpd-php .php
    AddType application/x-httpd-php-source .phps

  6. Restart Apache:
    SERVER:~# /usr/local/apache2/bin/apachectl restart

  7. Test our PHP installation. Edit in a directory that can be viewed by browser a file named test.php (or any name you choose) containing the following line:

    <?php phpinfo(); ?>

    Tip: The phpinfo function displays a lot of information related to configuration options, PHP version, besides information of the operating system and the webserver where the script was executed. This function is useful during the test phase, but due to the lot of information it displays, for a public website it's advisable to disable it in php.ini (disable_functions = phpinfo).

    Save the file and then from a browser execute it (http://localhost/path/to/test.php). A page must be displayed that looks like this. Analyze the content and check that everything is right.

Notes:


References:


The latest version of this document is available at: http://nediam.com.mx/en/docs/php_manual/index.php

<< 0 comments >>



TOP