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 Apache2. 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.
What to Download
So the starting point is the Apache web site, to download the latest release there www.apache.org where the latest PHP download can also be found. The projects of interest being HTTP Server and of course PHP.
HTTP Server Project provides a Win32 binary version on it's download page (Win32 Binary (MSI Installer)) 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 the firebird release. The current version (as of Nov 2005) of firebird for windows is Firebird-188.8.131.5231-Win32.exe and sourceforge will take you through it's mirror selection before actually starting the download.
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 sub-directory 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 Apache2 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 work. 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 Apache1 documents, but does point you in the right direction.
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:NetworkApache2confdirectory, and I set .conf files to automatically open 'Notepad' to edit them. The on-line 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 Web site in the c:Network` directory, so I create a sub directory of Web site, and use that as my DocumentRoot, so the references to `c:NetworkApache2htdocs are changed to c:NetworkWebsite. 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 cause 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:Networkphp-5_0_5php.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 the 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:NetworkApache2error.log, and usually points to the problem, otherwise it's back to the ApachePHP sites, or shout for help in the newsgroups.
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 a break the rules and install in it's own directory structure as c:Firebird_1_5. Firebird-184.108.40.20631-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 web site.
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:
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:
and a tmp sub directory 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.
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 sub directory '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:/Firebird_1_5/Backup/'); Need to create \Backup directory in c:\Firebird_1_5
The Test Site
In order to carry out tests, a simple PHP web site 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.