php3 - serving dynamic web pages


Table of Contents:


Introduction

php3 is programming language that has become successful as a server side scripting language for web servers. What has shown to be a good, and tight integration between php and database servers has allowed php to be the foundation for many useful tools for website administrators publishing dynamic (database driven) websites. The same tasks performed using php is arguably achievable with Perl (which is already widely used with databases and server side scripting) or with ASP, Microsoft's Active Server Pages.

This guide will help you install php3 with OpenBSD, php4 has been released but I have not as yet been able to install it and configure it, when I do I'll document it along with what is already here.

php3 installation

source-file: php-3.0.16.tgz       (available from the distfiles directory)
package: mysql-3.22.23.tgz, (required by --my-msql option)
package: gettext-0.10.35.tgz, (required by --with-gettext)
package: gdbm-1.8.0.tgz
config file: /var/www/conf/php3.ini

All the above specified source or package files are available from OpenBSD ftp mirrors.

For normal activities you may be satisfied with just installing the php binary package available from the OpenBSD ftp sites. The binary package is compiled using –without-mysql and a number of other things I probably need to get horde and imp up and running.

To include the mysql support requires installing the distribution files and configuring/re-compiling with mysql support. (The following instructions assume you have already installed mysql, and a few support packages such as gettext and gdbm. You can simply download the packages and install them using pkg_add.)

untar the source distribution

# cd /usr/src
# tar -zxf /[path-to-tar-source]/php-3.0.16.tar.gz
# cd php-3.0.16

The configuration selection I use below includes support for IMAP and mysql. Instructions for installing these are available in Mail Services, and MySQL.

Compiling php3 from source

You can also use an alternate 'setup' script that comes with php3 or use the ports collection with make FLAVOR=mysql. The --with-gettext option below assumes that the package has already been installed, if not you can either add the package or remove the option.

# ./configure --with-apxs=/usr/sbin/apxs --with-xml \
--with-config-file-path=/var/www/conf --with-mysql --prefix=/usr/local \
--sysconfdir=/etc --with-imap=/usr/local --with-ftp --with-gettext \
--enable-force-cgi-redirect=yes --enable-track-vars=yes \
--enable-magic-quotes=yes --enable-debug=no --with-system-regex=yes
 
# make
# make install
# cp php3.ini-dist /var/www/conf/php3.ini
# mkdir /var/www/php
# echo "<?php phpinfo() ?>" > /var/www/htdocs/test.php

 

After copying the binary files to their intended directories, the enable the php3_module in the configuration file, and add the data-types (but leave them commented out.) You must edit the configuration file /var/www/conf/httpd.conf to enable the MIME data-types and to include additional MIME data-types.

If you are comfortable with the ports system, then once you've configured the ports directory then you can install mysql support by using the "make FLAVOR=mysql" command. Check the documentation for further assistance.

Configuring Apache

The installation will make the below modifications to the httpd.conf file:

# Dynamic Shared Object (DSO) Support
LoadModule php3_module        /usr/lib/apache/modules/libphp3.so
 
# AddType allows you to tweak mime.types without actually editing it, or to
# make certain files to be certain types.
#AddType application/x-httpd-php3 .phtml
#AddType application/x-httpd-php3-source .phps

 

You should enable the changes and make additions as shown below:

# Dynamic Shared Object (DSO) Support
LoadModule php3_module        /usr/lib/apache/modules/libphp3.so
 
# AddType allows you to tweak mime.types without actually editing it, or to
# make certain files to be certain types.
AddType application/x-httpd-php3 .phtml
AddType application/x-httpd-php3-source .phps
AddType application/x-httpd-php3 .php
AddType application/x-httpd-php3 .php3

# Add to the Directory Index the php extensions
DirectoryIndex index.html index.htm default.html default.html index.php3 index.php index.phtml

The install does not configure some of the standard file extensions used for php3 files (at least from what I understand by checking the url's presented by some sites.)

Make the following recommended change to the default configuration /var/www/conf/php3.ini. The default file has a commented out section on where to store temporary upload files.

;upload_tmp_dir = ; temporary directory for HTTP uploaded files

Set a valid temporary directory location such as /tmp

upload_tmp_dir = /tmp ; temporary directory for HTTP uploaded files

Test whether the binaries are built and installed correctly by restarting the httpd server (force it to re-read the configuration file by using.)

# apachectl restart

If Apache was not previously running, then you could use the " apachectl start " command to start the server.

Testing php 3.

The above echo "<?php phpinfo() ?>" > /var/www/htdocs/test.php will let you quickly check whether php is working by calling up the file test.php:

# lynx localhost/test.php
[ lynx displays the following ...]
 
                           PHP Version 3.0.16

by Rasmus Lerdorf, Andi Gutmans, Zeev Suraski, Stig Bakken, Shane Caraveo, Jim Winstead, and countless others.

_______________________________________________________________________________________________________________

System: OpenBSD micron 2.7 GENERIC#25 i386
                           Build Date: Jun 29 2000

_______________________________________________________________________________________________________________

Extensions

Extensions Additional Information
PHP core CFLAGS=
HSREGEX=

[ ... more stuff cut out ... ]
 

 

Of course if you have a browser that supports tables (AOL Navigator, or Microsoft Internet Explorer) then it would a look a lot nicer.

Further test scripts are available, but once the above is working you know you have a 'working' php configuration. The additional scripts can help you with debugging errors or if there are specific components you need to review. Two directories (test, tests) hold a number of different tests for checking the functionality of your php configuration.

Below is one process for testing my php installation by copying the sample files into the standard web tree. (note: commands are typed from inside the /usr/src/php-3.0.16 directory)

# mkdir /var/www/htdocs/xyzxy
# cp -R examples /var/www/htdocs/xyzxy
# cp -R tests /var/www/htdocs/xyzxy
 

xyzxy is just a placeholder for some obscure name that you can use so your test files are not easily accessible to others on the network.

In a web browser point to the server and the above locations:

http://my-web-server/xyzxy/test
http://my-web-server/xyzxy/tests

Each of the above locations will list a number of php documents that can be used to check if php is working.

http://my-web-server/xyzxy/tests/bench.phtml

bench.phtml is a good test for whether the AddType directive (httpd.conf) is working correctly and to see whether loop constructs are working.

http://my-web-server/xyzxy/examples/date.php3
http://my-web-server/xyzxy/examples/dir.php3

date.php3 and dir.php3 are good tests for the AddType directive and whether the directory listing and date functions are working.

Make sure to clean up the test files when you are finished just incase there are some security holes in the scripts we don't know about.

# rm -rf /var/www/htdocs/xyzxy

Author and Copyright

Copyright (c) 2000/1/2 Samiuela LV Taufa. All Rights Reserved.

I reserve the right to be totally incorrect even at the best advice of betters. In other words, I'm probably wrong in enough places for you to call me an idiot, but don't 'cause you'll hurt my sensibilities, just tell me where I went wrong and I'll try again.

You are permitted and encouraged to use this guide for fun or for profit as you see fit. If you republish this work in what-ever form, it would be nice (though not enforceable) to be credited.

php3 - scripting the web.

Copyright  © 2000/1/2 NoMoa Publishers All rights reserved. Caveat Emptor