The FreeBSD 'zine
February 2000 : PHP Central

PHP Central - A new horizon
by Joel Sutton <[email protected]>

Welcome to the very first edition of PHP Central, a regular column on the PHP web based programming language. Each month I will attempt to introduce a new facet of PHP by using examples, rather than just talking about the straight theory.

What is PHP?

PHP is an interpreted programming language which is specifically designed to be used in developing web sites and web applications. It differs from other languages in two ways:

  • It has a number of extra facilities designed specifically for web applications.
  • The program is embedded into the web page itself.

Until the widespread release of tools like PHP, web applications were written in languages like Perl and C. Back then, the facilities weren't normally available to embed the program into a HTML file. So programmers had to embed the HTML into their program file.

Embedding your program directly into the HTML file has one distinct advantage - the development time is reduced. Languages like PHP (and others such as Cold Fusion, ASP and Zope) are often considered to be suitable for Rapid Application Development (RAD).

What can you do with PHP?

Being a fully fledged programming language, the possibilities are numerous and varied. However, people tend to use PHP for these sorts of jobs:

  • Integrating information from an existing database into a web site.
  • Developing fully functional applications which run in the web browser and, therefore, run on a number of different platforms without modification.
  • Extending an existing application to be remotely accessible.
  • Web site enhancement.

PHP can be compiled with a number of different facilities such as:

  • GD to generate .gif images on the fly.
  • pdflib for working with pdf files on the fly.
  • IMAP for working with mail boxes.
  • database support for MiniSql, MySql, PostgreSQL, Dbase files, and Interbase to name a few.
  • LDAP support.
  • SNMP for network diagnostics and manipulation.

Why use PHP?

This is a long and political argument so I will just list a few of the reasons why I chose to use PHP:

  • PHP is available on FreeBSD.
  • PHP is free.
  • It's fast to code.
  • PHP code can run on a variety of platforms.
  • It's a widely used web application development environment.

Where do I start?

Chances are, you'll only need to use a few of these facilities. Fortunately, the people who maintain the FreeBSD Ports collection have made it very easy for us to install a number of the more useful features of PHP.

First of all, it is necessary to install the software itself. To do this you will need to install the apache13-php3 port (other versions of apache with php are available). You will need to have the FreeBSD Ports collection installed to accomplish this.

Please check the following pages for information on installing FreeBSD ports:

The document, mentioned above, should cover most of the issues involved with installing the average FreeBSD port. Fortunately, apache13-php3 isn't an average port. When make is run, in the usual way, you will be presented with a screen similar to this:


You'll probably recognise the look and feel as being that of the FreeBSD installer (sysinstall). However, this screen allows you to specify which extra functions are to be installed with PHP. If the necessary supporting utilities, for those functions, are not installed the port will install them for you.

After you've installed the port, the simplest way to start the web server is to run the following command as root:

# apachectl start

For further information on configuring Apache and PHP, try one of the following web sites:

If you don't already have a favorite text editor, I suggest that you consider using VIM. VIM has the sole advantage of offering colour syntax highlighting - which can be a fantastically useful tool for writing bug free code.

My first PHP program

Change your current directory to somewhere in the web servers path - such as /usr/local/share/apache/htdocs/ - and create a new file called first.php3 with your favorite text editor. Its contents should look like this:

<title>First PHP Program</title>

<?php echo "Hello world....\n"?>


Open up your web browser and point it at your new file. You might get something like this:


Most of the program text, you will see, is standard HTML. The PHP code can be easily identified as the code between the special markers "<?php" and "?>". These markers tell PHP to treat everything inside them, as program code. In this case, we used the echo function to display some text on the browser.

Next time

Next month we will cover PHP code in a little more detail. We'll talk about loops, expressions and conditional statements.

Current Issue
. Issue #06 : July 2000

Old Issues
. Issue #01 : February 2000
. Issue #02 : March 2000
. Issue #03 : April 2000
. Issue #04 : May 2000
. Issue #05 : June 2000

Quick Links
. Table of Contents
. Mailing Lists
. FreeBSD Events
. User Group Calendar
. Site Statistics
. Old Articles
. Latest News
. Press Releases
. Contribute
. Send us Feedback
. Other Resources
. Submit an Article
. Submit an Event

Today's Fortune
Art is either plagiarism or revolution. -- Paul Gauguin

FreeBSD 'zine Poll
Are you going to BSDCon?
What the hell is BSDCon?
Results More polls

. VicFUG

. Issue #01 : Download
. Issue #02 : Download
. Issue #03 : Download
. Issue #04 : Download
. Issue #05 : Download
. Issue #06 : Download


Runs on FreeBSD

Add Channel to My Netscape


Contact: <[email protected]>
This site and the tarballs are built every 6 hours.
Copyright � 1998-2000, The FreeBSD 'zine
Code revision: 07/24/2000��All rights reserved.