nbsp;
Assignment 6 - System Update Installations + Installation of PHP
INLS 183 - Distributed Systems (new window)
October 28, 2002
Send comments to: bhayes@email.unc.edu

Assignments Index Page
nbsp;

Introduction / Background

I'm still working on setting up my home computer as a web server with open source web server, database and middleware/scriping software available for the Linux. Having installed Apache web server (assignment 3) and MySQL database server (assignment 5), this week I updated my system to RedHat 8.0, REinstalled the latest versions of Openssl and Apache and installed/configured PHP 4.2.3 to work with MySQL. Since the steps for the update installations (RH 8.0, Openssl and Apache) are covered in previous assignment writeups, this writeup will focus on the PHP install steps.

Note: I originally intended just to install PHP with the versions of OpenSSL (0.9.6b) and Apache (2.0.40-8) that I installed along with RH 8.0, however I found that the RPM version of Apache was not only older but also missing the apxs module need by PHP. So I decided to reinstall the more current versions of both OpenSSL (script) and Apache (script) from source tarballs using my previous write-ups.

The OpenSSL install went very smoothly. The Apache install presented problems because the RPM Apache install (in /usr/sbin from RH 8.0) and my tarball install (in /usr/local/apache2) conflicted such that my tarball httpd installation would not start because the RPM version was already running/listening on 80. I might have resolved this by restarting the server after I'd renamed the rpm httpd.conf and stopped the rpm httpd daemon. However, I decided to just UNinstall the rpm version ($ rpm -e httpd) in order make a clean start. This immediately solved the problem and I was able to get the new tarball Apache installation running on boot up.


Software Overview

PHP is a versatile scripting language that is well suited to web development and can be embedded within HTML. It integrates with the Apache web server and is particularly efficient for accomplishing CGI-like functions because it runs within the httpd server rather than as a separate, external process. PHP is syntactically similar to Perl and integrates will with database management software such as MySQL.

PHP is used in conjunction with MySQL backend by the UNC-Chapel Hill Academic Affairs Library (AAL) to dynamically generate the Campus E-Journals and E-Indexes & Databases lists of the Libraries electronic resources.

Health Sciences Library staff are actively working with AAL staff to develop the next version of the PHP-based public interface to the EJ/EID system. This work with PHP is providing an opportunity to compare it to the ColdFusion middleware that HSL currently uses in conjunction with Microsoft SQL database for its production web sites.

PHP software packages and documentation are available from PHP.net. As of September 2002, the latest and recommended maintenance version of PHP is 2.4.3. A complete list of changes implemented with this version is available here.


Installation and Troubleshooting Narrative (see script (incomplete))

CHECK FOR EXISTING PHP INSTALLATION; RETRIEVE PHP TARBALL
I used "which", "locate" and a newly discovered rpm command (rpm -q --queryformat "%{NAME}-%{VERSION}-%{RELEASE}:%{EPOCH}\n" php) to confirm that PHP was not previously installed on my system. I then visited the php.net site, read about available PHP versions and downloaded php-4.2.3.tar.gz (latest and recommended maintenance release) to /home/barrie/tmp.

$ wget "http://www.php.net/do_download.php?mr=http%3A%2F%2Fus2.php.net%2F&df=php-4.2.3.tar.gz"


PREPARATION, INSTALLATION AND CONFIGURATION
I copied the tar.gz package (tar.bz2 also available) to /usr/local and unzipped and detarred it there (as root since I'm writing to /usr/local).

$ sudo tar xzf php-2.4.3.tar.gz

It extracted into its own directory: /usr/local/php-2.4.3

I cded into the php-4.2.3 directory and reviewed the INSTALL file and the more current instructions referenced there at http://www.php.net/manual/en/install.apache.php. Per instructions in INSTALL, I checked to make mod_so module is enabled with my Apache httpd server install since its needed for PHP to work with it.

$ /usr/local/apache2/bin/httpd -l

The key module, mod_o.c, is installed along with several others. I proceeded with configuration and installation steps outlined in INSTALL. The one additional step listed in the online manual that was not listed in INSTALL was to configure Apache "--with-module=so"; I had previously enabled so (shared objects) during my Apache 2.x REinstall into /usr/local/apache2. My Apache apxs file that needs to be referenced in the PHP configure statement is in /usr/local/apache2/bin/apxs. Since my Apache install is version 2.x, I'll use the "--with-apxs2=" option instead of "--with-apxs=" MySQL is installed in /usr/local/mysql on my computer.

With that information, I can proceed with the PHP configuration and installation. I executed su - to become root since most of subsequent tasks require root access and permissions.

$ ./configure --with-mysql=/usr/local/mysql  --with-apxs2=/usr/local/apache2/bin/apxs
$ make
$ make install
Next, per INSTALL instructions, I copied the php.ini file to the place it needs to be.

$ cp php.ini-dist /usr/local/lib/php.ini

Looking at the file, I don't see anything that begs to be changed so I proceed without altering the php.ini file.

Next, I edit my httpd.conf file in /usr/local/apache/conf to add the lines indicated by INSTALL file. I find that PHP has already added the LoadModule instruction to the server configuration area of httpd.conf to have httpd load PHP when it starts:

LoadModule php4_module modules/libphp4.so

I added the 2 other lines to the AddType section of httpd.conf to instruct PHP to process all files ending in .php or .php4

AddType application/x-httpd-php .php
AddType application/x-httpd-php .php4

Restart the httpd server

$ /usr/local/apache2/bin/apachectl stop
$ /usr/local/apache2/bin/apachectl start

Check to see if httpd has started back up. It is:

[root@magnolia root]# ps -ef | grep httpd
root     23820     1  0 21:43 ?        00:00:00 
/usr/local/apache2/bin/httpd -k
nobody   23821 23820  0 21:43 ?        00:00:00 
/usr/local/apache2/bin/httpd -k
root     23823 23770  0 21:43 pts/0    00:00:00 grep httpd

Instructions for Use

PHP code is enclosed between a "<?php: beginning tag and a "?>" ending bracket. All PHP statements must end in a semicolon (;). PHP code may be imbedded within regular html markup; the part of the page within the php begin and end tags is processed by the PHP module running within the (Apache) web server. Pages containing PHP coding typically end in .php or .php4 extensions to designate that the page needs to be processed by PHP. The php file extensions could be .foo or .html as long as the web server httpd.conf file is updated to tell the httpd daemon which file types to pass along to PHP.

A common use of PHP code/pages is to receive input (e.g. from a search form), to run queries against a (MySQL) database based on that input, and then to return, manipulate and display in HTML some or all of the query output. Another common usage is to include conditional logic in an html page such that output of the page is different depending on what information is passed to it.

There is much more to PHP than this; see this basic tutorial on the PHP.net site.


Functionality (see phpfxn script).
I was able to create a php file (phpinfo) and view it with the lynx browser:
<?php
phpinfo();
?>
phpinfo() is one of many PHP functions; this function displays the specifics of the PHP installation on the server the PHP page resides. It itemizes the server information (environmental variables) available to be passed along to the browser.
  Send comments to: bhayes@email.unc.edu