Beginners' guide to Firebird and PHP

<< Choosing a file system on Linux for Firebird | Database technology articles | Using Apache, PHP and InterBase to develop websites >>

Beginners' guide to Firebird and PHP

By Lester Caine, updated 25th November 2005

Using Firebird with PHP is relatively easy, but does require an understanding of some quite complex pieces of software.

The first question is Windows or Linux. Linux will provide a much faster and more reliable server base, but the same facilities can be provided from a Windows server as required.

For ease of implementation, the Windows route is being documented with the plan that different versions of Linux will be supported as required.

There are several web servers that can be used as the base html support package, and the one selected here is Apache™ 2. While PHP is reported as being experimental on this package, no problems have so far been found with Apache™ 2.0.55 and PHP 5.0.5, the current stable releases.

back to top of page

What to download

So the starting point is the Apache™ website, to download the latest release there http://www.apache.org where the latest PHP download can also be found. The projects of interest being HTTP Server and of course PHP.

The HTTP Server Project provides a Win32 binary version on it's download page but it may be necessary to change the mirror from which it is downloaded if the default on is busy.

The PHP Project on the same site provides a download of the current PHP in the same way. I use the .zip package from the download page as it includes the extensions such as php_interbase, while the Windows installer does not.

The third item that will help is a copy of Firebird itself. If this has not already been installed, then the current versions can be obtained from the sourceforge archive which can be accessed via the main Firebird site. The latest news is always available here, and the download link on the header gives access to all Firebird releases. The current version (as of November 2005) of Firebird for Windows is Firebird-1.5.2.4731-Win32.exe]] and sourceforge will take you through its mirror selection before actually starting the download.

back to top of page

Starting with the web server

All of these packages come with quite comprehensive installation guides, which is not planned to reproduce here, but a few pointers are appropriate to get your system up and running. In fact, there is not much needed to get the system running 'from the box'. I have a habit of avoiding the Microsoft default setting for things so that I know where I am, and so I start with a C:\Network directory as the base for this installation, and then all the network stuff is in the one place. If your existing installations are some where else, it is just a matter of using the correct paths where requested. So we start with apache_2.0.46-win32-x86-no_src.msi, which will complain if your version of Windows does not have a recent Microsoft msi installer. The installer will ask all the usual questions, and information on this can be found in the installation guide, which is also available off-line once the package has been installed. Setting up the Domain and Server name the same as the machine name if you are not connecting to a real web domain, select the Typical setup until you have time to play, and I change the default path to C:\Network\. The install takes less than a minute on a fast machine. Once that is done, I extract the PHP .zip (php-5.0.5-Win32.zip in this case) into the network directory, keeping the zip files directory structure in tact. This produces a subdirectory in C:\Network of \php-5.0.5-Win32 which is both a bit of a mouthful, and has 'dots' in it which I find Windows screws up on, so before using it, the name is changed, in this case to php-5_0_5.

Since Firebird is independent of Apache™/PHP, we can first check the setup of the web server before adding the database stuff. The first nice feature in Apache™ 2 is the Apache Service Monitor, which allows the starting and stopping of local and remote Apache™ servers. As we have not changed anything yet, Apache™ should start without any problem, accessing localhost:80 should give you the Apache™ default page. If it does not, then **** and we need to find out why your network is not working. FAQ for Apache™ problems can be found at http://httpd.apache.org/docs/2.0/faq/support.html. This document is not as comprehensive as the earlier Apache™ 1 documents, but does point you in the right direction.

back to top of page

Adding PHP

Assuming we have a default page, then now is the time to start breaking things. Stop the server using the Monitor, or the stop button in the Program Menu. Then find the Apache™ config file. This has a link to it from the Program Menu under Apache HTTP Server 2.0.55-Configure Apache Server - Edit the Apache httpd.conf. It can be found in C:\Network\Apache2\conf\ directory, and I set .conf files to automatically open Notepad to edit them. The online installation guide for PHP can be used, or downloaded as part of the help files (which is a Windows help file version of the manuals).

There are only a couple of things to change, the first of which is optional. I like to build the website in the C:\Network\ directory, so I create a sub directory of the website, and use that as my DocumentRoot, so the references to C:\Network\Apache2\htdocs are changed to C:\Network\Website. Then the test pages are loaded into that directory, but more of that later. The second and more important change is to enable PHP. This is actioned by adding

 LoadModule php5_module C:/Network/php-5_0_5/php5apache2.dll

at the end of the LoadModule list and

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

at the end of the AddType list. You may need to add additional lines here if other PHP packages use different extensions, but this will give us the basics. In fact I normally only use .php extensions for PHP script files, so the additional extensions are not normally used.

We are now ready to restart the Apache™ server, and check that PHP loads, which of course it will not, so we address a couple of points there as well. While we have extracted the PHP directory structure, a couple of bits are in the wrong place. First copy C:\Network\php-5_0_5\php.ini-recommended to your Windows directory (C:\WINNT or C:\Windows, make a note of which ) and rename it php.ini. This gives the default configuration, and is the file that will be edited later to add the InterBase® stuff, but for now just worry about a default PHP. NOW it should be possible to start Apache™, and do this BEFORE worrying about the InterBase® extensions, so as to ensure that any problems are cleared before going to the next step. I have a set of simple html pages that allow the installed software to be checked at each stage. An index page allows selection of both test pages and documentation. These will be listed later, but the most important page is testphpinfo.php, the "Hello World" of PHP coding. This accesses the comprehensive settings page for PHP and allows all of the settings to be checked. If this page does not display, then PHP is not running, and needs to be sorted out before proceeding. The most useful file in this instance is C:\Network\Apache2\error.log, and usually points to the problem, otherwise it's back to the Apache™/PHP sites, or shout for help in the newsgroups.

