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 :)

5 Comments

  1. Articles Repository » Blog Archive » PHP programming basics said,

    January 9, 2007 at 5:11 pm

    […] How to install PHP on windows How to install PHP on Linux How to install Apache on Windows PHP, MySQL, Apache installers […]

  2. Kevin said,

    January 18, 2007 at 9:24 pm

    Thank-you:

    I will try this later today

  3. Ondřej Válek said,

    January 19, 2007 at 1:37 am

    on Debian, forget about this old-fashioned and dangerous manual, and instead type in as root:
    # apt-get install libapache2-mod-php5
    wait few second, and you’re done, everything works. The same applies for other Linux distributions, only the package manager name would be different (yum, pacman, emerge, whatever …). Please forget for ever about those stupid “you need to compile it in Linux” ideas.

  4. Articles Repository » Blog Archive » Loops in PHP said,

    January 20, 2007 at 11:55 pm

    […] FAST PHP Tutorial (Part 1) How to Install PHP on Windows (Fast PHP Tutorial Part 2) How To Install PHP On LinuxHow To Install Apache on WindowsEasy Installers to Install PHP, MySQL, Apache on Windows< href=”http://fastcreators.com/article/2007/01/09/php-programming-basics/”>PHP Programming BasicsOperators in PHPDecision Making using IF-ELSE in phpDecision Making using PHP Switch Statement […]

  5. Articles Repository » Blog Archive » Detailed Guide On Arrays In PHP said,

    February 2, 2007 at 1:49 pm

    […] FAST PHP Tutorial (Part 1) How to Install PHP on Windows (Fast PHP Tutorial Part 2) How To Install PHP On Linux How To Install Apache on Windows Easy Installers to Install PHP, MySQL, Apache on Windows PHP Programming Basics Operators in PHP Decision Making using IF-ELSE in php Decision Making using PHP Switch Statement Loops In PHP […]

Post a Comment

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word