Howto Install PHP on Linux ?

Dec-21st-2008

# PHP Installation.

[root@map007 root]# cd /usr/local/src
[root@map007 src]# wget http://www.php.net/distributions/php-4.4.6.tar.gz

# Unpack the Source Code

[root@map007 src]# tar zxf php-4.4.6.tar.gz
[root@map007 src]# cd php-4.4.6

# Build and Install PHP


FOR APACHE 1.3.x:

[root@map007 src]# ./configure –prefix=/usr/local/php –with-apxs=/usr/local/apache/bin/apxs –with-mysql=/usr/local/mysql –enable-memory-limit=yes –enable-debug=no –enable-track-vars –enable-ftp

Use the configure line below if you require more features.
[root@map007 src]# ./configure –prefix=/usr/local/php –with-apxs=/usr/local/apache/bin/apxs –with-mysql –enable-memory-limit=yes –enable-debug=no –enable-track-vars –enable-ftp –enable-calendar –with-zlib –with-gd –with-jpeg-dir=/usr/local –with-png-dir=/usr/local –with-tiff-dir=/usr/local –with-xml –enable-wddx –with-xmlrpc –enable-gd-native-ttf –with-ttf –enable-exif –with-freetype-dir=/usr/local

FOR APACHE 2.x:

[root@map007 src]# ./configure –prefix=/usr/local/php –with-apxs2=/usr/local/apache/bin/apxs –with-mysql=/usr/local/mysql –enable-memory-limit=yes –enable-debug=no –enable-track-vars –enable-ftp

**************************************************************************************************************

if you get “lex” Error
you need to install: flex

[root@map007 src]# make
[root@map007 src]# make install
[root@map007 src]# cp php.ini-dist /usr/local/php/lib/php.ini
[root@map007 src]# ln -s /usr/local/php/bin/php /sbin/php

I like to keep my config files all together in /etc. I set up a symbolic link like this:

[root@map007 src]# ln -s /usr/local/php/lib/php.ini /etc/php.ini

To ensure your PHP files are properly interpreted, and not just downloaded as text files, remove the # at the beginning of the lines which read:

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

If the AddType lines above don’t exist, manually enter them (without the leading # of course) after the line

AddType application/x-tar .tgz

or anyplace within the <IfModule mod_mime.c> section of httpd.conf

If you wish to use other/additional extensions/filetypes for your PHP scripts instead of just .php, add them to the AddType directive:

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

An example: if you wanted every single HTML page to be parsed and processed like a PHP script, just add .htm and .html:

AddType application/x-httpd-php .php .htm .html

There will be a bit of a performance loss if every single HTML page is being checked for PHP code even if it doesn’t contain any. But if you want to use PHP but be “stealthy” about it, you can use this trick.

Add index.php to the list of valid Directory Index files so that your “default page” in a directory can be named index.php.

<IfModule mod_dir.c>
DirectoryIndex index.php index.htm index.html
</IfModule>

You can add anything else you want here too. If you want foobar.baz to be a valid directory index page, just add the .baz filetype to the AddType line, and add foobar.baz to the DirectoryIndex line.

Restart Apache :

[root@map007 src]# service httpd restart

Uninstalling PHP :-

[root@server root]# rm -rf /usr/local/php
[root@server root]# rm -rf /sbin/php

******************************************************************************************************************

Enjoy Linux !!!

Mega World News Facebook Twitter Myspace Friendfeed Technorati del.icio.us Digg Google Yahoo Buzz StumbleUpon Weekend Joy

Add A Comment

*