Running Linux, 5th Edition - Matthias Kalle Dalheimer [455]
In addition to running PHP4 as a module, you can run it as a CGI program started by the web server, at the expense of some additional overhead. When running PHP as a CGI program, each new page that contains PHP code requires starting a new instance of the PHP interpreter, which in turn requires creating a new process and
Figure 25-3. Administering MySQL databases with phpMyAdmin
loading the PHP interpreter into this process. When the interpreter is finished creating the page, its process ends, the memory is freed, all file handles are closed, and all database connections are shut down.
As a web server module, the PHP interpreter becomes part of the web server and is always loaded into memory. In addition, it can keep resources such as database connections alive across different pages, which can bring huge performance benefits.
All big-ticket PHP sites use PHP as a module, mostly because of the better performance it affords.
PHP4 as an Apache Module
As we have already said, running the PHP interpreter as a web server module is best for getting good performance. Today, most distributions (including Slackware, Debian, SUSE, and Red Hat) ship both Apache and the PHP4 module for Apache, so it is generally not necessary to build the PHP4 module yourself. It may be a good idea to do so anyway, however.
Because of its vast amount of functionality, the PHP4 module needs quite a number of additional libraries or modules. If you install the module from your installation CDs, the installation program will have automatically installed the necessary modules. However, the modules shipped with distributions are typically loaded with functionality to satisfy all needs and tastes. The result can be a system that's heavier and slower than it needs to be.
Thus, the advantage of building PHP4 by yourself is that you can decide which functionality you want to go into the module. Check the documentation to see which additional libraries you might need to install.
Since we firmly believe that you should know what goes on behind the scenes, even if you use the more comfortable ready-made solutions, we will give you some hints regarding how to work from scratch and how the pieces work together.
To load the PHP4 module into the Apache web server at runtime, you need to have the Apache module mod_so. You can check whether this module is presented by issuing:
owl$ httpd -l
Compiled-in modules:
http_core.c
mod_so.c
If this module is not available, please check whether you may have missed installing some of the additional Apache packages in your distribution. If you have built Apache from scratch, follow the documentation to get this module.
It is also possible to compile the PHP4 module directly into Apache, but this requires some very intertwined building of both Apache and PHP4 and does not really give you a big advantage, so we won't cover this here.
Now we need to build PHP and make a dynamic shared object (DSO) out of it. Luckily, this is not as involved as it sounds. Download PHP4 from http://www.php.net/download.php. You will end up with a package called php-4.4.0.tar.gz (the actual version number may differ slightly). Unpack the tar file and configure PHP with:
owl$ ./configure \
--with-mysql=/usr/lib/mysql\
--with-ldap=yes\
--with-gd=yes\
--with-zlib=yes\
--with-config-file-path=/etc/\
--with-apxs=/usr/lib/apache/apxs\--enable-versioning\
--enable-track-vars\
--enable-thread-safety
You can read about numerous additional options in the extensive PHP documentation, but for starters, this will do. Note that you might need to replace some of the paths here with the actual locations on your system. After configure is finished, do a make and then a make install to install PHP (you may need to do the make install as root).
Next, edit the httpd.conf file, Apache's configuration file. If you have installed Apache from your installation CDs, chances are the following lines are already there and you just need to uncomment them. In any case, you should have the following lines in your