back to top of page

Adding Firebird

If we have a working PHP Version 5.0.5 information page then we are well on the way to a fully functional system. The next step needs an operational copy of Firebird, which again I break the rules and install in its own directory structure as C:\Firebird_1_5. Firebird-1.5.2.4731-Win32.exe should install without any problem, and just changing the install directory to C:\Firebird_1_5 will align it with these notes (then any additional Firebird packages will be installed below the Firebird directory). The default install process will have the check box for copying gds32.dll to the Windows systems directory un-selected, and that file is necessary in order for php_interbase.dll to run, so should be selected before continuing. Notes on checking the Firebird installation are available on the Firebird website.

Now we are ready to tempt fate, and enable the php_interbase.dll extension to PHP. So first stop the Apache™ server again, so that the Windows copy of php.ini (you did make a note of where it went?) can be edited. The easy change is to remove the ';' from the start of the php_interbase.dll line. The second more important change is the extension_dir entry, change this to

 extension_dir="C:\Network\php-5_0_5\ext\"

which removes the need to move any of the other extension packages if you want to use them. Two further changes help with later packages. The session.save_path entry should be changed to

 session.save_path="C:\Network\Apache2\tmp"

and a \tmp subdirectory added to the Apache2 directory.

The final change is recommended when php_interbase is being used, but causes other problems, so I am not currently using it. This is the magic_quotes_sybase entry, and leaving it off allows ibWebAdmin to work properly. Watch this space for more information.

With these changes made, then we are ready to restart Apache™, and check the testphpinfo.php page. Provided that Apache™ starts, then InterBase® should appear just below the iconv entry on the settings page, and we are ready to try out Firebird with PHP.

back to top of page

ibWebAdmin

ibWebAdmin is a nice PHP package to add as it provides all the facilities that you could need for database management. It can be downloaded from sourceforge and the latest version is 1.0. Download ibWebAdmin_1.0.zip, and then unzip it into the C:\Website site directory where it will create a subdirectory ibWebAdmin_1.0, which I change to ibWebAdmin_1_0 before Windows complains.

Configuring ibWebAdmin is relatively easy, but does require the Linux default values changing to Windows format, the following settings are affected. These entries are found in the configuration file in the /inc subdirectory (configuration.inc.php), being a Unix file, you may have problems editing it, as it will not open normally in Notepad, but Wordpad will handle it quite happily, until you can decide on a suitable PHP editor, which is another area for discussion.

 define('BINPATH', 'C:/Firebird_1_5/bin/'); Firebird program directory

 define('SECURITY_DB', 'C:/Firebird_1_5/security.gdb'); Firebird security file

 define('TMPPATH', 'C:/Network/Apache2/tmp/'); This was the tmp directory we created earlier

 define('DEFAULT_DB', 'security.gdb'); Use the security database because we know it is there

 define('DEFAULT_PATH', 'C:/Firebird_1_5/'); As Above

 define('BACKUP_DIR', 'C:irebird_1_5/Backup/'); Need to create \Backup directory in C:\Firebird_1_5

back to top of page

The test site

In order to carry out tests, a simple PHP website setup has been provided as a zip file, which will unzipped to create the C:\Website site directory. It consists of a simple index.html page which accesses five functions, which can be used to test the installation.

The directory structure that I work with currently is as follows:

  • C:\Firebird_1_5\ - for the Firebird installation
  • C:\Firebird_1_5\Backup\ - is added as the home for ibWebAdmin backup files
  • C:\Network\Apache2\ - for the Apache™ server
  • C:\Network\Apache2\tmp\ - needs to be added to provide the location for Apache™ and PHP temporary files
  • C:\Network\PHP-5_0_5\ - for the PHP module
  • C:\Website\ - for the actual website pages
  • C:\Website\PHP\ - is a set of basic test programs
  • C:\Website\Config\ - contains copies of the configuration files to get the test system working

TestPHPInfo is the phpinfo command encapsulated in a PHP page in order to use it.

fbWebAdmin takes you to the ibWebAdmin package once it is installed.

TestConnection is a simple check of the database connection and USER table contents.

TestFBQuery is a more advanced check of the database connection listing the USER table fields. (The username and password entries in dtest.php and fbclass_tester.php will need changing if you change the SYSDBA default entries.)

NS Lookup allows host names and IP addresses to be looked up.

In addition to the test pages, the \Config directory contains copies of the configuration files for Apache™ (httpd.conf), PHP (php.ini) and ibWebAdmin (configuration.inc.php). These files can be used directly if the C:\Network and C:\Firebird_1_5 directory structure is maintained, or they can be used in BeyondCompare to check which lines need modification in a new setup.

This paper was written by Lester Caine in 2005 and is copyright Lester Caine and IBPhoenix Inc.

See also:
Setting up PHP and Firebird on Linux
Using Apache™, PHP and InterBase® to develop websites
IBExpert Benchmark

back to top of page
<< Choosing a file system on Linux for Firebird | Database technology articles | Using Apache, PHP and InterBase to develop websites >>