The Installation Itself

The Installation Itself

Now that you understand the background, it's time to start the installation. The following assumes that you have a working UNIX machine, installed and ready to go.


If you don't already have a UNIX machine and want a good place to start, Linux is the ideal UNIX-based operating system for PC-based hardware. Just make sure to tell it to install all the developer utilities during installation, because you'll need these to get PHP up and running.

We assume that your UNIX machine is networked, has a private IP address assigned, and can be pinged from your workstation (and your workstation from it). We also assume that you are familiar with basic UNIX commands and utilities.

If all this looks good to you, then you can get started. Log in to your UNIX machine as root (or become root from a normal user account using su), and you can begin.

Downloading and Installing PostgreSQL

Because your development environment is for your own use only, you don't need to worry about putting PostgreSQL on a separate machine. You can use the same machine to run Apache, PHP, and your database without any real performance implications.

Make sure that you get the complete archive of PostgreSQL from and that you download the source code not any binaries. You'll compile it yourself for maximum speed and resilience. The filename of your downloaded file will look something like postgresql-7.4.3.tar.gz.

You can download the file using lynx or ftp if you must, but our preferred route is wget:

   # wget 

After you've downloaded it, unpack PostgreSQL in the normal way:

   # tar -xzvf postgresql-7.4.3.tar.gz 

This will create a directory called postgresql-7.4.3 that contains the source files for PostgreSQL. Change into that directory:

   # cd postgresql-7.4.3 

Now, run the configure script to generate a Makefile appropriate to your particular UNIX environment.

   # ./configure 

With luck, you won't see any errors and you'll get a string of checks passed, with the last line reading:

   config.status: linking ./src/makefiles/Makefile.linux to src/Makefile.port 

or something very similar to this line. If this all looks good, you can start the compilation process by simply typing:

   # make 

It may take quite a while for PostgreSQL to compile, so go have a cup of coffee at this point. When you return, PostgreSQL will have compiled without incident, we hope, and you can install it as follows:

   # make install 

Strictly speaking, PostgreSQL is now installed. But a certain amount of configuration is still required. Follow these steps to get your database working directory set up (where all your data will be stored):

   # adduser postgres    # mkdir /usr/local/pgsql/data    # chown postgres /usr/local/pgsql/data    # su - postgres    # /usr/local/pgsql/bin/initdb -D /usr/local/pgsql/data 

You're almost ready to start the PostgreSQL daemon (server) now. One final step: You have to tell PostgreSQL where to allow connections from. Normally, this will just be from the same server or, in a pinch, from other machines on the same network.

Say that your server's IP address in this case is, and you want to allow access from that IP address only. Edit the file /usr/local/pgsql/data/pg_hba.conf using your favorite editor, and add this line to the very bottom of the file:

   Host  all  all  trust 

Save the file and quit the editor. You can now start PostgreSQL using the following syntax:

   # su - postgres    # /usr/local/pgsql/bin/postmaster -i -D /usr/local/pgsql/data & 

The first line is very important. The postmaster process must run as your new postgres user and not as root or whoever you may have been logged in as. The -i directive when starting is important, too, because it tells PostgreSQL to allow TCP/IP connections something it disallows by default.

That's it. You can create a database as follows, again as the user postgres:

   # /usr/local/pgsql/bin/createdb databasename 

Then you can manipulate it using the PostgreSQL console as follows:

   # /usr/local/pgsql/bin/psql databasename 

Finally, you can create new users as follows:

   # /usr/local/pgsql/bin/createuser username 

This concludes your crash course in PostgreSQL installation. Anything else you might need to know is in the PostgreSQL documentation or explained throughout the course of this book.

Installing the Various Support Libraries

In an ideal world, you could now press on and install PHP and Apache. Unfortunately, life isn't fair and, as a result, you're now presented with the unenviable task of installing a number of support libraries for PHP.

Which libraries you need depends on exactly what functionality you require. For example, if you need to parse XML and XSL (which you do), you'll need the XML and XSL support libraries.

You'll need the following libraries for the examples in this book:

Mercifully, all the preceding libraries are free, too.

