Fall Semester 2004


Lecture Notes Twelve: Installing PHP-4.3.7

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

burrowww.cs.indiana.edu% which make
/usr/local/gnu/bin/make
burrowww.cs.indiana.edu%
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.3.7 as an Apache module.

Here's how you do it.

This installation will take about 20'.

But you need to follow the steps carefully.

OK, let's get started.

Start by creating a nobackup (or scratch folder) (see how) to work in.

Suppose you create a nobackup folder, then you will be working in

/nobackup/username
where username is your username.

Copy

/l/www/classes/a348/software/php/php-4.3.7.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
/nobackup/dgerman/php-4.3.7
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 \
  --prefix=/u/dgerman/apache/apache_1.3.26/src 
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
/nobackup/dgerman/php-4.3.7
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 \
  --prefix=/u/dgerman/apache/apache_1.3.26/src
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

/u/username/apache/apache_1.3.26/conf
(Come on, do it now! You know how to do it.)

Now you need to recompile apache.

burrowww.cs.indiana.edu% pwd
/nfs/paca/home/user1/dgerman/apache/apache_1.3.26
burrowww.cs.indiana.edu% ./configure \
  --prefix=/u/dgerman/apache/apache_1.3.26 \
  --activate-module=src/modules/php4/libphp4.a 
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
    </IfModule>

    #
    # 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
/nfs/paca/home/user1/dgerman/apache/apache_1.3.26/conf
burrowww.cs.indiana.edu% ../bin/httpd -l
Compiled-in modules:
  http_core.c
  mod_env.c
  mod_log_config.c
  mod_mime.c
  mod_negotiation.c
  mod_status.c
  mod_include.c
  mod_autoindex.c
  mod_dir.c
  mod_cgi.c
  mod_asis.c
  mod_imap.c
  mod_actions.c
  mod_userdir.c
  mod_alias.c
  mod_access.c
  mod_auth.c
  mod_setenvif.c
  mod_php4.c
suexec: disabled; invalid wrapper /u/dgerman/apache/apache_1.3.26/bin/suexec
burrowww.cs.indiana.edu% 
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

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; 
     session_register("acc"); 
   } 
 ?>

<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> 


</form></body></html>
burrowww.cs.indiana.edu%
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?

Also, don't forget to check What's New? for additional information on the installation.


Last updated: Oct 13, 2004 by Adrian German for A348/A548