Home Accessibility Courses Diary The Mouth Forum Resources Site Map About Us Contact
For 2021 - online Python 3 training - see ((here)).

Our plans were to retire in summer 2020 and see the world, but Coronavirus has lead us into a lot of lockdown programming in Python 3 and PHP 7.
We can now offer tailored online training - small groups, real tutors - works really well for groups of 4 to 14 delegates. Anywhere in the world; course language English.

Please ask about private 'maintenance' training for Python 2, Tcl, Perl, PHP, Lua, etc.
Sourcing, installing and configuring PHP

PHP can be used either as a language that's embedded within web pages, to be run on the web server, or stand alone. Since it was designed as an embedded language, that's much the most common use and we'll look at its installation and configuration in that way in this module. It turns out that if you install PHP to be embedded in a web server, you can choose to get the stand alone program too!


1. PHP comes bundled with most Linux distributions. It won't necessarily be the most recent version (bundled software tends to provide the latest stable version that was available at the time that the bundle was sent for final testing), but it will be a version that has been somewhat configured to work with your installation.

2. Download the source code of PHP from www.php.net - compile and install your own version on your Linux or Unix system. The www.php.net site does NOT provide binaries for Linux / Unix, stating that it come with most operating system downloads anyway these days.

3. Download windows binaries from www.php.net. There are two versions - a .zip package (about 6 Mbytes in the current release) and an installer (about 1 Mbyte). You are strongly encouraged to use the .zip version; the installer version is restricted in what it provides - "CGI Only" it says, and the documentation says "We consider CGI installations of PHP to be suicidal".

4. As from release 10.1.x of Mac OSX, PHP was bundled as a part of the operating system - however, it is configured off by default.

If you have another requirement, the www.php.net site will point you at binaries for the less common operating systems, and there's plenty of discussions, documentation and FAQs available.

Before you source your PHP, consider very carefully which version you need.

UPDATE - April 2006. Latest versions are 4.4.x and 5.1.x - use 4.4.x for older compatibility and 5.1.x for new installations. Version 5.0 has a much improved OO model and is almost totally compatible with version 4 (but do note - "almost"). I'll leave my older notes following this paragraph in case you need to refer back to older versions.

Version 3 of PHP is now very old, and there are major speed and functionality improvements in version 4. Version 4.0 (up to version 4.0.6) is probably too old to recommend these days too.

Version 4.1.2 is configured (by default) to accept form variables both as globals and in $_GET and $_POST arrays. Globals are the way it always "was" done, but are less secure if the programmer doesn't really know about these things, so the $_GET and $_POST arrays were introduced in 4.1.0. You might choose 4.1.2 if you want a well established, stable PHP which is compatible with older and newer scripts

Version 4.2.3 ONLY accepts form variables via $_GET and $_POST by default, but it can be configured to accept the older form too.

Version 4.3.0 involved major internal changes. It was release in December 2002. There are a few compatibility and interfacing issues with release 4.3.0, and at the time of writing you might wish to stick with the previous release if you have a major software system already developed on another (older) server.

Note that PHP is a language with a very active developer community, and so you can expect new releases much more frequently than for other languages. You won't necessarily always want to upgrade to the latest release every time one comes out.


Before you install PHP to provide that executable content you want in your web page, you need to install a web server!

PHP works with a variety of web server, including Microsoft's IIS (Internet Information Server) and PWS (Personal Web Server), Xitami, Netscape servers, O'Reilly website pro, Sambar, OmniHTTPd, and Badblue. Far and away the most popular server is the Open Source Apache web server - this comes as standard with Linux, with OSX and with most other Unixes. It can be downloaded for Windows from www.apache.org, and being open source you don't pay a license fee!

Even if you're installing PHP on your local Windows machine that already has PWS or IIS on it, we suggest that you install Apache - especially if you're using you local machine as a test and development system; you're likely to find your ISP running Apache as the server of their choice. Installation and configuration of Apache is covered in other texts.

We'll look at some examples of PHP installation ...


1. Download the .zip binary distribution of PHP for Windows from www.php.net

2. Unpack (unzip) the distribution file into a directory called c:\php ... you'll end up with a subdirectory there called
or similar.

3. You have two files to copy

 a) The file php4ts.dll should be copied to the sapi
 subdirectory, where there should already by a file
 called php4apache.dll and one called
 b) The file php.ini-dist should be copied to the system
 directory - usually c:\windows, and renamed to php.ini

4. Edit the Apache configuration file to include instructions for it to provide PHP support when restarted. The file is likely to be
 c:\Program Files\Apache Group\Apache2\conf\httpd
and you need to add the following onto the end:

LoadModule php4_module c:/php/php-4.3.0-win32/sapi/php4apache2.dll
AddType application/x-httpd-php .php .php4