The process for downloading and installing each of the these packages is much the same in each case. Just follow these simple steps:

  1. Visit the Web sites in the preceding list to locate a download URL for each package.

  2. Download the relevant .tar.gz source file using wget.

  3. Unpack the archive using tar -xzvf filename.tar.gz.

  4. Change to the directory just created, usually named filename (that is, the same as what you just downloaded, but without the .tar.gz suffix).

  5. Run ./configure with the --enable-shared suffix (that is, ./configure--enable-shared).

  6. Run make.

  7. Run make install.

  8. Change back to your original directory (cd..) and go to the next package.

There are a couple of exceptions and additions, however:

With all the previous packages installed, you're ready to get onto PHP and Apache themselves.

Installing PHP and Apache

PHP and Apache must be installed in tandem, so we've put them together in one section here. It'll become clear exactly why very shortly.

First, download the latest versions of Apache and PHP from their respective Web sites and It's worth pointing out that Apache v2 and PHP are not yet the best of friends. We strongly recommend at this writing that you stick with the latest 1.3.x version of Apache, currently 1.3.31.

The two files you'll download will be named something like apache-1.3.31.tar.gz and php-5.0.0.tar.gz. Uncompress them in the normal manner:

   # tar -xzvf apache-1.3.31.tar.gz    # tar -xzvf php-5.0.0.tar.gz 

The first step is to do an initial configure on Apache. Change into the Apache directory (probably apache-1.3.31) and run the configure script with no parameters. It will complain, but ignore it:

   # ./configure    Configuring for Apache, Version 1.3.31    + Warning: Configuring Apache with default settings.    + This is probably not what you really want. 

When it's done, you can go ahead and configure PHP. Change back out of the Apache directory and into the PHP directory:

   #cd..    # cd php-5.0.0 

You now configure PHP using a fairly long configure statement. This should be entered on a single line:

   ./configure --with-apache=../apache_1.3.31 --with-libxml-dir=/usr/local/lib    --with-gd --with-gettext --without-mysql --with-pgsql --enable-sockets    --with-jpeg-dir=/usr/local/lib --with-png-dir=/usr/local/lib --with-zlib-dir=    /usr/local/lib --enable-gd-native-ttf --with-freetype-dir=/usr/local/lib    --with-xmlrpc --with-dom -enable-xslt --with-expat-dir=/usr/local/lib    --with-xsl 

Note that if you are using a newer version of Apache than 1.3.31, you will need to amend the --with-apache directive accordingly to reflect the unpack path.

It may well take a few minutes to configure, but assuming that you've followed this appendix correctly up until now, you shouldn't receive any error messages and all should configure okay.

You can then go ahead and build PHP:

   # make    # make install 

Note that the make may well take a few minutes, depending on the speed of your server. The make install will probably not take too long at all. If it fails, you may need to retrace your steps. Check, in particular, that all the support packages mentioned in the previous section have been configured correctly.

PHP has now created a module in your Apache unpack directory; you can now configure and install Apache making use of that module:

   #cd..    # cd apache-1.3.31    # ./configure --prefix=/usr/local/apache --activate-    module=src/modules/php5/libphp5.a 

Once again, the configure statement must be on a single line when entered. You should see Apache configure, and advise that it is activating the module you just told it to. This is a good thing and implies everything is working okay to this point.

You can now go ahead and compile Apache:

   # make    # make install 

There's just one final step: You need to tell the Apache configuration file how to handle the .php extension. Modify the file /usr/local/apache/conf/httpd.conf and add the following lines:

   AddType application/x-httpd-php .php .php4 .php3 .php5    AddType application/x-httpd-php-source .phps 

These lines can be added virtually anywhere but should be placed near all the other AddType and AddHandler directives in the file to keep things clean.

Testing Your Installation

All that remains is to test your installation. Start Apache using the following syntax:

   # /usr/local/apache/bin/apachectl start 

Now create a file in /usr/local/apache/htdocs called test.php containing the following code:

   <?php    phpinfo();    ?> 

Save it and, in your workstation's Web browser, point it to the IP address of your UNIX machine, followed by /phpinfo.php. For example, if your server was, point it to You should see a screen similar to Figure D-1.

Figure D-1

If so, congratulations. Your PHP installation has been successful! You will probably want to create Virtual Server entries for each project that you work on, however. Much more information on this can be found in Chapter 24, "Deployment.''

Professional PHP5 (Programmer to Programmer Series)
Professional PHP5 (Programmer to Programmer Series)
Year: 2003
Pages: 182
BUY ON AMAZON © 2008-2017.
If you may any questions please contact us: