# =========================================================
# Header details
#
# Copyright ........: Frank Schulte (fschulte\@hightek.com)
# Module/method ....: ./sourceforge.net/doc/pkg/php/index.html
# Version ..........: 00001
# CVS ..............: $Id: index.html,v 1.1.1.1 2001/07/18 01:50:35 fschulte Exp $
# Analyst ..........: FS
# Developers .......: FS  - Frank Schulte (fschulte\@hightek.com)
# Description ......: PHP installation documentation
#
#  LastAmended Name
#  ----------- -------------------------------------------------------------
#
# History ..........:
#
# Vers.     Date    SSR   By  Reason
# ----- ----------- ---- ---- ------------------------------
# 00001 19.12.2000  n/a  FS   Begin Documentation of installation process
# 00002 21.02.2001  n/a  FS   Move changelog into a seperate file.
# 00003 16.06.2001  n/a  FS   Add zlib and mcrypt compile in docu.
# =========================================================
Changelog: here

Step by step installation guide for mod_php and standalone php

1. Get needed Sources:

1.1. PHP itself

http://www.php.net/downloads.php
php-4_0_5


1.2. the zlib because SF uses compression functions

http://www.gzip.org/zlib.tar.gz

As of 08.06.2001 we use version 1.1.3
 
 

1.3. LDAP
ftp://ftp.OpenLDAP.org/pub/OpenLDAP/openldap-release/openldap-2.0.7.tgz


1.3. mcrypt

ftp://argeas.cs-net.gr/pub/unix/mcrypt/
http://mcrypt.hellug.gr/


1.3. libmcrypt

FS: 16.06.2001, please note carfully that we had no luck comiling in libmcrypt !

WE HAVE TRIED

version 2.4.11 and 2.4.15
But no luch so far !

Please check the documentation below in the PHP patching section.


To use it, download libmcrypt-x.x.tar.gz from here and follow the included installation instructions. You need to compile PHP with the --with-mcrypt parameter to enable this extension. Make sure you compile libmcrypt with the option --disable-posix-threads.

ftp://mcrypt.hellug.gr/pub/mcrypt/libmcrypt/libmcrypt-2.4.11.tar.gz

2. Preparations

Config, make and install all needed external libs and modules.

Setup the path to the base installation path of the sourceforge.net installation.

export PKG=/home/system/pkg/sourceforge.net

2.1. Zlib

2.1.1. Static libs

export ZLIB_PKG=${PKG}/zlib/1.1.3

mkdir -p ${ZLIB_PKG}

tar -xzf zlib-1.1.3.tar.gz
cd zlib-1.1.3
./configure --prefix=${ZLIB_PKG}
make test

su -
<root-password>

make install

2.1.2. Shared libs

export ZLIB_PKG=${PKG}/zlib/1.1.3

mkdir -p ${ZLIB_PKG}

tar -xzf zlib-1.1.3.tar.gz
cd zlib-1.1.3
./configure --prefix=${ZLIB_PKG}
make test

su -
<root-password>

make install

echo "${ZLIB_PKG}/lib" >> /etc/ld.so.conf

ldconfig

2.2. mcrypt

export LIBMCRYPT_PKG=${PKG}/libmcrypt/2.4.11

tar -xzf libmcrypt-2.4.11.tar.gz
cd libmcrypt-2.4.11

./configure --prefix=${LIBMCRYPT_PKG} --disable-posix-threads
make
make check
make install

echo "${LIBMCRYPT_PKG}/lib" >> /etc/ld.so.conf

ldconfig

2.3. LDAP

Follow this install documents for LDAP.

3. Installation PHP 4

3.1. Patch PHP 4.0.5 to fix max keysize segfault problem with libmcrypt 2.4.11

We had many troubles to get PHP 4.0.5 and libmcrypt 2.4.11 to work.

We had to patch the ext/mcrypt/mcrypt.c file to fix an error in PHP 4.0.5. In PHP 4_0_6 Release Candidate 1 this was fixed. We took the patch from the PHP site for the mcrypt documentations . See at bottom of the page with the comments, you will find (16.06.2001):
 

kennwhite.no.spam.@hotmail.antispam.com
                06-Jun-2001 04:18
                There was much activity over the instability of mcrypt in php 4.05
                recently. See
             http://marc.theaimsgroup.com/?l=php-cvs&m=99021946326583&w=2
                for example.

                The source of most problems is from the crappy example in the manual
                above. There is a bug, which has been fixed in the 4.0.6 Release
                Candidate 1, which gracefully returns an error if you try to use a key
                length greater than that *supported* for the algorithm. In other words,
                you must not use a key size larger than the algorithm (obviously), but
                also not larger than that supported.

                Take a look at the man page for mcrypt, which lists all the modes and
                key sizes, or check out the Core PHP book, which has very good examples.
                If you:
                tail /usr/local/apache/logs/error_log
                using the example above, you'll see a segfault. The solution:
                $key="smaller key";

                Finally, Derek Rethans (the lead PHP developer for mcrypt) recommends
                using the libmcrypt-2.4.11.tar.gz version, as it apparently is the most
                stable. After having stress-tested this for several days, I think he's
                right on target. I've had no luck with versions .12 - .14, but using
                version 11 and PHP 4.05 on RH 6.2 (*with* the proper key sizes) has been
                very robust so far.

                -kenn
 

Do this to incorporate the needed patch:

# Change to root because as normaluser we can not read the apache directorys
su -
<root-password>

cd ${BASE_SOURCES}/sourceforge.net-binaries-needed-software
cd php-4.0.5

cd ext/mcrypt

patch --unified --input=sf-genericinst/patches/mcrypt_patch_max_keysize.diff -b --reject-file=./mcrypt.reject.c

You should see this output:
 

patching file mcrypt.c
Hunk  #2 succeeded at 464 with fuzz 1.


This will patch the mcrypt.c file. A backup of the file will be put into the file mcrypt.c.orig.

3.1.1. reconfig PHP 4.0.5

If you have previusly compiled PHP 4.0.5 and want

- to add mcrypt
- you want to re-add mcrypt after patching it with the above patch
- you want to add/delete any other module to php
you can do this:

cd ${BASE_SOURCES}/sourceforge.net-binaries-needed-software
cd php-4.0.5

cd ext

rm -rf module_name

for example

rm -rf mcrypt

cd ${BASE_SOURCES}/sourceforge.net-binaries-needed-software
cd php-4.0.5

cd _apxs

../config ... <all config options you used the last time compiling php +/- new or deleted modules>

3.1.2. How to debug SF PHP code

With custom error handling functions look here.

Or try the one below.
 

You must first verify that the include_path setting in httpd.conf and php.ini is exactly the same ! And add development folder to have access to the debug helping include files.

;;;;;;;;;;;;;;;;;;;;;;;;;
; Paths and Directories ;
;;;;;;;;;;;;;;;;;;;;;;;;;
; include_path: UNIX: "/path1:/path2"  Windows: "\path1;\path2"
include_path    = "${PKG}/SF/cvs-read:${PKG}/SF/cvs-read/www/include:${PKG}/php/4.0.5/lib/php:${PKG}/SF/development:."
Add to /etc/local.inc these lines:
// set IS_DEBUG to true !!!
// FS: 15.06.2001
//$IS_DEBUG=true;
$IS_DEBUG=false;

if ( $GLOBALS['IS_DEBUG'] ) {
        require_once('fschulte_utils.php');

        print "local.inc: Loaded.<BR>\n";
}

Now if you set $IS_DEBUG to true you will get debug output. But be warned that if you output lines before the headers you will not see the right pages. But for debugging you know what you do, right ?

Then you can add this php.ini settings to get ALL output and ALL warnings delivered to the Browser. Please note that the ";" is the line comment character.

output_buffering        = Off   ; Output buffering allows you to send header lines (including cookies)

; implicit_flush                = Off   ; Implicit flush tells PHP to tell the output layer to flush itself
implicit_flush          = On    ; Implicit flush tells PHP to tell the output layer to flush itself

;error_reporting        =       E_ALL & ~E_NOTICE               ; Show all errors except for notices
error_reporting =       E_ALL                                           ; Show all errors except for notices

display_errors  =       On      ; Print out errors (as a part of the output)

;display_startup_errors = Off           ; Even when display_errors is on, errors that occur during
display_startup_errors = On             ; Even when display_errors is on, errors that occur during

;log_errors             =       Off     ; Log errors into a log file (server-specific log, stderr, or error_log (below))
log_errors              =       On      ; Log errors into a log file (server-specific log, stderr, or error_log (below))

; track_errors  =       Off     ; Store the last error/warning message in $php_errormsg (boolean)
track_errors    =       On      ; Store the last error/warning message in $php_errormsg (boolean)
 
 
 


3.2. finish the php installation

We use a target subdirectorys to build the PHP apache module and the standalone PHP binary. This will work with GNU make, which all Linux systems have. Please install GNU make on other systems if you don't have it.

# Change to root because as normaluser we can not read the apache directorys
su -
<root-password>

