|
Spring Semester 2002 |
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 /tmp/dgerman/php-4.1.0 burrowww.cs.indiana.edu% ./configure \ --with-mysql=/l/mySQL \ --with-apache=/u/dgerman/apache/apache_1.3.22 \ --with-config-file-path=/u/dgerman/apache/apache_1.3.22/conf \ --with-xml --enable-track-vars \ --prefix=/u/dgerman/apache/apache_1.3.22/src
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.)/u/username/apache/apache_1.3.22/conf
Now you need to recompile apache.
burrowww.cs.indiana.edu% pwd /nfs/paca/home/user1/dgerman/apache/apache_1.3.22 burrowww.cs.indiana.edu% ./configure \ --prefix=/u/dgerman/apache/apache_1.3.22 \ --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)
Then restart your server
(You may have to stop, then start, if the test below fails.)../bin/apachectl restart
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.22/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.22/bin/suexec burrowww.cs.indiana.edu%
Now create a simple file one.php that looks like this
place it in<? phpinfo() ?>
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:
/tmp now
/tmp now
/tmp now
/tmp now
/tmp now
/tmp now
/tmp now
/tmp now.
/tmp is a shared place, OK?) So do it before you forget. Be careful.
Two more things we need to do:
/u/username/apache/apache_1.3.22/phpsessions
php.ini and find this line:
session.save_path = /tmp
then change it into
session.save_path = /u/username/apache/apache_1.3.22/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?