php4 - serving dynamic web pages


Table of Contents:


Introduction

php4's release has been much anticipated and OpenBSD has packaged different pre-compilations for direct installation. A direct binary package will most likely cater for the majority of peoples' needs.

This guide will help you install php4 with OpenBSD.

My gratitudes to those who have sent me information on their php4 installation successes which has lead to my being able to get this far.

Installing php4

[package: php4-4.0.3pl1p1-mysql.tgz (available from ftp sites)]
[package: mysql-3.22.32.tgz, (required by above package)]
[config file: /var/www/conf/php.ini]

If all you wish to do is install php4 and mysql for some custom software you are deeveloping then just install the packages using the pkg_add package manager.

# pkg_add /[path-to-package-file]/mysql-3.22.32.tgz

# pkg_add /[path-to-package-file]/php4-4.0.3pl1p1-mysql.tgz

 

Using the Ports Tree to Reconfigure php4

[source: ports.tar.gz]

[source: php4-4.0.3pl1.tar.gz (available from php4 or OpenBSD ftp sites)]
[package: imap-uw-2000b.tgz (required for below configuration)]
[package: c-client-2000c.tgz (required during build time for imap client connection)]
[package: pdflib-3.02.tgz]

The configuration selection I use below includes support for IMAP and mysql. Instructions for installing IMAP and MySQL in Mail Services, and MySQL. The c-client can be package added as listed above, instead of the manual approach described in the Mail Services notes.

After decompressing the ports.tar.gz tree onto your hard-disk. Install and configure imap as described above, along with any other libraries you wish to configure with php to support.

# cd /usr
# tar -zxf /path-to-file/ports.tgz

For those with a fast Internet connection, go ahead and skip the next step and go straight to making your file. For us with slow if infrequent access, follow these steps.

1. Download the current ports collection and php4 files (for my configuration php4-4.0.3pl1 co-incided with the latest version supported by the ports.tar.gz file)

2. Place the file into the /usr/ports/distfiles directory (if the directory does not exist, go ahead and create it.) The directory is where the ports activity downloads files, so it doesn't have to search the Internet if the files are already there.

Change into the php4 directory and use the FLAVOR options to create IMAP support.

# cd /usr/ports/www/php4

# env FLAVOR="mysql imap gettext pdflib gd" make

 

[ ... screen output of config / make process ... ]

 

libzlib.la TSRM/libtsrm.la -lz -lcrypto -lssl -lresolv -lm -lresolv

Making all in pear

 

# env FLAVOR="mysql imap gettext pdflib gd" make install

[ ... screen output of config / make process ... ]

 

+---------------

| To finish the install, you need to enable the php4

| module using the following command

|

| /usr/local/sbin/php4-enable

+---------------

# /usr/local/sbin/php4-enable

enabling php4 module... cp /usr/local/lib/libphp4.so /usr/lib/apache/modules/libphp4.so

chmod 755 /usr/lib/apache/modules/libphp4.so

[activating module `php4' in /var/www/conf/httpd.conf]

note: sample configuration files can be found in /usr/local/share/doc/php4

 

# cp /usr/ports/www/php4/work/php-4.0.4pl1/php.ini-dist /var/www/conf/php.ini

# echo "<?php phpinfo() ?>" > /var/www/htdocs/test.php

The FLAVORS selection included gettext and a few other options I want. After the make finishes the configuration it generates the necessary files and the 2nd thing we do is install by using make install. This causes the ports tree to create a package and add the package to our system.

After the package installation, the package manager prompts us to execute the php4-enable program.

After php4-enable I am copying the sample initialisation file php.ini-dist into the expected configuration directory (/var/www/conf)

php4 should now be installed with the features that I require.

Configuring Apache

The installation (/usr/local/sbin/php4-enable) will make the below modifications to the apache configuration file:

# Dynamic Shared Object (DSO) Support

LoadModule php4_module /usr/lib/apache/modules/libphp4.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:

Edit /var/www/conf/httpd.conf

# Dynamic Shared Object (DSO) Support
LoadModule php4_module /usr/lib/apache/modules/libphp4.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-php .phtml
AddType application/x-httpd-php-source .phps
AddType application/x-httpd-php .php
AddType application/x-httpd-php .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 php4 files (at least from what I understand by checking the url's presented by some sites.) We retain the use of php3 as this is common on many php scripts available on the net.

php4 will use the system default "tmp" partition/path if not otherwise specified. In php3 you were required to specify the tmp space to be used for php uploads as in the following. The default file has a commented out section on where to store temporary upload files.

File /var/www/conf/php.ini

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

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

System OpenBSD hostname 2.8 GENERIC#399 i386
Build Date Today's Date
_______________________________________________________________________________________________________________

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

Compiling from source

Being offline, when things go wrong there is no net connection to check what I'm doing wrong, so I have found fiddling with compiling the source has worked for me. After installing all the supporting programs shown above, I can compile the features I wish by doing the following.

# ./configure --with-apxs=/usr/sbin/apxs --with-xml \
--with-config-file-path=/var/www/conf --with-mysql=/usr/local --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 php.ini-dist /var/www/conf/php.ini
# echo "<?php phpinfo() ?>" > /var/www/htdocs/test.php

Note that with php4 a full make; make install will automatically perform the tasks normally performed in a package installation by php4-enable

The above compile sequences used to work, but the config has changed significantly and we are all better off because of the ports tree and Anil Madhavapeddy and the number of patches required to get php4 working with OpenBSD.

Apache fails to start

After you restart your machine you may get an error during the restart, and when you attempt to manually start Apache such as the following:

# apachectl start

/usr/libexec/ld.so: httpd: libmysqlclient.so.6.0: No such file or directory

/usr/sbin/apachectl start: httpd could not be started

The problem is that the libmysqlclient.so.6.0 file is not in the standard path for the run-time linker ld.so. To ensure that the file is always included when the system is started you can either link the file to the standard location, or add the file location to the default search path.

Approach 1:

We can create a symlink of the library file into a standard library path such as /usr/local/lib/

# ln -s /usr/local/lib/mysql/libmysqlclient.so.6.0 /usr/local/lib/libmysqlclient.so.6.0

Approach 2:

We can include the new directory into the list of directories searched by ld.so and this can be done in the configuration rc.conf.local

edit /etc/rc.conf.local and add the following line in Section 3:

shlib_dirs="$shlib_dirs /usr/local/lib/mysql" # extra directories for ldconfig

This will override the existing setting in /etc/rc.conf which is usually:

shlib_dirs= # extra directories for ldconfig

We are using $shlib_dirs in the above example to expand whatever settings exist for shlib_dirs and then include our new directory. Note that you must use quotation marks and use a space between directory paths.

There are some security concerns about adding directories into the standard path for ldconfig so you should study the man pages.

Editorial Notes

Especial appreciation is given here to Guillermo Ruiz who's e-mail detailing how he was able to configure PHP4 and MySQL saved many hours of 'fiddling' to get the above notes.

Guillermo's notes are linked here and The copyright of the original material remains with Guillermo Ruiz.

More documentation on using the Ports and getting different flavors is available at http://php3.de/manual/zh/install.openbsd.php

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.

php4 - scripting the web.

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