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
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
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
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
For RPM, go to the apache and php websites at http://httpd.apache.org/
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'.
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.
Installing PHP under Windows
To install the IIS web-server under Windows, you'll need
your original Windows install disk, you'll also need the
professional version of your chosen Windows, if you have
home, standard or something similar then you'll have to
download the Windows version of apache from the apache
website and install that. Go into your windows control
panel, then open 'Add remove programs' click on 'Add/remove
Windows components' on the side menu, then from the dialog
that opens select 'IIS Internet information services' and
click next. Follow any further instructions.
If you had to install Apache2 for windows then this will
have been just as easy, by simply answering the questions
and clicking next.
Please remember to read all dialog boxes fully, especially
any that tell you where the root of your file system is.
Once you have your web-server installed, go to www.php.net
and download the Windows binaries for PHP and click on the
downloaded file to install.
Testing the installation
If everything has gone ok, find the root folder for your web
server. Under linux this will be something such as
'/var/srv' or '/usr/share/httpd/' or 'c:\inetpub' depending
on your installation platform, again I can't tell you
exactly where to look because this will be different
depending on your chosen install. One thing I will say, is
there is a chance that there may be an 'index.html' or
'Default.htm' in there somewhere which will help you decide
if it's your web server root directory.
Once you find this location, create a simple file called
'mytest.php' or 'testfile.php' and put the following lines
Save your file then try to run it using
http://localhost/mytest.php (or whatever file name you
chose) and if all goes well you should see the default php
A word of warning on choice of file name, it's very very
ill advised to call the file phpinfo.php or phptest.php
Automated cracking tools used by script kiddie's will very
often look for files like this to try and determine details
about a given server prior to attacking it further. A good
rule of thumb to follow is that if the file name is a common
one, and easily guessed then chances are there's a script
out there somewhere to find it.
In this article we looked at installing a web server and PHP
so you can start creating PHP scripts, I only wish I could
have been more specific in a lot of cases, but because of
the immense number of differences it's a very tricky thing
There are many pre made LAMP & WAMP packages that will
automate a lot of this stuff for you, and it is highly
recommended you use those. Manually installing this stuff
is not for the feint hearted and as long as I've been doing
this, the average Apache config file still gives even me
nightmares at times.
In the next article, we'll get stuck into some PHP properly.