CUBRID 2008 R3.1 PHP Library Build Guide
Open Source PHP Library for CUBRID Database
(http://sourceforge.net/projects/cubridinterface)
1. Introduction
This manual mainly tells you how to build CUBRID 2008 R3.1 PHP Library with PHP 5.3/5.2 on Linux and Windows.
2. Building on Linux
In this section, we will introduce two ways of building PHP Library for CUBRID on Linux:
1. Compile CUBRID PHP Library together with original PHP source code;
2. Compile CUBRID PHP Library individually.
Building CUBRID PHP Library on 64bit Linux
In this section, we assume that the Linux system is 32bit. If you build CUBRID PHP Library on
64bit Linux, remember to install 64bit CUBRID 2008 R3.1
|
2.1 Configuring the Environment
CUBRID 2008 R3.1:
Install CUBRID 2008 R3.1, and make sure the Environment Variable %CUBRID% is defined in your
system;
PHP 5.3/5.2 source code:
Download PHP source code (PHP 5.2 or 5.3) from PHP.net. In this document, we use PHP 5.3.3 and 5.2.14.
Apache2
We can use apache2 to test PHP.
2.2 Compile PHP Library with PHP source code
1. Extract PHP source code, and create directory cubrid under dir ext:
$> tar zxvf php-<version>.tar.gz (or tar jxvf php-<version>tar.bz2)
$> cd php-<version>/ext
ext> mkdir cubrid
2. Put the following files in CUBRID PHP Library into directory cubrid:
cubrid-php> php_cubrid.c php_cubrid.h php_cubrid_version.h config.m4
3. Go to the root directory of PHP source code and update the configuration file:
php-root> ./buildconf --force
Note: When developing a PHP extension, it is strongly recommended that autoconf version 2.13
be installed, despite the newer releases which are available. Version 2.13 is recognized as a common
denominator of autoconf availability, usability, and user base. Using later versions will sometimes
produce cosmetic differences from the expected output of configure.
You can set environment PHP_AUTOCONF to path of autconf-2.13 and set PHP_AUTOHEADER to
path of autoheader-2.13.
|
4. Configure the project. Before you run configure, we strongly recommend that you run "./configure -h"
to check the configure options. An example may be like this (we assume that apache2 has been installed in
/usr/local):
php-root>./configure --prefix=/usr/local/php -with-cubrid=shared --enable-maintainer-zts \
--with-apxs2=/usr/local/apache2/bin/apxs
--with-cubrid=shared |
Include CUBRID support |
--enable-maintainer-zts |
Enable thread safety - for code maintainers only!! |
--with-apxs2=FILE |
Build shared Apache 2.0 Handler module. FILE is the optional pathname to the Apache apxs tool apxs |
5. Build and install the package. If it was successfully compiled, the cubrid.so file will be created in the /modules directory:
php-root> make; make install
6. Copy php.ini-xxx (In PHP 5.2.x, they are php.ini-dist and php.ini-recommended; In PHP 5.3.x, they are php.ini-development
and php.ini-production; choose what you need) file to directory /usr/local/php/lib, and rename it to php.ini.
php-root> cp php.ini- production /usr/local/php/lib/php.ini
7. In php.ini file set the extension_dir variable and add CUBRID PHP Library to extension variable. For example:
extension_dir = "/usr/local/php/lib/php/extension/no-debug-zts-xxx"
extension = cubrid.so
2.3 Compile PHP Library for CUBRID individually
1. Download PHP Library, extract it and enter the directory:
$> tar zxvf CUBRID-PHP-<version>.src.tar.gz
$> cd cubrid-php-<version>
2. Run phpize:
cubrid-php> /usr/bin/phpize
What is phpize? Where can I get it?
phpize is a shell script to prepare PHP extension for compiling. Typically, when you install PHP, phpize will
be automatically installed. If it is not installed on your system, the process of get it is as follows:
1. Download PHP source code, and make sure its version is what you want your PHP extenstion works
with. Extract PHP source code, and enter its root directory:
$> tar zxvf php-<version>.tar.gz (or tar jxvf php-<version>tar.bz2)
$> cd php-<version>
2. Configure the project, and build and install it. You can specify the directory you want install PHP to
with configure option --prefix:
php-root> ./configure --prefix=prefix_dir; make; make install
3. Then you can find phpize in prefix_dir/bin.
|
3. Configure the project. Before you run configure, you'd better run ./configure -h to see the configure options. Forexample:
cubrid-php> ./configure --with-cubrid --with-php-config=/usr/local/bin/php-config
4. Build. If it was successfully compiled, the cubrid.so file will be created in the /modules directory:
cubrid-php> make
5. Copy cubrid.so to the extensions directory in lib/php directory which is located inside PHP root directory (/usr/local/php):
cubrid-php> mkdir /usr/local/php/lib/php/extensions
cubrid-php> cp modules/cubrid.so /usr/local/php/lib/php/extensions
6. In php.ini file set the extension_dir variable and add CUBRID PHP Library to extension variable. For example:
extension_dir = "/usr/local/php/lib/php/extensions"
extension = cubrid.so
2.4 Test CUBRID PHP Library Installation
1. Create a test.php file with the following contents:
<?php phpinfo(); ?>
2. Use web browser to visit http://localhost/test.php, and if you see the following contents, the installation is successful.
CUBRID |
Value |
Version |
8.3.1.xxxx |
3. Building on Windows
In this section we will introduce two ways of building PHP Library for CUBRID:
1. Compile CUBRID PHP Library with VC9 for PHP 5.3;
2. Compile CUBRID PHP Library with VC6 for PHP 5.3/5.2;
Which version do I choose? (from windows.php.net)
If you are using PHP with Apache 1 or Apache2 from apache.org you need to use the VC6 versions of PHP;
If you are using PHP with IIS you should use the VC9 versions of PHP;
VC6 Versions are compiled with the legacy Visual Studio 6 compiler;
VC9 Versions are compiled with the Visual Studio 2008 compiler and have improvements in performance and stability.
The VC9 versions require you to have the Microsoft 2008 C++ Runtime (x86) or the Microsoft 2008 C++ Runtime (x64) installed.
Do NOT use VC9 version with apache.org binaries
|
3.1 Compile CUBRID PHP Library with VC9 for PHP 5.3
Download CUBRID PHP Library, extract it and enter directory win, you will find Visual Studio 2008 project files
php_cubrid.sln and php_cubrid.vcproj. Before you open the project, you should do some preparations.
Note: When using CUBRID PHP VC9 Library with PHP on Windows, make sure that Microsoft Visual C++ 2008
Redistributable Package is installed.
|
3.1.1 Configuring the Environment
CUBRID 2008 R3.1:
Install CUBRID 2008 R3.1, and make sure the Environment Variable %CUBRID% is defined in your
system;
Visual Studio 2008:
You can alternately use the free Visual C++ Express Edition or the VC++ 9 compiler in the Windows SDK v6.1
if you're a makefile master;
PHP 5.3 binaries:
You can install VC9 x86 Non Thread Safe or VC9 x86 Thread Safe, and check if the value of system environment
variable %PHPRC% is rightly set;
In the VC9 project Properties, under the Linker tree node, select the General node, you can see $(PHPRC)
in Additional Library Directories.
|
PHP 5.3 source code:
Remember to get the source that matches your binary version. After you extract the PHP 5.3 source code,
add system environment variable %PHP5_SRC%, and set its value to the path of PHP 5.3 source code.
In the VC9 project Properties, select the General node from C/C++ tree node. You can see $(PHP5_SRC)
in Additional Include Directories.
|
Note: You do not need to build PHP 5.3 from source, but you do need to configure it. If you don't, VC9 will
tell you that it can't find header file config.w32.h. You can read the wiki page below to get how to configure it.
http://wiki.php.net/internals/windows/stepbystepbuild
3.1.2 Build VC9 Library for PHP 5.3
1. Open VC9 project under directory win, in the Solution Explorer on the left, right click on the php_cubrid
project name and select Properties;
2. On the top right corner of the php_cubrid Property Page press Configuration Manager button. In the new window,
select the configure you want for Active solution configuration for Configuration in the Project contexts. There are
four configurations (Release_TS, Release_NTS, Debug_TS and Debug_NTS). Then close the Configuration Manager;
3. Once you complete the properties modification, press the OK button. Then press F7 to compile;
4. As we have built php_cubrid.dll we have to make PHP recognize it as an extension:
a) Inside PHP installation folder create the new folder called cubrid, and copy php_cubrid.dll to cubrid folder.
You can also put php_cubrid.dll in %PHPRC%\ext if this directory exists.
b) In php.ini file set the extension_dir variable and add CUBRID PHP Library to extension variable.
3.2 Compile CUBRID PHP Library with VC6 for PHP 5.3/5.2
Download CUBRID PHP Library, extract it and enter the directory, you will find VC6 project file php_cubrid.dsp. Before
you open the project, you should do some preparations.
3.2.1 Configuring the Environment
CUBRID 2008 R3.1:
Install CUBRID 2008 R3.1, and make sure the Environment Variable %CUBRID% is defined in your
system;
Visual C++ 6.0 SP6:
You should install the VC++ 6.0 SP6;
Windows Server Feb. 2003 SDK:
All official releases or snaps are built using VC6 with SP6 and this SDK, and you'd better compile you extension using this SDK.
If you don't install this SDK (It seems that you can no longer download it from Microsoft Download Center for free), you
can also use VC6's default settings. But you may see errors when you compile the extension and have to fix them
manually.
|
PHP 5.3/5.2 binaries:
You can install VC6 x86 Non Thread Safe or VC6 x86 Thread Safe, and check if the value of system environment
variable %PHPRC% is rightly set;
In the VC6 project, you can find $(PHPRC) in Settings->Link->Input->Additional library path
|
PHP 5.3/5.2 source code:
Remember to get the source that matches your binary version. After you extract the PHP source code,
add system environment variable %PHP5_SRC%, and set its value to the path of PHP source code.
In the VC6 project, you can find $(PHP5_SRC) in Settings->C/C++->Preprocessor->Additional include directories
|
Note: If you build CUBRID PHP Library with PHP 5.3 source code, you need to configure PHP 5.3 on Windows. If you don't,
VC9 will tell you that it can't find header file config.w32.h. You can read the wiki page below to get how to configure it.
http://wiki.php.net/internals/windows/stepbystepbuild
3.2.2 Build VC6 Library for PHP 5.3/5.2
1. Open VC6 project, in Build menu, select Set Active Configuration. There are four configurations
(Win32 Release_TS, Win32 Release, Win32 Debug_TS and Win32 Debug). Choose what you want, then close the Set Active
Project Configuration;
2. On the top right corner of the php_cubrid Property Page press Configuration Manager button. In the new window,
select the configure you want for Active solution configuration for Configuration in the Project contexts. There are
four configurations (Release_TS, Release_NTS, Debug_TS and Debug_NTS). Then close the Configuration Manager;
3. Once you complete the properties modification, press the OK button. Then press F7 to compile;
4. As we have built php_cubrid.dll we have to make PHP recognize it as an extension:
a) Inside PHP installation folder create the new folder called cubrid, and copy php_cubrid.dll to cubrid folder.
You can also put php_cubrid.dll in %PHPRC%\ext if this directory exists.
b) In php.ini file set the extension_dir variable and add CUBRID PHP Library to extension variable.