Getting PHP and Apache working together can sometimes be... well, challenging. This document helps to demystify some of the process. It covers both the Apache module and standalone binary versions of PHP.
There are two ways to install Apache/PHP: with everything compiled into one binary file, and with a whole bunch of compiled libraries that are loaded dynamically into the server as needed. For a production server, I don't recommend using the dynamic module method; it's slower, and less stable, in my opinion. I've always had nothing but problems with a bunch of dynamic modules in Apache; they have to be loaded in when it runs (and in a certain order), their versions can differ from what the server itself expects, etc. You never know what you're getting. When you compile everything yourself, and include just what you need and want, that means you're using your system libraries and your options and support; with a premade binary distribution, and/or a bunch of modules that are hard to keep track of, it's hard to know exactly what's going on. With the "compiling everything into one binary" method, there's only one file to keep track of... "httpd".
Doing it with premade binary distributions is initially faster (all you should have to do is untar Nisca, configure it, and use it), but you spend more time later on diagnosing why it doesn't work like it should than you would have just compiling it all yourself from scratch to begin with. :) As if that wasn't enough, you also have to add a line to your "php.ini" and/or "httpd.conf" files for every module you want loaded at runtime (all of them, that is). Plus, there are a few compile-time options that you won't find in any premade distribution. But if you want to just download some premade binaries and modules, feel free... :)
No matter how you eventually get it installed, you'll need several things installed to support the NISCA features you want. Below is a table of the applications and libraries you'll need to do different things. (All versions shown are minimums. Required packages are in red; optional packages are in that other color.)
Package | Version | Footnote |
---|---|---|
Apache | v 1.3.x | 1 |
MySQL | v 3.23.x | |
PHP | v 4.x.x | |
zlib | v 1.1.4 | |
UCD SNMP | v 4.2.3 | 2 |
libGD | v 1.8.x | 3 |
libJPEG | v 6b | 4 |
libPNG | v 2.1 | 5 |
The FreeType Library | v 1.x/2.x | 6 |
The Ming Library (for Flash) | v 0.2 | 7 |
The Zend Optimizer | ? | 8 |
NISCA also requires that Session Variables and Perl-Compatible Regular Expressions support be enabled in both the Apache and CGI binary versions of PHP. They're both enabled by default; please don't disable them. Another thing you'll have to do when you install PHP is double-check these settings in your "php.ini" file:
You'll also be happy to know that Nisca no longer uses the SNMP functions built into PHP. It calls the binaries that come with ucd-snmp directly, and could probably use other SNMP client binaries as well.
The order to do things in to install the proper PHP support is:
Now on to the specific sections for however you want to install it; compiling it all yourself, which is the method I both use and recommend, or installing from some kind of binary distribution, which there are several to choose from.
One thing common to all, though, is you no longer need to hack the PHP source code to enable SNMPv2c support, because Nisca no longer uses PHP's SNMP functions. What a relief.
This shouldn't take more than 150 meg of disk space even if you leave every source code directory installed and don't delete any of the source code archives you downloaded. (Hey, that's peanuts these days... :) Make sure you have enough room to do all this in!
Here are package-specific notes for everything listed above. These instructions should be followed in this order. You should probably do all this as root; I've never tried it as any other user. Make sure your umask is sane; "022" is a good value. Also, don't delete a package's source code directory after you've installed it; some packages need the right include files (*.h) to compile correctly.
If you already have one of these packages installed, just make sure it's a sufficiently-high version and skip its section below if so.
ZLIBLIB=../zlib ZLIBINC=../zlibFor example, my zlib source directory was "../zlib-1.1.2", so that's what I put on those two lines.
freetype
A special note about Freetype. I've traced most problems to trying to use
only version 2.x on your system. For some odd reason, I can't get libgd and
PHP to work together with only version 2.x; you have to compile libgd
using v1.x and its header files (that is, use "-DHAVE_LIBTTF" instead of
"-DHAVE_LIBFREETYPE" in libgd's Makefile) or PHP won't actually include
TrueType support in itself. If you have the v2.x libfreetype.* installed,
PHP will use that for gd's TTF support even though gd has v1.x in it, and
(miraculously) it works. So you would install FreeType v1.x, then install
FreeType v2.x, then compile libgd with FreeType v1.x support only, then
compile PHP with "--enable-gd-native-ttf". Completely counter-intuitive and
bizarre, but for some reason it works. shrug.
libgd
Note that although PHP now comes with a bundled version of libgd, it's version
2.x of libgd. I'm not sure I'd trust it... plus, I couldn't even get PHP to
compile with the bundled libgd. So do it this way if you experience trauma.
CFLAGS=-O -DHAVE_LIBXPM -DHAVE_LIBPNG -DHAVE_LIBJPEG -DHAVE_LIBTTF LIBS=-lgd -lpng -lz -ljpeg -lm -lttf INCLUDEDIRS=-I. -I/usr/local/include/freetype \ -I/usr/X11R6/include/X11 -I/usr/local/include
If you want to try out the "InnoDb" features of mysql, use "--with-innodb". This is supposed to make mysql faster and give it support for row-level locking and transactions (Nisca doesn't use transactions, but row-level locking makes it a lot faster). I use it myself; it's just wonderful. Really. :) Hey, I'd tell you if it were otherwise. I would.
PHP 4
Here's the big one. Let's take it slowly, starting with the Apache module
version.
./configure \ --with-apache=/path/to/src/of/apache-1.3.xx \ --with-mysql=/usr/local \ --with-zlib --enable-sysvshm=yes \ --enable-sysvsem=yes --with-config-file-path=/home/httpd/conf \ --disable-debug --enable-track-vars=yes \ --enable-magic-quotes=yesNote that the magic-quotes thing is rather necessary for proper Nisca operation; otherwise you'll have to go through the script and add stripslashes() and addslashes() functions in a billion places. You can leave it out here and enable it with this directive, in "php.ini":
magic_quotes_runtime = On
Then there are the optional commands. If using libgd, you'll need this:
--with-gdThat, though, will install the bundled libgd (version 2). To use the one you installed earlier, use this instead:
--with-gd=/usr/localYou might also need the following if you see a warning about libxpm when running configure. You'll only need it if using libgd, too.
--with-xpm-dir=/usr/X11R6To find the libjpeg header files, include this command, pointing to wherever you compiled libjpeg earlier:
--with-jpeg-dir=/path/to/src/of/libjpeg6bIf using the freetype library, include these as well:
--enable-gd-native-ttf --with-freetype-dir=/usr/localI did have to play with PHP's configuration a bit to get freetype to work; it requires some combination of the following PHP "./configure" directives:
--enable-gd-native-ttf --with-freetype-dir --enable-gd-imgstrttf --with-ttfTry the first two (which works for me) and if it doesn't work, play around with the options until you find a combination that works. Look in the "configure" output for a line saying:
checking whether to enable truetype string function in gd... yesIf it says "no" instead, it isn't working yet. Once it says "yes", it's ready.
./configure \ --with-apache=/usr/src/apache/apache_1.3.27 \ --with-xpm-dir=/usr/X11R6 --with-freetype-dir=/usr/local/lib \ --with-jpeg-dir=/usr/src/apache/libjpeg6b --with-png-dir=/usr/src/apache/libpng-1.0.11 \ --with-pdflib --with-swf --with-ftp --with-dba --with-bz2 \ --with-gd=/usr/local \ --enable-gd-native-ttf --with-curl \ --with-mysql=/usr/local --with-pgsql --with-ldap --with-imap \ --with-openssl=/usr/local/ssl --enable-sysvshm=yes --with-zlib \ --enable-sysvsem=yes --with-config-file-path=/home/httpd/conf \ --with-tiff-dir=/usr/lib \ --disable-debug --enable-track-vars=yes \ --enable-magic-quotes=yes --enable-bcmath=yes
Apache
There are many ways to install Apache. I'll give you the method I use.
It's probably not the method most people would recommend to you, but
it works great for me so this is how I do it.
CC="gcc" \ OPTIM="-DHARD_SERVER_LIMIT=512 -DDOCUMENT_LOCATION=\\\\\"/home/www\\\\\" -DDEFAULT_PATH=\\\\\"/bin:/usr/bin:/usr/local/bin\\\\\" -DACCEPT_FILTER_NAME=\\\\\"httpready\\\\\"" \ CFLAGS="-O2 -mcpu=pentiumpro -fomit-frame-pointer" \ SSL_BASE="/usr/local/ssl" \ ./configure \ "--prefix=/home/httpd" \ "--with-layout=Apache" \ "--server-uid=nobody" \ "--server-gid=nogroup" \ "--with-perl=/usr/local/bin/perl" \ "--suexec-docroot=/home/www" \ "--activate-module=src/modules/php4/libphp4.a" \ "--activate-module=src/modules/perl/libperl.a" \ "--enable-module=auth_db" \ "--enable-module=auth_anon" \ "--enable-module=log_agent" \ "--enable-module=log_referer" \ "--enable-module=rewrite" \ "--enable-module=vhost_alias" \ "--enable-module=unique_id" \ "--enable-module=digest" \ "--enable-module=usertrack" \ "--enable-module=expires" \ "--enable-module=cern_meta" \ "--enable-module=mmap_static" \ "--enable-module=headers" \ "--enable-module=info" \ "--enable-module=php4" \ "--enable-module=perl" \ "--enable-module=ssl" \ "--disable-rule=SSL_COMPAT" \ "$@"
zend_optimizer.optimization_level=1023 zend_extension="/usr/local/lib/ZendOptimizer.so" zend_optimizer.enable_loader = 0This last one shouldn't be used if you're using the commercial version of the Zend optimizer (the one that compiles actual binary versions of your PHP code), or are somehow otherwise creating precompiled, Zend-optimized PHP executables. Otherwise, please do use it, as it's responsible for a large part of my speed increase. :)
I've been referred to this page, which has full PHP RPMs for RedHat 6.x and 7.x. I haven't tried them myself, and probably won't, since I always try to make things myself unless it's, like, XFree86. But give it a try if you want to RPM your way to Nisca.