#native_company# #native_desc#

The ABC’s of PHP II – What do I need to make it work?

By Peter Shaw
on March 26, 2009

Welcome to part 2 in my 10 part series on the basics of the
PHP web scripting language, in the last part I introduced
you to PHP (and to your author) : In this part of the
series I’m going to show what you need in order to start
developing using PHP.

What platforms does PHP run on?

PHP runs on all the major computing platforms available
today, this includes all versions of windows, all the major
linux distro’s and a lot of specialist systems for devices
like the Cobalt Raq and a lot of embedded devices.
In this article however we will be concentrating on running
PHP under the Apache and IIS web servers, which between the
two covers approx 95% of the systems most people will have
access to.
Installing PHP under Linux
Most distro’s will have a ready made option at install time
to add PHP and Apache, or they will usually have an option
in your systems package installer, unfortunately there are a
number of different systems in use here and it’s not
practical to try and cover each one.
There is however light at the end of the tunnel. Most of
today’s distro’s fall into either a ‘Red Hat’ style system
or a ‘Debian’ style system. This means that there are 2
distinct package management systems making it quite easy to
add new software. Unfortunately you’ll have to use the
command line.
If you have a Red Hat system, then you’ll use the RPM
program to manage your packages, from your distro’s desktop
find the option to launch a ‘Konsole’ (KDE) or an
‘XTerminal’ or something similar. The option your looking
for may be labelled ‘Shell’ or ‘Command Line’.
Once you have a window open, you’ll very likely see
something that looks like:


Once you have this then your ready to start typing commands.
First off try just typing ‘rpm’ (without the quotes) and
press return.
If you get some kind of error message about rpm not being
found, then it’s likely that you have a Debian style system
in which case try typing ‘apt-get’ (again without the
Quotes) and press return. If you get a screen full of text,
then you have a Debian system.

Installing the Actual Software

Now that we know what kind of system we have, we can now use
the appropriate system commands.
We can check if we have PHP and/or apache installed by using the following :

$ rpm -q -a | grep php

Or for Debian/Ubuntu

$ dpkg -l | grep php

(dpkg is part of the ‘apt-get’ system)

On my 2 test systems, I get the following:

shawty@netfinity:~> rpm -q -a | grep php
shawty@netfinity:~> rpm -q -a | grep apache


shawty@poweredge:~$ dpkg -l|grep php
ii  libapache2-mod-php5  5.2.3-1ubuntu6.5   server-side, HTML-embedded scripting language
shawty@poweredge:~$ dpkg -l|grep apache
ii  apache2              2.2.4-3ubuntu0.1   Next generation, scalable, extendable web se

The above commands will list all software in the machine,
but only show those entries which match (or grep) the search
term. As a result you can see that I have both apache and
mod_php installed on both machines. If you don’t have them
already installed then you can normally do the following to
add them??
For RPM, go to the apache and php websites at http://httpd.apache.org/
and http://www.php.net/
respectively. Download the rpm package for your particular
linux distro, save this to a folder on your linux system
where you can access it from your terminal window. Once you
have downloaded the file switch to your terminal and type
‘rpm -i <filename>’ replacing the <filename>
with the name of the file you downloaded.
If all goes well you should find that all installs ok, and
that RPM resolves any other missing packages. I would
however strongly suggest that you use that to install
‘apache2’ and ‘mod_php5’.
Under Debian/Unbuntu things are so much simpler:

$ sudo apt-get install apache2
$ sudo apt-get install libapache2-mod-php5

The package names ‘libapache2-mod-php5’ and ‘apache2’ may be
different, depending on the distro’s naming rules, again if
you know how to use your package manager, then it’s strongly
advised that you use that.

Comment and Contribute

Your comment has been submitted and is pending approval.


Peter Shaw