(note - you can select other / different file extensions for PHP if you wish, and you should load php4apache.dll not php4apache2.dll if you're running Apache 1.3)

5. Restart Apache

6. Create a file in the htdocs directory on the web server called test.php4, and type the following into it:
 <?php phpinfo(); ?>

7. Visit the page with a browser and you should see ...

[Picture 1]

Now that you have basic functionality working, you'll probably want to go on and make some changes in the php.ini file to enable emailing from your server, and to allow the session functions to work. Both these features will NOT work unless you change the configuration file - you have been warned ;-)


Although PHP is provided as part of the Apple operating system distribution, it's switched off by default ... first stage to getting it running is to turn on the web server from your system preferences (under the "sharing" submenu).

Then edit the apache configuration file at /private/etc/httpd/httpd.conf, taking the # character off the start of the two lines that mention php. (If you find one with a capital P, change it to a lower case p). Also add the following line at the end of the configuration file:
 AddType application/x-httpd-php .php4

Stop and restart the server ("sharing" submenu of system preferences), and create and visit a test page containing
 <?php phpinfo(); ?>
and you should see:

[Picture 2]


Runtime PHP configuration is controlled by the php.ini file that you may have had to make minor changes to during the installation process. If you're going to be running a public facing server, or if you're providing a service that's more than just a test and development installation, we suggest that you spend a few minutes going through some of the pertinent settings in this file.

The syntax of the file is straightforward. Whitespace and Lines beginning with a semicolon are silently ignored. Section headers (e.g. [Foo]) are also silently ignored, even though they might mean something in the future.

Directives are specified using the following syntax:
 directive = value
Directive names are *case sensitive* - foo=bar is different from FOO=bar.

The value can be a string, a number, a PHP constant (e.g. E_ALL or M_PI), one of the INI constants (On, Off, True, False, Yes, No and None) or an expression (e.g. E_ALL & ~E_NOTICE), or a quoted string ("foo").

Boolean flags can be turned on using the values 1, On, True or Yes. They can be turned off using the values 0, Off, False or No.


YOU NEED TO BE VERY CAREFUL OF SOME OF THESE as they will have script compatibility issues!

Relating to the population of global variables from the incoming form and environment:

register_globals = Off
 ; [Security, Performance]
register_globals = On
 ; [Old style compatibility]

and if you set it on:

variables_order = "EGPCS"
 ; [Collect environment variables as well as ...]
variables_order = "GPCS"
 ; [Collect Get, Post, Cookie and Server variables]

What do you want to happen to any error messages?

display_errors = Off
 ; [Don't tell the user but ...]
log_errors = On
 ; [... write to a log file]
error_log = filename

Do you want input data to be automatically \ protected?
magic_quotes_gpc = Off
Input data is no longer escaped with slashes so that it can be sent into SQL databases without further manipulation. Instead, you should use the function addslashes() on each input element you wish to send to a database.

include_path = ".:/php/includes"
 ; where to look for included files


The following must be checked if you want the services they effect to work!

File uploads:

file_uploads = On
 ; Allow file uploads?
upload_tmp_dir =
 ; and if so, where to keep them temporarily

Email (for Windows systems):

SMTP = localhost
sendmail_from = me@localhost.com

MySQL connection:

mysql.default_port =
mysql.default_socket =
mysql.connect_timeout = -1

(There are many other MySQL settings and settings for other relational databases!)

The following are for the session functions, which be default DO NOT WORK under Windows ay you must change the save_path:

session.save_handler = files
session.save_path = /tmp
session.use_cookies = 1
session.cookie_path = /


max_execution_time = 30
 ; Maximum execution time of each script, in seconds
memory_limit = 8M
 ; Maximum amount of memory a script may consume (8MB)
post_max_size = 8M
 ; Maximum data that you can upload in a "post"
upload_max_filesize = 2M
 ; Maximum allowed size for uploaded files.
session.cookie_lifetime = 0
 ; Cookies to be non-persistent
session.cache_expire = 180
 ; sessions to be kept for 180 minutes

See also Training module on installing PHP

Please note that articles in this section of our web site were current and correct to the best of our ability when published, but by the nature of our business may go out of date quite quickly. The quoting of a price, contract term or any other information in this area of our website is NOT an offer to supply now on those terms - please check back via our main web site

Related Material

Sourcing, installing and configuring PHP
  [192] - ()
  [316] - ()
  [481] - ()
  [934] - ()
  [1667] - ()
  [1688] - ()
  [1731] - ()
  [1768] - ()
  [1936] - ()
  [2317] - ()
  [2433] - ()
  [2589] - ()
  [2646] - ()
  [3132] - ()
  [3635] - ()
  [3955] - ()
  [4319] - ()
  [4437] - ()

resource index - PHP
Solutions centre home page

You'll find shorter technical items at The Horse's Mouth and delegate's questions answered at the Opentalk forum.

At Well House Consultants, we provide training courses on subjects such as Ruby, Lua, Perl, Python, Linux, C, C++, Tcl/Tk, Tomcat, PHP and MySQL. We're asked (and answer) many questions, and answers to those which are of general interest are published in this area of our site.

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2022: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho

PAGE: http://www.wellho.net/solutions/php-sour ... g-php.html • PAGE BUILT: Wed Mar 28 07:47:11 2012 • BUILD SYSTEM: wizard