want to join us? register, it's easy | help

FAST PHP Tutorials

How To Install PHP on Linux

Dear Students,

Today we will learn how can we install PHP on Linux. Lets go through these steps,

You must be logged in with the admin account to install PHP so login as root

We need to get installation files from the PHP Website and save it on your hard drive. You can download it to your download directory where you download all the files from internet or if you have not made one yet then lets create a download directory

mkdir /usr/local/download

Now we will download installation file from php ftp website to our download directory

cd /usr/local/download
ftp ftp.php.net
cd pub/distributions
bin
get php-5.2.0.tar.gz
bye

the file name may differ according to the PHP version you are downloading. I have downloaded the latest stable release of PHP i.e PHP 5.2.0

Now we are ready to install PHP. Lets go to the download directory

cd /usr/local/download

Now use this tar command

tar xzf php-5.2.0.tar.gz -C ../etc

this command will install PHP from download directory to /usr/loca/etc/

Did you see the name of installation folder in /etc/ directory? arrrgh! Isn't it ugly? Lets rename it to something good,

cd /usr/local/etc
ln -s php-5.2.0 php

now it is acceptable the next step is to compile PHP with this command

./configure -with-apache=../httpd -with-config-file-path=/www/conf -enable-track-vars

now make a PHP executable with

make

which will take some time and then install it with

make install

do you think we are done? well, unfortunately no, we need to add php module to apache with this,

cd ../httpd
 ./config.status -activate-module=src/modules/php5/libphp5.a

then

make

then stop apache and install new binaries,

bin/apachectl stop
make install

restart apache now

bin/apachectl start

if you have read my article - How to install php on windows then you must know by now that we have to change move the php.ini file to the proper location

cd ../php
cp php5.ini-dist /www/conf/php5ini

and remove-dist from its name.

Do you think we are done with PHP installation on Linux? well, fortunately yes.. we are now, you can make a test page with

<?php echo "PHP ! I'm gonna get you.."; ?>

and browse this page if you see what you wrote your php is working fine otherwise it has some problem, test all the steps again and if still stuck with it ask for help here :)