PostgreSQL & PHP Tutorials - Installing PHP

PHP »  Installing PHP
PHP »  Starting Out »  Installing PHP

Posted By Chris Smith Posted on 07 Feb 2006, 05:17 AM
After installing PostgreSQL and Apache we can finally set up PHP and start writing some database scripts.    Finally we have to do the PHP installation.

Again, it's best to use a pre-built system package if you can - it makes things so much easier to upgrade in the future.

Some packages don't include every single extension, but you can usually find them. For example, debian has a 'php4' package - the postgresql package is 'php4-pgsql'.
For more information see your system's documentation.

If you really want to compile from source (this is necessary if you can't find an extension in any pre-built packages), keep reading!

After downloading the tarball from a php mirror, the start is much the same:

$ tar -xjf php-<version>.tar.bz2

Jump into the directory:

$ cd php-<version>

(replace <version> with the version number you downloaded from the website).

Running ./configure --help will show all commands again.

To compile an Apache PHP module with PostgreSQL support, we need to do:

$ ./configure --with-pgsql=/usr/local/pgsql --with-apxs=/usr/local/apache/bin/apxs

If you chose to install Apache 2, then you'll need to change the last part to:

--with-apxs2=/usr/local/apache/bin/apxs


Change the paths if you installed PostgreSQL in a different directory, or if you installed Apache in a different place.

Why do we need to specify the path? Linux (and most BSD's) look for "header" files (which tell other app's what functions they can run - ie they provide something like an API) in specific spots (/usr/include/ , /usr/lib/ ). Since /usr/local/pgsql is not a standard spot, we have to tell it where they are.

The same goes for apxs support, since /usr/local/apache isn't a regular directory, we need to specify it's location.

The same idea goes for any other modules you want to install (eg mysql, gd libraries, imap libraries and so on). You need to install the main package for that program and then you can add support to it in PHP.

After configure finishes, you will get:

Thank you for using PHP.


Now it's make time again:

$ make

And finally:

$ sudo make install

After it activates the module in Apache, we need to tweak the apache configuration file slightly to make it recognise PHP.

Back up the original file first:
$ sudo cp /usr/local/apache/conf/httpd.conf /usr/local/apache/conf/httpd.conf.backup

Edit the config file in your favourite editor (vi, emacs or something else), and add:

AddType application/x-httpd-php .php .phtml

Underneath the line:

AddType application/x-tar .tgz


This allows us to use .php and .phtml as PHP files. If you want to use different extensions, add them to this list.

Finally, we need to restart apache:

$ sudo /usr/local/apache/bin/apachectl stop
$ sudo /usr/local/apache/bin/apachectl start


Then we can create a test php page.

Create a file in the /usr/local/apache/htdocs/ directory called 'info.php' and put the following in it:


<?php
phpinfo();
?>


After saving that, go to your browser and try to view it. It should come up with details about your installation.

We finally have PHP installed!
Avg Rating: 5
Vote Count: 9


              

  New Reply


I have just installed PHP 5.1.4 on my server in an attempt to get postgres and php playing together and now when I attempt my info.php I get:-
[code=SERVER_RESPONSE_CLOSE] The server closed the connection while reading the response
What have I done wrong?

[Editor's Note] Check your apache error logs and go from there. If you still need help, ask on the php mailing list.
Alf Stockton 11 May 2006 Reply


Want to post a comment? Fill in the details below.

Your Name  : 
Your Email  : 
Your Website  : 
Spam Check! Please answer this question  : 8 + 3 =
Comment