Installing Apache and PHP on Linux/Unix
 
1. Unzip and untar Apache and PHP:
%>gunzip httpd-2_X_XX.tar.gz
%>tar xvf httpd-2_X_XX.tar
%>gunzip php-XX.tar.gz
%>tar xvf php-XX.tar
2. Configure and build Apache. At a minimum, you’ll want to pass two options. The first
option, --enable-so, tells Apache to enable the ability to load shared modules. The
second, --with-mpm=worker, tells Apache to use a threaded multiprocessing module
known as worker. Based on your particular needs, you might also consider using the
multiprocessing module prefork. See the Apache documentation for more information
regarding this important matter.
%>cd httpd-2_X_XX
%>./configure --enable-so --with-mpm=worker [other options]
%>make
3. Install Apache:
%>make install
4. Configure, build, and install PHP (see the section “Customizing the Unix Build” or
“Customizing the Windows Build,” depending on your operating system, for information
regarding modifying installation defaults and incorporating third-party
extensions into PHP):
%>cd ../php-X_XX
%>./configure --with-apxs2=/usr/local/apache2/bin/apxs [other options]
%>make
%>make install
5. Copy the php.ini-dist file to its default location and rename it php.ini. The php.ini file
contains hundreds of directives that are responsible for tweaking PHP’s behavior. The
later section “Configuration” examines php.ini’s purpose and contents in detail. Note
that you can place this configuration file anywhere you please, but if you choose a nondefault
location, then you also need to configure PHP using the --with-config-filepath
option. Also note that there is another default configuration file at your disposal,
php.ini-recommended. This file sets various nonstandard settings and is intended to
better secure and optimize your installation, although this configuration may not be
fully compatible with some of the legacy applications. Consider using this file in lieu of
php.ini-dist.
%>cp php.ini-recommended /usr/local/lib/php.ini
6. Open the httpd.conf file and verify that the following lines exist. (The httpd.conf file is
located at APACHE_INSTALL_DIR/conf/httpd.conf.) If they don’t exist, go ahead and add them. Consider adding each alongside the other LoadModule and AddType entries,
respectively.
LoadModule php5_module modules/libphp5.so
AddType application/x-httpd-php .php
Believe it or not, that’s it! Restart the Apache server with the following command:
%>/usr/local/apache2/bin/apachectl restart
Now proceed to the section “Testing Your Installation.”
 
Installing Apache and PHP on Windows
 
1. Start the Apache installer by double-clicking the apache_X.X.XX-win32-x86-no_ssl.msi
icon.
2. The installation process begins with a welcome screen. Take a moment to read the
screen and then click Next.
3. The License Agreement is displayed next. Carefully read through the license. Assuming
that you agree with the license stipulations, click Next.
4. A screen containing various items pertinent to the Apache server is displayed next. Take a moment to read through this information and then click Next.
5. You will be prompted for various items pertinent to the server’s operation, including the Network Domain, Server Name, and Administrator’s Email Address. If you know this
information, fill it in now; otherwise, just use localhost for the first two items, and put
in any e-mail address for the last. You can always change this information later in the
httpd.conf file. You’ll also be prompted as to whether Apache should run as a service
for all users or only for the current user. If you want Apache to automatically start with
the operating system, which is recommended, then choose to install Apache as a service for all users. When you’re finished, click Next.
6. You are prompted for a Setup Type: Typical or Custom. Unless there is a specific reason
you don’t want the Apache documentation installed, choose Typical and click Next.
Otherwise, choose Custom, click Next, and, on the next screen, uncheck the Apache
Documentation option.
7. You’re prompted for the Destination folder. By default, this is C:\Program Files\Apache
Group. Consider changing this to C:\, which will create an installation directory
C:\Apache2\. Regardless of what you choose, keep in mind that the latter is used here
for the sake of convention. Click Next.
8. Click Install to complete the installation. That’s it for Apache. Next you’ll install PHP.
9. Unzip the PHP package, placing the contents into C:\php5\. You’re free to choose
any installation directory you please, but avoid choosing a path that contains spaces.
Regardless, the installation directory C:\php5\ will be used throughout this chapter for
consistency.
10. Make the php5ts.dll file available to Apache. This is most easily accomplished simply
by adding the PHP installation directory path to the Windows Path. To do so, navigate to
Start ➤ Settings ➤ Control Panel ➤ System, choose the Advanced tab, and click the
Environment Variables button. In the Environment Variables dialog box, scroll through
the System variables pane until you find Path. Double-click this line and, in the Edit
System Variable dialog box, append C:\php5 to the path
11. Navigate to C:\apache2\conf and open httpd.conf for editing.
12. Add the following three lines to the httpd.conf file. Consider adding them directly
below the block of LoadModule entries located in the bottom of the Global Environment
section.
LoadModule php5_module c:/php5/php5apache2.dll
AddType application/x-httpd-php .php
PHPIniDir "C:\php5"
13. Rename the php.ini-dist file php.ini and save it to the C:\php5 directory. The php.ini
file contains hundreds of directives that are responsible for tweaking PHP’s behavior. The later section “Configuration” examines php.ini’s purpose and contents in detail. Note that you can place this configuration file anywhere you please, but if you choose a nondefault location, then you also need to configure PHP using the --with-config-file-path option. Also note that there is another default configuration file at your disposal,
php.ini-recommended. This file sets various nonstandard settings, and is intended to
better secure and optimize your installation, although this configuration may not be
fully compatible with some of the legacy applications. Consider using this file in lieu
of php.ini-dist.
14. If you’re using Windows NT, 2000, or XP, navigate to Start ➤ Settings ➤ Control Panel ➤Administrative Tools ➤ Services.
15. Locate Apache in the list, and make sure that it is started. If it is not started, highlight the label and click Start the service, located to the left of the label. If it is started, highlight
the label and click Restart the service, so that the changes made to the httpd.conf file
take effect. Next, right-click Apache and choose Properties. Ensure that the startup type
is set to Automatic. If you’re still using Windows 95/98, you need to start Apache manually via the shortcut provided on the Start menu.
Testing Your Installation
The best way to verify your PHP installation is by attempting to execute a PHP script. Open a
text editor and add the following lines to a new file. Then save that file within Apache’s htdocs
directory as phpinfo.php:
<?php
phpinfo();
?>
Now open a browser and access this file by typing the appropriate URL:
http://localhost/phpinfo.php