Installing Firebird: Difference between revisions

From The Uniform Server Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 263: Line 263:




''(I'm not a english speaking man. there will be typos and poor grammar. I would apreciate anybody who corrects them and add more information.)''
''(I'm not an english speaking man. there will be typos and poor grammar. I would apreciate anybody who corrects them and add more information.)''





Revision as of 11:07, 20 June 2008

Introductions

The following method is a little changed from that which I explained in http://forum.uniformserver.com. You can see the previouse one clicking here.

Thanks to the policy of Firebird that it allows the server run as an application we can install firebird into Uniform Server. the key is adding "-a" after fbserver.exe command: fbserver.exe -a.

Firebird is open source and supports many options and syntaxes more than mysql. Still there are not many who use firebird as an web-based server. because of that I also had a hard time to use it. To many of us Mysql is a great option to use but it's not open source. I spent my time to install firebird to Uniform server and I just want to be a helper to them who want to use firebird as a portable database server.

The following shows how to install Firebird to your portable Uniform server.

Install Firebird Server

Visit http://www.firebirdsql.org and download the latest firebird no-install version and uncompress the zip to the uniform server\udrive\usr\local and change the newly created folder name to firebird. Here is the link for firebird v.2.1.0.17798.

Make a folder where you want to save firebird database files like: \udrive\var\firebird

Edit start_server.bat

Open start_server.bat and find a line like:

start \usr\local\mysql\bin\mysqld-opt.exe --defaults-file=/usr/local/mysql/bin/my-small.cnf

Under that line write down and save:

start \usr\local\firebird\bin\fbserver.exe -a

Edit php.ini

Check that you have php_interbase.dll in your php extension folder. If you don't have you have to get it from http://www.php.net. You will need php_pdo_firebird.dll also if you want to use PDO.

Open php.ini and find extension option and uncomment extension=php_interbase.dll. If you want to use pdo then uncomment extension=php_pdo_firebird.dll also.

Add the following to php.ini:

[InterBase]
ibase.allow_persistent =
ibase.max_persistent = 
ibase.max_links =
ibase.default_db =
ibase.default_user =
ibase.default_password =
ibase.default_charset =
ibase.timestampformat =
ibase.dateformat =
ibase.timeformat =

The value is not given. set your own value if you want. Blank means default value will be used.

"Strings in Firebird are delimited by a pair of single quote (apostrophe) symbols", so if you want convenience change the value of "magic_quotes_sybase" to "On"

Edit Close.bat

Open \udrive\home\admin\program\Close.bat and find the line:

:nomysql

Add under:

%Disk%:\home\admin\program\pskill.exe fbserver.exe
IF ERRORLEVEL 1 goto nofirebird
%Disk%:\home\admin\program\pskill.exe fbserver.exe c
:nofirebird

Firebird tray icon will be shown so we can shutdown the server using tray icon but we want the database server to be shutdowned when we finish the Uniform server. So we use pskill to kill the process by force.

Install Web Admin tool

Download the ibWebAdmin from here and unzip to \udrive\home\admin\www

Open ibWebAdmin\inc\configuration.inc.php and change some values like:

define('BINPATH', '/usr/local/firebird/bin/');
define('SECURITY_DB', '/usr/local/firebird/security2.fdb');
define('TMPPATH', '/tmp/');
define('DEFAULT_PATH',    '/var/firebird/');

We already created \var\firebird folder for saving database!

define('DEFAULT_HOST',    'localhost');
define('DEFAULT_CACHE',   8192); 

for better caching. You can change that.

define('DEFAULT_SERVER',  'FB_2.0');

$ALLOWED_DIRS = array('/var/firebird/',
                      '/tmp/');
define('BACKUP_DIR', '/var/firebird/backup/'); 

You need to create \var\firebird\backup for backup folder.

Edit Firebird configuration

Open \udrive\usr\local\firebird\firebird.conf and change some values like:

RootDirectory = \usr\local\firebird
DatabaseAccess = Restrict W:\usr\local\firebird;W:\var\firebird;W:\var\firebird\backup

Be careful when you define the DatabaseAccess, it should have the drive letter "W:", otherwise the firebird gives you error.

TempDirectories = /tmp

DefaultDbCachePages = 8192

Edit Uniform Admin Panel Files

Open \udrive\home\admin\www\includes\tool.inc and find line:

<a target="_phpmyadmin" onclick="h(this);" href="<?=$apanel?>/phpMyAdmin/"><?=$US['nav-pma']?></a>

Add next:

<a target="_ibwebadmin" onclick="h(this);" href="<?=$apanel?>/ibWebAdmin/"><?=$US['nav-ibwa']?></a>

Open \udrive\home\admin\www\includes\server.inc and find line:

<a target="content" onclick="h(this);" href="<?=$apanel?>/cgi-bin/includes/lang/<?=file_get_contents("includes/.lang");?>/smysql.cgi"><?=$US['nav-smysql']?></a>

Add next:

<a target="content" onclick="h(this);" href="<?=$apanel?>/cgi-bin/includes/lang/<?=file_get_contents("includes/.lang");?>/rfirebird.cgi"><?=$US['nav-rfirebird']?></a>
<a target="content" onclick="h(this);" href="<?=$apanel?>/cgi-bin/includes/lang/<?=file_get_contents("includes/.lang");?>/sfirebird.cgi"><?=$US['nav-sfirebird']?></a>

Open \udrive\home\admin\www\cgi-bin\includes\lang\en\sserver.cgi and find:

    system "/home/admin/program/uniserv.exe \"\\usr\\local\\mysql\\bin\\mysqladmin.exe --user=root --password=$password shutdown\"";
}

Add next:

$res = system "\\home\\admin\\program\\pskill.exe", "fbserver.exe";

if ($res == 0){
      system "/home/admin/program/pskill.exe fbserver.exe c";
}

Open \udrive\home\admin\www\includes\lang\en.php add in the code:

    'nav-rfirebird' => 'Run Firebird',
    'nav-sfirebird' => 'Stop Firebird',

    'nav-ibwa' => 'ibWebAdmin',

Create Files

Create rfirebird.cgi file in the \udrive\home\admin\www\cgi-bin\includes\lang\en:

#!/usr/bin/perl

require header;
require secure;

print "
<div id=\"main\">
<h2>» Start Firebird</h2>
<h3>Starting Firebird</h3>
<p>";

&check_Firebird;
if ($run) {
      if ($ENV{'QUERY_STRING'}eq"F"){
        &start_Firebird;
        print "Firebird server was forced to start.";
        print "<br />";
      }

      else {
        print <<ENDDD;
        Firebird server already running.
        <br />
        But if you think that it is mistake click on this <a href="$ENV{SCRIPT_NAME}?F">link</a>
        <br />
        </p>
        </div>
ENDDD
      }
} 

else {
      print <<ENDDD;
      Firebird server started.
      </p>
      </div>
ENDDD
      require footer;
      &start_Firebird;
}

require footer;

exit;

sub check_Firebird(){
    $res = system "\\home\\admin\\program\\pskill.exe", "fbserver.exe";
    if ($res == 0){$run=1} 
    else {$run=0}
}

sub start_Firebird(){
    exec "/usr/local/firebird/bin/fbserver.exe -a";
}

Create sfirebird.cgi file in \udrive\home\admin\www\cgi-bin\includes\lang\en:

#!/usr/bin/perl

require header;
require secure;

print "
<div id=\"main\">
<h2>» Stop Firebird</h2>
<h3>Stopping Firebird</h3>
<p>";

&check_Firebird;
if ($run) {
      &stop_Firebird;
      print "Firebird server stopped.<br>";
} 

else {
      if ($ENV{'QUERY_STRING'}eq"F"){
        &stop_Firebird;
        print "Firebird server was forced to stop.";
        print "<br>";
      } 

      else {
        print <<ENDDD;
        Firebird server was not running.
        <br />
        But if you think that it is a mistake click on this <a href="$ENV{SCRIPT_NAME}?F">link</a>
        <br />
ENDDD
      }
}

print <<ENDDD;
</p>
</div>
ENDDD

require footer;

exit;

sub check_Firebird(){
    $res = system "\\home\\admin\\program\\pskill.exe", "fbserver.exe";
    if ($res == 0){$run=1} 
    else {$run=0}
}
sub stop_Firebird(){
      system "/home/admin/program/pskill.exe fbserver.exe c";
}

Copy DLL

Copy fbclient.dll from \udrive\usr\local\firebird\bin to \udrive\usr\local\php. and for compatibility copy another and change its name to gds32.dll. If you have already then replace it. If the version of dll and the server are different it will not work!

If you encounter errors like “Application failed to start gds32.dll not found” or similiar there are solutions for these. try some of following:

Copy fbclient.dll also to \udrive\usr\local\apache\bin and copy another and change its name to gds32.dll. If you still have problem to connect to the server then you probably have gds32.dll or fbclient.dll in your %WINDIR%system32 folder and the dll file is of a old version. replace it or if you don't have any applications that use the dll file then remove it.

GDS_DB Problem

If you encounter 'too many open links(0)' error or 'Undefined service gds_db/tcp' error then add the following line to %SystemRoot%\system32\drivers\etc\services:

gds_db           3050/tcp                           #InterBase Server

You can create install_gds_db.php file in \udrive\home\admin\www:

<?php

// flag for gds_db port
$f_gds_db = false;

$systemroot = getenv("SystemRoot");

$service_file = $systemroot.DIRECTORY_SEPARATOR.'system32'.DIRECTORY_SEPARATOR.'drivers'.DIRECTORY_SEPARATOR.'etc'.DIRECTORY_SEPARATOR.'services';

$lines = file($service_file);

foreach ($lines as $line) {
	if (strpos($line, 'gds_db') !== false) {
		$f_gds_db = true;
		break;
	}
}

if (!$f_gds_db) {
	if ($fp = fopen($service_file, 'a')) {
		fwrite($fp, "\r\ngds_db           3050/tcp                           #InterBase Server");
		fclose($fp);
		echo "<script>alert('gds_db port is sucessfully installed.\\nPlease restart the server!');</script>\n";
	}
	else {
		echo "<script>alert('failed to install gds_db port!\\nIf you want to use Firebird database you have to open gds_db port manually.\\nAdd the following line to services file:\\ngds_db\\t\\t3050/tcp\\t\\t#InterBase Server');</script>\n";
	}
}

?>


Put the following code somewhere in the \udrive\home\admin\www\index.php, then when you start the server if the gds_db port is not installed it will install automatically. This is good for portable server. Anywhere you go just start the server then everything is ok:

<?
include "install_gds_db.php";
?>


(I'm not an english speaking man. there will be typos and poor grammar. I would apreciate anybody who corrects them and add more information.)