Spring Semester 2003

Lecture Notes Twelve: Installing PHP-4.1.0

For this set of notes it's important to make sense of this command:

burrowww.cs.indiana.edu% which make
Is CGI easy to program? Is it powerful?

Are there any other things out there, alternatives to it?

Server-side programming. How about PHP?

PHP started out as a CGI script (written in Perl).

It now can be installed as a standalone CGI script and as an Apache module.

The first one is more portable. The second more efficient.

In class we are going to install PHP-4.1.0 as an Apache module.

Here's how you do it.

This installation will take about 20'.

But please, please, please,

follow the steps very carefully.

OK, let's get started.

Create a temporary directory /tmp/username

Copy /u/dgerman/public/php-4.1.0.tar.gz there and uncompress and unarchive it.

Then remove the .tar file and go into the directory created.

Inside that directory run ./configure as follows:

burrowww.cs.indiana.edu% pwd
burrowww.cs.indiana.edu% ./configure \
  --with-mysql=/l/mySQL \
  --with-apache=/u/dgerman/apache/apache_1.3.26 \
  --with-config-file-path=/u/dgerman/apache/apache_1.3.26/conf \
  --with-xml --enable-track-vars \
Here it's better to write this command in a file and run it as a shell script.

This way you have a record of what you actually did, and can track down bugs.

burrowww.cs.indiana.edu% pwd
burrowww.cs.indiana.edu% ls -ld try
-rwxr-xr-x   1 dgerman  faculty       236 Oct  7 17:10 try
burrowww.cs.indiana.edu% cat try
./configure \
  --with-mysql=/l/mySQL \
  --with-apache=/u/dgerman/apache/apache_1.3.26 \
  --with-config-file-path=/u/dgerman/apache/apache_1.3.26/conf \
  --with-xml --enable-track-vars \
burrowww.cs.indiana.edu% ./try
Please ask me if you don't know how to do this.

Then run make.

Then run make install.

Copy php.ini-dist as php.ini into the directory

(Come on, do it now! You know how to do it.)

Now you need to recompile apache.

burrowww.cs.indiana.edu% pwd
burrowww.cs.indiana.edu% ./configure \
  --prefix=/u/dgerman/apache/apache_1.3.26 \
Then run make.

Then run make install.

Change your httpd.conf by uncommenting these two lines:

    # LanguagePriority allows you to give precedence to some languages
    # in case of a tie during content negotiation.
    # Just list the languages in decreasing order of preference. We have
    # more or less alphabetized them here. You probably want to change this.
    <IfModule mod_negotiation.c>
        LanguagePriority en da nl et fr de el it ja kr no pl pt pt-br ru ltz ca es sv tw

    # AddType allows you to tweak mime.types without actually editing it, or to
    # make certain files to be certain types.
    # For example, the PHP 3.x module (not part of the Apache distribution - see
    # http://www.php.net) will typically use:
    #AddType application/x-httpd-php3 .php3
    #AddType application/x-httpd-php3-source .phps
    # And for PHP 4.x, use:
    AddType application/x-httpd-php .php
    AddType application/x-httpd-php-source .phps

    AddType application/x-tar .tgz

    # AddHandler allows you to map certain file extensions to "handlers",
    # actions unrelated to filetype. These can be either built into the server
    # or added with the Action command (see below)
(Note: if you have to add these two directives use pico line no. is 778 or so.)

Then restart your server

../bin/apachectl restart
(You may have to stop, then start, if the test below fails.)

Now verify that your server now has the PHP module inside:

burrowww.cs.indiana.edu% pwd
burrowww.cs.indiana.edu% ../bin/httpd -l
Compiled-in modules:
suexec: disabled; invalid wrapper /u/dgerman/apache/apache_1.3.26/bin/suexec
Now create a simple file one.php that looks like this
<? phpinfo() ?>
place it in htdocs and access it from the web.

If it works, you're done, so please don't forget to remove everything you had on /tmp.

Let me remind you:

Please, please, please. (/tmp is a shared place, OK?)

So do it before you forget. Be careful.

Two more things we need to do:

  1. create a folder /u/username/apache/apache_1.3.26/phpsessions

  2. open your php.ini and find this line:
    session.save_path = /tmp
    then change it into
    session.save_path = /u/username/apache/apache_1.3.26/phpsessions
    where, as you can see, you add the folder that you have just created.
Now try this example:
burrowww.cs.indiana.edu% cat three.php
<? session_start();
   if (session_is_registered("acc")) {
     if ($fun == "add") $acc += $arg; 
     else if ($fun == "sub") $acc -= $arg; 
   } else {
     $acc = 0; 

<html><head><title>Sessions Examples</title></head><body bgcolor=white>
<form method="POST" action="<? echo $SCRIPT_NAME; ?>"> 

The current value of the accumulator is: <? echo $acc ?>

<table cellpadding=2><tr> 
<td> Amount: </td> <td> 

<input type="text" name="arg" size=4> </td> <td> 

Function: </td> <td> <select name="fun"> 
  <option value="non"> Click Me! 
  <option value="add"> Deposit
  <option value="sub"> Withdraw   
</select> </td> </tr> </table> 

<p> Enter the amount, select a function, then press 

<input type="submit" value="Proceed"> <p> 

As you work with it, check the contents of the files in phpsessions.

(Work with your own version, not with mine, while you check the folder).

Can you figure out what's going on?

Last updated: Feb 6, 2003 by Adrian German for A348/A548