nav-left cat-right
cat-right

PHP

3.5 PHP

PHP is the other key LAMP component that I insist on installing from source. A lot of PHP's functionality can be added in as modules, and a base PHP distribution installed via yum or RPM will include most or all of these modules for compatibility reasons. Some of them I'll never use, and some I've never even heard of. I definitely do not want the memory overhead of unused modules.

3.5.1 Pre-installs

Make sure you have the following packages installed.

  • yum install zlib-devel gdbm-devel libjpeg-devel libpng libpng-devel

3.5.2 Install PHP

Download the latest PHP tarball from http://www.php.net/downloads.php into /usr/src/php.

  • sudo su -
  • mkdir /usr/src/php
  • cd /usr/src/php
  • wget [mirror url for tarball]
  • tar zxvf php-5.[version]
  • cd php-5.[version]

This is the configure line I use. Your mileage may vary, but I'm fond of it. Please note that this is a very minimal set of options! If you start getting errors from PHP saying such-and-such function doesn't exist, you're missing a module, and you'll need to come back here, re-run the configure script with your module added, and recompile the whole thing.

  • ./configure --disable-all --with-apxs2=/usr/sbin/apxs --with-mysql --disable-short-tags --with-zlib --with-gdbm --with-gd --enable-gd-native-ttf --with-freetype-dir=/usr/lib --with-jpeg-dir=/usr/lib --with-png-dir=/usr/lib --enable-ctype --with-pcre-regex --enable-session --enable-xml --enable-libxml --enable-dom --enable-spl --enable-json
  • make
  • service apache stop
  • make install
  • service apache start

3.5.3 Configure PHP

Copy the example .ini file to a place where PHP will read it:

  • cp /usr/src/php/php-[version]/php.ini-recommended /usr/local/lib/php.ini

Verify some of the following settings. I'll give you the settings I use for a development box. You may want to change the error reporting level and/or logging for a production box. For zlib.output_compression, remember that we set up apache with mod_deflate,
so we don't want to compress output in PHP as well.

short_open_tag = Off
zlib.output_compression = Off
magic_quotes_gpc = Off

For a development machine, I use the following error settings:

display_errors = On
log_errors = Off
error_reporting = E_ALL

On a production machine, you might want this instead:

display_errors = Off
log_errors = On
error_log = /var/log/php
error_reporting = E_ALL & ~E_NOTICE

3.5.4 Configure Apache to use PHP

The PHP install script may have added some or all of the necessary configuration lines in the Apache config file. The following options need to be set inside, so double-check each one in /etc/httpd/httpd.conf:

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

Restart apache. Try making a test page! If you've been following this guide straight through, just go to /srv/www and create a test.php page, and hit it with your browser.

Be Sociable, Share!