News:

Build a stunning handcrafted website with IT Acumens

Main Menu

PHP Installation In Linux

Started by sivaji, Jan 11, 2008, 01:05 PM

Previous topic - Next topic

sivaji

Linux Installation

Installing PHP

As mentioned above, PHP is not really a program in and of itself. Instead, it's a plug-in module for your Web server (probably Apache). There are actually three ways to install the PHP plug-in for Apache:
     
       As a CGI program that Apache runs every time it needs to process a PHPenhanced Web page
       As an Apache module compiled right into the Apache program
       As an Apache module loaded by Apache each time it starts up

The first option is the easiest to install and set up, but it requires Apache to launch PHP as a program on your computer every time a PHP page is requested.This activity can really slow down the response time of your Web server, especially if more than one request needs to be processed at a time.

The second and third options are almost identical in terms of performance, but since you're likely to have Apache installed already, you'd probably prefer to avoid having to download, recompile, and reinstall it from scratch. For this reason, we'll use the third option.

To start, download the PHP Complete Source Code package from http://www.php.net/downloads.php. At the time of this writing, PHP 4 has become well-established as the version of choice; however, the newly released PHP 5 is gaining ground quickly. I'll be covering the installation of PHP 5.0 here, but the same steps should work just as well with PHP 4.

The file you downloaded should be called php-version.tar.gz. To begin, we'll extract the files it contains (the shell% prompt is included to represent that you can run these steps without being logged in as root):

shell%tar xfz php-version.tar.gz
shell%cd php-version

To install PHP as a loadable Apache module, you'll need the Apache apxs program. This comes with most versions of Apache (both versions 1.3 and 2.0), but if you're using the copy that was installed with your distribution of Linux, you may need to install the "Apache development" package to access Apache apxs.
You should be able to install this package by the means provided by your software distribution. For example, on Debian Linux, you can use apt-get to install it as follows (you'll have to log in as root first):

shell#apt-get install apache-dev

By default, Fedora Core, RedHat, and Mandrake will install the program as /usr/sbin/apxs, so if you see this file, you know it's installed. If you've installed Apache by hand, it will probably be /usr/local/apache/bin/apxs.

For the rest of the install procedure, you'll need to be logged in as the root user so you can make changes to the Apache configuration files. The next step is to configure the PHP installation program by telling it which options you want to enable, and where it should find the programs it needs to know about (such as Apache and MySQL). Unless you know exactly what you're doing, simply type the command like this (all on one line):

shell#./configure --prefix=/usr/local/php
--with-apxs=/usr/sbin/apxs
--with-mysql=/usr/local/mysql
--enable-magic-quotes

Replace /usr/sbin/apxs and /usr/local/mysql with the location of your apxs program and the base directory of your MySQL installation, respectively.

         Apache 2.0

         If you're using Apache 2.0 or later, you need to type --with-apxs2=... instead of --with-apxs=...
         to enable support for Apache 2.0. As of this writing, this support is still experimental and is not   
         recommended for production sites. As a result of the ongoing work on this front, you may need to
        download the latest pre-release (unstable) version of PHP to get it working with the latest release
        of Apache 2.0, but it's worth trying the stable release version first.
       
        For full instructions on how to download the latest pre-release version of PHP, see   
        http://www.php.net/anoncvs.php.

Again, check for any error messages and install any files it identifies as missing. On Mandrake 8.0, for example, it complained that the lex command wasn'tfound. I searched for "lex" in the Mandrake package list and it came up with flex, which it described as a program for matching patterns of text used in many
programs' build processes. Once that was installed, the configuration process went without a hitch. After you watch several screens of tests scroll by, you'll be returned to the command prompt. The following two commands will compile and then install PHP. Take a coffee break: this will take some time.

shell#make
shell#make install

Upon completion of make install, PHP is installed in /usr/local/php (unless you specified a different directory with the --prefix option of the configure script above), with one important exception—its configuration file, php.ini.PHP comes with two sample php.ini files called php.ini-dist and php.inirecommended. Copy these files from your installation work directory to the /usr/local/php/lib directory, then make a copy of the php.ini-dist file and call it php.ini:

shell#cp php.ini* /usr/local/php/lib/
shell#cd /usr/local/php/lib
shell#cp php.ini-dist php.ini

You may now delete the directory from which you compiled PHP—it's no longer needed.

We'll worry about fine-tuning php.ini shortly. For now, we need to tweak Apache's configuration to make it more PHP-friendly. Open your Apache httpd. conf configuration file (usually under /etc/apache/ or /etc/httpd/ if you're using your Linux distribution's copy of Apache) in your favorite text editor.

Next, look for the line that begins with DirectoryIndex. In certain distributions, this may be in a separate file called commonhttpd.conf. This line tells Apache which file names to use when it looks for the default page for a given directory. You'll see the usual index.html, but you need to add index.php to the list if it's
not there already:

DirectoryIndex index.html index.php

Finally, go right to the bottom of the file (again, this should go in commonhttpd. conf if you have such a file) and add these lines to tell Apache which file extensions should be seen as PHP files:

AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps

That should do it! Save your changes and restart your Apache server. If all things go according to plan, Apache should start up without any error messages. If you run into any trouble, the helpful folks in the SitePoint Forums[14] (myself included) will be happy to help.
Am now @ Chennai