Chapter 30. Installation

This section holds common questions about the way to install PHP. PHP is available for almost any OS (except may be for MacOS before OSX), and almost any web server.

To install PHP, follow the instructions in the INSTALLATION file located in the distribution. Windows 95 and NT users should also read the README.WIN32 file. There are also some helpful hints for Windows users here.

If you are trying to install PHP for use with Netscape's web server on Unix see: http://www.webgenx.com/php/phpnes.php3

1. Where should my php3.ini file be located?
2. I installed PHP using RPMS, but Apache isn't processing the PHP pages! What's going on here?
3. I installed PHP using RPMS, but it doesn't compile with the database support I need! What's going on here?
4. How do I get these libraries to work?

1. Where should my php3.ini file be located?

By default on UNIX it should be in /usr/local/lib. Most people will want to change this at compile-time with the --with-config-file-path flag. You would, for example, set it to something like:

    --with-config-file-path=/etc
     
And then you would copy php3.ini-dist from the distribution to /etc/php3.ini and edit it to make any local changes you want.

2. I installed PHP using RPMS, but Apache isn't processing the PHP pages! What's going on here?

Assuming you installed both Apache and PHP from RPM packages, you need to uncomment or add some or all of the following lines in your http.conf file:

# Extra Modules
AddModule mod_php.c
AddModule mod_php3.c
AddModule mod_perl.c

# Extra Modules
LoadModule php_module         modules/mod_php.so
LoadModule php3_module        modules/libphp3.so     /* for PHP 3 */
LoadModule php4_module        modules/libphp4.so     /* for PHP 4 */
LoadModule perl_module        modules/libperl.so
      
And add:

AddType application/x-httpd-php3 .php3    /* for PHP 3 */
AddType application/x-httpd-php .php      /* for PHP 4 */
      
... to the global properties, or to the properties of the VirtualDomain you want to have PHP support added to.

3. I installed PHP using RPMS, but it doesn't compile with the database support I need! What's going on here?

Due to the way PHP is currently built, it is not easy to build a complete flexible PHP RPM. This issue will be addressed in PHP 4. For PHP, we currently suggest you use the mechanism described in the INSTALL.REDHAT file in the PHP distribution. If you insist on using an RPM version of PHP, read on...

Currently the RPM packagers are setting up the RPMS to install without database support to simplify installations and because RPMS use /usr/ instead of the standard /usr/local/ directory for files. You need to tell the RPM spec file which databases to support and the location of the top-level of your database server.

This example will explain the process of adding support for the popular MySQL database server, using the mod installation for Apache.

Of course all of this information can be adjusted for any database server that PHP supports. We will assume you installed MySQL and Apache completely with RPMS for this example as well.

  • First remove mod_php3 :
    
rpm -e mod_php3
              

  • Then get the source rpm and INSTALL it, NOT --rebuild
    
rpm -Uvh mod_php3-3.0.5-2.src.rpm
              

  • Then edit the /usr/src/redhat/SPECS/mod_php3.spec file

    In the %build section add the database support you want, and the path.

    For MySQL you would add
    
--with-mysql=/usr \
             
    The %build section will look something like this:
    
	./configure --prefix=/usr \
    	--with-apxs=/usr/sbin/apxs \
    	--with-config-file-path=/usr/lib \
    	--enable-debug=no \
    	--enable-safe-mode \
    	--with-exec-dir=/usr/bin \
    	--with-mysql=/usr \
    	--with-system-regex
             

  • Once this modification is made then build the binary rpm as follows:
    
rpm -bb /usr/src/redhat/SPECS/mod_php3.spec
            

  • Then install the rpm
    
rpm -ivh /usr/src/redhat/RPMS/i386/mod_php3-3.0.5-2.i386.rpm
            

Make sure you restart Apache, and you now have PHP with MySQL support using RPM's. Note that it is probably much easier to just build from the distribution tarball of PHP and follow the instructions in INSTALL.REDHAT found in that distribution.

4. How do I get these libraries to work?