Installing Apache and PHP on Linux

This section guides you through the process of Installing Apache and PHP from source.

Targeting the Linux platform for Installing Apache. You need a respectable ANSI-C compiler and build system, two items that are available through all of the major distributions’ package managers. In addition, PHP requires both Flex (http://flex.sourceforge.net) and Bison (www.gnu.org/software/bison/bison.html), while Apache requires at least Perl version 5.003. Finally, you’ll need root access to the target server to complete the build process. For the sake of convenience, before beginning the installation process, consider moving both packages to a common location such as /usr/src/. The Installing Apache process follows:

1. Unzip and untar Apache and PHP. In the following code, the X represents the latest stable version numbers of the distributions you downloaded in the previous section:

%>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 Installing Apache. At a minimum, you’ll want to pass the option — enable-so, which tells Apache to enable the ability to load shared modules:

%>cd httpd-2_X_XX
%>./configure --enable-so [other options]
%>make

3. Install Apache (which you will need to do as the system superuser):

%>make install

4. Configure, build, and install PHP (see the “Configuring PHP at Build Time on Linux” section for information regarding modifying installation defaults and incorporating third-party extensions into PHP). In the following steps, APACHE_INSTALL_DIR is a placeholder for the path to Apache’s installed location, for instance /usr/local/apache2:

%>cd ../php-X_XX
%>./configure --with-apxs2=APACHE_INSTALL_DIR/bin/apxs [other options]
%>make
%>make install

5. PHP comes bundled with a configuration file that controls many aspects of PHP’s behavior. This file is known as php.ini, but it was originally named php.ini-dist. You need to copy this file to its appropriate location and rename it php.ini. The later section Configuring PHP” 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, 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.inidist. To use this file, execute the following command to Installing Apache:

%>cp php.ini-recommended /usr/local/lib/php.ini

6. Open Apache’s configuration file, known as httpd.conf, 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 Add Type 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/apache/bin/apachectl restart

Proceed to the “Testing Your Installation” section.

■ Tip The AddType directive in Step 6 binds a MIME type to a particular extension or extensions. The .php extension is only a suggestion; you can use any extension you like, including .html, .php5, or even .jason. In addition, you can designate multiple extensions simply by including them all on the line, each separated by a space. While some users prefer to use PHP in conjunction with the .html extension, keep in mind that doing so will ultimately cause the file to be passed to PHP for parsing every single time an HTML file is requested. Some people may consider this convenient, but it will come at the cost of performance to Installing Apache .

andcombd