cd ${BASE_SOURCES}/sourceforge.net-binaries-needed-software
cd php-4.0.5

# create the target directorys for apache module and standalone binary:
mkdir _apxs
mkdir _cgi
 
 
 

6.3.1. make/install Apache module version of PHP

Please note: DO NOT USE   --with-openssl=${PKG}/openssl/0.9.6

If I used this for PHP the apache webserver craches when accessing by ssl. The browser gives an Error message about security problems or network problems. In the mod_ssl logfiles is an entry about the browser uses an old pice of an encrypted certificate or uses an false en/decryption algorythm. Only after I recompile and install PHP without this option all is fine !!!
 

cd _apxs

../configure --prefix=${PKG}/php/4.0.5 --with-pgsql=${PKG}/postgres/7.1beta1 --enable-track-vars --enable-discard-path --with-config-file-path=${PKG}/apache/conf --with-ldap=${PKG}/openldap/2.0.7 --enable-rule=EAPI --with-zlib=${PKG}/zlib/1.1.3 --with-mcrypt=${LIBMCRYPT_PKG} --enable-debug --with-apxs=${PKG}/apache/1.3.17/sbin/apxs

make
make install

# Add lib pathes of openssl and openldap to system /etc/ld.so.conf
echo "${PKG}/openssl/0.9.6/lib" >> /etc/ld.so.conf
echo "${PKG}/openldap/2.0.7/lib" >> /etc/ld.so.conf
echo "${PKG}/zlib/1.1.3/lib" >> /etc/ld.so.conf
echo "${PKG}/libmcrypt/2.4.15/lib" >> /etc/ld.so.conf

ldconfig

cp php.ini-dist ${PKG}/apache/conf/php.init

# Add PHP4 Parsing to httpd.conf
# Outcomment PHP Parsing or add lines below:
#
# AddType application/x-httpd-php .php
# AddType application/x-httpd-php-source .phps
#
vi ${PKG}/apache/conf/httpd.conf

# Restart Apache Servef
${PKG}/apache/1.3.17/sbin/apachectl stop
${PKG}/apache/1.3.17/sbin/apachectl start

# Add test PHP4 Script for testing
echo "<? phpinfo(); ?>" >> ${PKG}/apache/share/htdocs/test_php4.php

# Browse to this url and you should see PHP4 informations !
http://localhost/test_php4.php

6.3.2. make/install standalone PHP binary

From Paul D. Smith and a little bit modified:

All the cron jobs in the sourceforge cronjobs directory are written in
php, so you need to build a standalone PHP to use them. As far as
we know at least some of them do important things (for example,
cronjobs/db_project_sums.php is the thing which updates the
counts of bugs, mailing lists, etc. that are displayed on the project
homepages; without running this these will always be 0).

cd _cgi

../configure --prefix=${PKG}/php/4.0.5 --with-pgsql=${PKG}/postgres/7.1beta1 --enable-track-vars --enable-discard-path --with-config-file-path=${PKG}/apache/conf --with-ldap=${PKG}/openldap/2.0.7 --enable-rule=EAPI --with-zlib=${PKG}/zlib/1.1.3 --with-mcrypt=${LIBMCRYPT_PKG}
 

make

cp php ${PKG}/php/4.0.5/bin

That should do it.

6.3.3. Test PHP script:

echo "#!${PKG}/php/4.0.5/bin/php" > test.php
echo "<?php> phpinfo(); <php?>" >> test.php

./test.php

Now you should get the PHP info output.

6.4. Apache SSL config and test:

cp ${BASE_SOURCES}/sf-genericinst/conf/httpd.conf.ssl.apache.1.3.17 ${PKG}/apache/conf/httpd.conf
${PKG}/apache/1.3.17/sbin/apachectl stop
${PKG}/apache/1.3.17/sbin/apachectl startssl

<certificate-passphrase>

Type "TEST"

https://localhost:8443/test_php4.php

Answer all questions with yes.
 

7. Sourceforge.net Installation: WebSite
 

7.1. Configure the Apache httpd.conf

Comment: DO NOT use different ports than 80 (http) and 443 (https) because this is today hardcoded in the code of sourceforge !!!

Copy our httpd.conf to apache installation:

cp ${BASE_SOURCES}/sf-genericinst/conf/httpd.conf.ssl.apache.1.3.17 ${PKG}/apache/conf/httpd.conf
 

7.2. Install php.ini file:

cd ${BASE_SOURCE}/sf-genericinst/conf
cp php.ini.php.4.0.5 ${PKG}/apache/conf/php.ini