Installation of Apache and PHP in UNIX Operating System


As previously we have discussed about Installing Libraries and Installing MySQL on UNIX so that in this article we will finally discuss about the last necessary installation process in which we will assist you about how you can install or deploy Apache and PHP in UNIX operating system. 

Installing Apache and PHP

PHP can be integrated with the Apache Web server in one of two ways: as a dynamic module loaded into the web server at run time, or as a static module integrated into the Apache source tree at build time. Each alternative has advantages and disadvantages:

■ Installing PHP as a dynamic module makes it easier to upgrade your PHP build at a later date, as you only need to recompile the PHP module and not the rest of the Apache Web server. On the flip side, with a dynamically loaded module, performance tends to be lower than with a static module, which is more closely integrated with the server.

■ Installing PHP as a static module improves performance because the module is compiled directly into the Apache source tree. However, this close integration has an important drawback: if you ever decide to upgrade your PHP build, you will need to reintegrate the newer PHP module into the Apache source tree and recompile the Apache Web server.

This section shows you how to compile PHP as a dynamic module that is loaded into the Apache server at run time.

1. Ensure that you are logged in as the system’s root user.
[user@host]# su – root

2. Extract the contents of the Apache source archive to your system’s

temporary directory.
[root@host]# cd /tmp
[root@host]# tar -xzvf /tmp/apache_1.3.31.tar.gz

3. To enable PHP to be loaded dynamically, the Apache server must be compiled with Dynamic Shared Object (DSO) support. This support is enabled by passing the –enable-module=so option to the Apache configure script, as shown here:

[root@host]# cd /tmp/apache_1.3.31
[root@host]# ./configure –prefix=/usr/local/apache ↵
–enable-module=so

You should see a few screens of output (Below Figure has a sample) as configure configures and sets up the variables needed for the compilation process.

image

4. Now, compile the server using make and install it to the system using make install.

[root@host]# make
[root@host]# make install

Below Figure  illustrates what you might see during the compilation process. Apache should now be installed to /usr/local/apache/.

image

5. Next, proceed to compile and install PHP. Begin by extracting the contents of the PHP source archive to your system’s temporary directory.

[root@host]# cd /tmp
[root@host]# tar -xzvf /tmp/php-5.0.1.tar.gz

6. This step is the most important in the PHP installation process. It involves sending arguments to the PHP configure script to control the final capabilities of the PHP module. These command-line parameters specify which PHP extensions should be activated, and they also tell PHP where to find the supporting libraries needed by those extensions.

[root@host]# cd /tmp/php-5.0.1
[root@host]# ./configure –prefix=/usr/local/php5 ↵
–with-apxs=/usr/local/apache/bin/apxs –with-libxml- ↵

dir=/usr/local/lib –with-zlib –with-zlib-dir=/usr/local/lib ↵
–with-mysql=/usr/local/mysql

Here is a brief explanation of what each of the previous arguments does.

■ The –with-apxs argument tells PHP where to find the Apache’s APXS (APache eXtenSion) script. This script simplifies the task of building and installing loadable modules for Apache.

■ The –with-libxml-dir and –with-zlib-dir arguments tell PHP where to find the libxml2 and zlib libraries (the installation procedure for these libraries is discussed in the section entitled “Installing Supporting Libraries”).

■ The –with-mysql argument activates PHP’s MySQL extension and tells PHP where to find the local MySQL installation. The configure script uses this information to find the system’s MySQL client libraries and to add MySQL support to PHP.

■ The –with-zlib argument activates the ZLIB library in the final
PHP build, making data compression services available to all extensions. Below Image will illustrates what you will see during the configuration process.

image

The PHP configuration process is extremely sophisticated, enabling you to control many aspects of PHP’s behavior. To see a complete list of available options, use the command ./configure –help, and visit http://www.php.net/manual/en/configure.php for detailed explanations of what each option does.

7. Next, compile and install PHP using make and make install:

[root@host]# make
[root@host]# make install

Below Figure illustrates what you might see during the compilation process. PHP should now be installed to /usr/local/php5/.

image

8. The next step in the installation process consists of configuring Apache to correctly recognize requests for PHP pages. This is accomplished by opening the Apache configuration file, httpd.conf (which is found in the conf/ subdirectory of the Apache installation directory), in a text editor and adding the following line to it. AddType application/x-httpd-php .php

9. Save the changes to the file. Also, check to make sure this line appears somewhere in the file:

LoadModule php5_module libexec/libphp5.so

The PHP installation process should automatically add this line to the file, but it has been known to fail. If you don’t see it, add it yourself.

10. Start the Apache server by manually running the apachectl script.

[root@host]# /usr/local/apache/bin/apachectl start

Apache should start up normally. Below picture demonstrates what you will see as the server starts up. Once installation is successfully completed and the server has started, move down to the section entitled “Testing Apache and PHP” to verify that all is functioning as it should.

image


Leave a Reply