Impossible tri-bar

Digital Phenomena - Your first stop for internet consultancy 
PHP4 Installation Overview

Page 4 — Installing PHP4 (Non-Windows)

In this section, you'll learn how to install PHP4 as a DSO for Apache, from the source. Let's start with the download (if you have an existing version of PHP on your system, you can skip right to the configuration steps):

  1. Go to the "Downloads" area at http://www.php.net and select the link for the latest source files.
  2. Put this file somewhere logical, like /usr/local/ or /opt/ or anywhere else you want.
  3. Unzip or uncompress the file, so that you're left with the *.tar file.
  4. Type the following to un-tar the file into a directory called php-[version]:
    tar -xvf php-[version]
    
  5. cd into /usr/local/php-[version] (or wherever you put it).

The build process for PHP follows the same sequence as the build process for Apache: configure, make, make install. Just for your own edification, this next step will show you the numerous configuration options that you have, when building PHP. At the prompt, type:

./configure --help

You'll see a list of the 150 or so configuration options for PHP. You can get away with using just one, but here are a few of the more popular options:

  • --with-apxs=[/path/to/apxs] : This option builds PHP as a DSO. You should specify the path to the apxs script, which is usually in the Apache bin directory (/usr/local/apache[version]/bin/ or wherever you put it).
  • --enable-ftp : This option enables the built-in FTP functions.
  • --with-gd=[/path/to/gd] : This option enables the image-creation functions, if you have the GD library installed.
  • --with-mcrypt=[/path/to/mcrypt] : This option includes mcrypt support, if you have the mcrypt libraries installed.
  • --with-mhash=[/path/to/mhash] : This option includes mhash support, if you have the mhash libraries installed.
  • --with-mysql=[/path/to/mysql] : This option enables the MySQL functions, if you have MySQL installed in the directory specified. If you do not specify a directory, the bundled MySQL library will be used.
  • --with-oci8=[/path/to/ORACLE_HOME] : This option enables the Oracle 8 (oci*) functions, if you have the Oracle client libraries installed.

Once you get the hang of configuring and building PHP, feel free to pick and choose your configuration options. Remember: Because you're creating the DSO version of PHP, you can add or delete options until the end of time and you won't have to do much more than restart Apache later on.

For now, let's just create the DSO version of PHP with MySQL support. Type the following configuration line, replacing [/path/to/mysql] with your own actual path (such as /usr/local/mysql) and changing [/path/to/apxs] to be the actual path to your apxs file (look in the Apache installation bin directory):

./configure --with-mysql=/[path to mysql] --with-apxs=/[path to apxs]

Now, watch the configuration file do its thing, checking for everything under the sun. Hopefully, you'll see a good set of makefiles being created, and then you'll be kicked back to the prompt. If you had any warnings or errors, try to decipher the problem from the messages that appear, and attempt the configuration again. You can also check the PHP FAQ. If you made it to this point without fatal errors or other bad warnings, however, type the following:

make

At this point, "make" runs the makefiles created in the configuration step and begins to build PHP. Again, the goal is to get through this step without warnings and fatal errors. If you had warnings or errors, try to decipher the problem from the messages that appear, and attempt the configuration again. When you're back at the prompt, type:

make install

This final step in the compilation sequence compilation will create the DSO, plop it in the Apache modules directory, modify some parts of the Apache httpd.conf file for you, and return you to the prompt, where you'll need to go back to the Apache httpd.conf and make one more modification: You need to tell Apache what to do with *.php or *.phtml files.

With httpd.conf open in your text editor, find a section that looks like the following:

# And for PHP 4.x, use:
#
#AddType application/x-httpd-php .php
#AddType application/x-httpd-php-source .phps

Just take away the "#" before the two AddType lines, and add ".phtml" on the line with ".php". If you want to create your own file extension for PHP files, like .joe (really, you can!), add .joe after the .php and .phtml in the first AddType line. The section should now look something like this:

# And for PHP 4.x, use:
#
AddType application/x-httpd-php .php .phtml
AddType application/x-httpd-php-source .phps

TIP: If you want to parse *.html files as PHP, just add the file extension to the list in your AddType line, so that it ends up looking like this:

AddType application/x-httpd-php .php .phtml .html

Save the file, go up a directory (cd ..), and stop and restart Apache by typing:

./bin/apachectl stop

Followed by:

./bin/apachectl start

If you get an error at startup about Apache not being able to load the PHP module, because it can't find a correspondingly named library (like libmysqlclient.so), here's what you do:

  1. Use "find" to located the file that it says it can't find.
  2. Using a text editor, open "/etc/ld.so.conf".
  3. Add the directory in which the problematic file exists.
  4. Save the file.
  5. Type "ldconfig".
  6. Return to the PHP directory and type "make clean".
  7. Issue the configuration command, followed by the make and make install steps.

After telling your system where the libraries are, the build sequence should be successful, or at least closer to finishing. If your build does not complete without failing, and you're at your wit's end about some obscure library, you can search the php-install mailing list search archives for a similar problem and possible solution. Of course, if the build sequence was successful, you're ready to test the installation.

next page»


|Home|About Us|Services|Search|
|Software|Products|Support|Links|Latest|
W3C validatedW3C validated CSSCompatible with all browsers