# CUBRID 10.1.x 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 10.1.x PHP Library with PHP 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 10.1.x

### 2.1 Configuring the Environment

- CUBRID 10.1.x:

    Install CUBRID 10.1.x, and make sure the Environment Variable %CUBRID% is defined in your
    system;

- PHP source code:

    Download PHP source code (PHP 5.4.x, 5.6.x, or 7.1.x) from PHP.net. In this document, we use PHP 5.4.x, PHP 5.6.x, and 7.1.x.

- 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-php:

      cubrid-php> php_cubrid.c php_cubrid.h php_cubrid7.c php_cubrid7.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 or later
      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 \
                --with-apxs2=/usr/local/apache2/bin/apxs

     --with-cubrid=shared

     Include CUBRID support

     --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, 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

     10.1.0.xxxx

## 3. Building on Windows x86

    In this section we will introduce two ways of building PHP Library for CUBRID:

      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 VC9 versions for PHP5.4.x.
      If you are using PHP with IIS you should use the VC9 versions for PHP5.4.x.

      If you are using PHP with Apache 1 or Apache2 from apache.org you need to use the VC11 versions for PHP5.6.x or VC14 for PHP7.
      If you are using PHP with IIS you should use the VC11 versions for PHP5.6.x or the VC14 for PHP7.

      VC9 Versions are compiled with the legacy Visual Studio 2008 compiler;
      VC9 Versions are compiled with the Visual Studio 2008 compiler and have improvements in performance and stability.
      VC11 Versions are compiled with the legacy Visual Studio 2012 compiler;
      VC11 Versions are compiled with the Visual Studio 2012 compiler and have improvements in performance and stability.
      VC14 Versions are compiled with the legacy Visual Studio 2015 compiler;
      VC14 Versions are compiled with the Visual Studio 2015 compiler and have improvements in performance and stability.

### 3.1 Compile CUBRID PHP Library with VC9 for PHP 5.4.x

    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 10.1.x:

    Install CUBRID 10.1.x, 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 6.1
    if you're a makefile master;

- PHP 5.4.x 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.4.x source code:

    Remember to get the source that matches your binary version. After you extract the PHP 5.4.x source code,
    add system environment variable %PHP5_SRC%, and set its value to the path of PHP 5.4.x 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.4.x 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.4.x

     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 VC11 for PHP 5.6.x

    Download CUBRID PHP Library, extract it and enter directory win, you will find Visual Studio 2012 project files
    php_cubrid.sln and php_cubrid.vcproj.  Before you open the project, you should do some preparations.

      Note: When using CUBRID PHP VC11 Library with PHP on Windows, make sure that Microsoft Visual C++ 2012
      Redistributable Package is installed.

### 3.2.1 Configuring the Environment

- CUBRID 10.1.x:

    Install CUBRID 10.1.x, and make sure the Environment Variable %CUBRID% is defined in your
    system;

- Visual Studio 2012:

    You can alternately use the free Visual C++ Express Edition or the VC++ 11 compiler in the Windows SDK
    if you're a makefile master;

- PHP 5.6.x binaries:

    You can install VC11 x86 Non Thread Safe or VC11 x86 Thread Safe, and check if the value of system environment
    variable %PHPRC% is rightly set;

      In the VC11 project Properties, under the Linker tree node, select the General node, you can see $(PHPRC)
      in Additional Library Directories.

- PHP 5.6.x source code:

    Remember to get the source that matches your binary version. After you extract the PHP 5.6.x source code,
    add system environment variable %PHP5_SRC%, and set its value to the path of PHP 5.6.x source code.

      In the VC11 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.6.x from source, but you do need to configure it. If you don't, VC11 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 VC11 Library for PHP 5.6.x

     1. Open VC11 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.3 Compile CUBRID PHP Library with VC14 for PHP 7.1.x

    Download CUBRID PHP Library, extract it and enter directory win, you will find Visual Studio 2015 project files
    php_cubrid7.sln and php_cubrid7.vcproj.  Before you open the project, you should do some preparations.

      Note: When using CUBRID PHP VC14 Library with PHP on Windows, make sure that Microsoft Visual C++ 2015
      Redistributable Package is installed.

### 3.3.1 Configuring the Environment

- CUBRID 10.1.x:

    Install CUBRID 10.1.x, and make sure the Environment Variable %CUBRID% is defined in your
    system;

- Visual Studio 2015:

    You can alternately use the free Visual C++ Express Edition or the VC++ 14 compiler in the Windows SDK
    if you're a makefile master;

- PHP 7.1.x binaries:

    You can install VC14 x86 Non Thread Safe or VC14 x86 Thread Safe, and check if the value of system environment
    variable %PHP7% is rightly set;

      In the VC14 project Properties, under the Linker tree node, select the General node, you can see $(PHP7)
      in Additional Library Directories.

- PHP 7.1.x source code:

    Remember to get the source that matches your binary version. After you extract the PHP 7.1.x source code,
    add system environment variable %PHP7_SRC%, and set its value to the path of PHP 7.1.x source code.

      In the VC14 project Properties, select the General node from C/C++ tree node. You can see $(PHP7_SRC)
      in Additional Include Directories.

    Note: You do not need to build PHP 7.1.x from source, but you do need to configure it. If you don't, VC14 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.3.2 Build VC14 Library for PHP 7.1.x

     1. Open VC14 project under directory win, in the Solution Explorer on the left, right click on the php_cubrid7
        project name and select Properties;

     2. On the top right corner of the php_cubrid7 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 %PHP7%\ext if this directory exists.
        b) In php.ini file set the extension_dir variable and add CUBRID PHP Library to extension variable.

## 4. Building on Windows x64

    This section will guide you through the steps you need to follow to build Windows x64 CUBRID PHP Driver with PHP5.4.x (VC9 environment), PHP 5.6.x (
    VC11 environment), and PHP 7.1.x (VC14 environment)

### 4.1 PHP 5.4.x

### 4.1.1 Configuring the Environment for PHP 5.4.x

- CUBRID 10.1.x:

    Install CUBRID 10.1.x, 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;

- PHP 5.4.x x64 binaries:

    You can build your own VC9 x64 PHP with SDK, or you can get it at http://www.anindya.com, both
    VC9 x64 Non Thread Safe and VC9 x64 Thread Safe are available. After you have installed it, please 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.4.x source code:

    Remember to get the source that matches your binary version. After you extract the PHP 5.4.x source code,
    add system environment variable %PHP5_SRC%, and set its value to the path of PHP 5.4.x 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.4.x 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

### 4.1.2 Build x64 VC9 Library for PHP 5.4.x

     1. Open VC11 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 under Active solution configuration, there are four configurations (Release_TS, Release_NTS,
      Debug_TS and Debug_NTS). We need to create a new one for our x64 build. For this reason, select the
      <New> option. In the new window, input the configuration name (e.g., Release_TS_x64). For the copy
      setting from choose the corresponding x86 configuration, in our case Release_TS. Then click "OK".

     3. In the same Configuration Manager window, click the dropdown box under the Platform header label.
      If there is x64, choose it, otherwise choose <New...>. In the new window, choose x64 option for
      New platform. Press OK and close the Configuration Manager.

     4. Once you complete the properties modification, press the OK button. Then press F7 to compile;

     5. 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.

### 4.2 PHP 5.6.x

### 4.2.1 Configuring the Environment for PHP 5.6.x

- CUBRID 10.1.x:

    Install CUBRID 10.1.x, and make sure the Environment Variable %CUBRID% is defined in your
    system;

- Visual Studio 2012:

    You can alternately use the free Visual C++ Express Edition;

- PHP 5.6.x x64 binaries:

    You can build your own VC11 x64 PHP with SDK, or you can get it at http://www.anindya.com, both
    VC11 x64 Non Thread Safe and VC11 x64 Thread Safe are available. After you have installed it, please check
    if the value of system environment variable %PHPRC% is rightly set;

      In the VC11 project Properties, under the Linker tree node, select the General node, you can see $(PHPRC)
      in Additional Library Directories.

- PHP 5.6.x source code:

    Remember to get the source that matches your binary version. After you extract the PHP 5.6.x source code,
    add system environment variable %PHP5_SRC%, and set its value to the path of PHP 5.6.x source code.

      In the VC11 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.6.x from source, but you do need to configure it. If you don't, VC11 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

### 4.2.2 Build x64 VC11 Library for PHP 5.6.x

     1. Open VC11 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 under Active solution configuration, there are four configurations (Release_TS, Release_NTS,
      Debug_TS and Debug_NTS). We need to create a new one for our x64 build. For this reason, select the
      <New> option. In the new window, input the configuration name (e.g., Release_TS_x64). For the copy
      setting from choose the corresponding x86 configuration, in our case Release_TS. Then click "OK".

     3. In the same Configuration Manager window, click the dropdown box under the Platform header label.
      If there is x64, choose it, otherwise choose <New...>. In the new window, choose x64 option for
      New platform. Press OK and close the Configuration Manager.

     4. Once you complete the properties modification, press the OK button. Then press F7 to compile;

     5. 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.

### 4.3 PHP 7.1.x

### 4.3.1 Configuring the Environment for PHP 7.1.x

- CUBRID 10.1.x:

    Install CUBRID 10.1.x, and make sure the Environment Variable %CUBRID% is defined in your
    system;

- Visual Studio 2015:

    You can alternately use the free Visual C++ Express Edition;

- PHP 7.1.x x64 binaries:

    You can build your own VC14 x64 PHP, or you can get it at http://www.anindya.com, both
    VC14 x64 Non Thread Safe and VC14 x64 Thread Safe are available. After you have installed it, please check
    if the value of system environment variable %PHP7% is rightly set;

      In the VC14 project Properties, under the Linker tree node, select the General node, you can see $(PHP7)
      in Additional Library Directories.

- PHP 7.1.x source code:

    Remember to get the source that matches your binary version. After you extract the PHP 7.1.x source code,
    add system environment variable %PHP7_SRC%, and set its value to the path of PHP 7.1.x source code.

      In the VC14 project Properties, select the General node from C/C++ tree node. You can see $(PHP7_SRC)
      in Additional Include Directories.

    Note: You do not need to build PHP 7.1.x from source, but you do need to configure it. If you don't, VC14 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

### 4.3.2 Build x64 VC14 Library for PHP 7.1.x

     1. Open VC14 project under directory win, in the Solution Explorer on the left, right click on the php_cubrid7
        project name and select Properties;

     2. On the top right corner of the php_cubrid7 Property Page press Configuration Manager button. In the
      new window under Active solution configuration, there are four configurations (Release_TS, Release_NTS,
      Debug_TS and Debug_NTS). We need to create a new one for our x64 build. For this reason, select the
      <New> option. In the new window, input the configuration name (e.g., Release_TS_x64). For the copy
      setting from choose the corresponding x86 configuration, in our case Release_TS. Then click "OK".

     3. In the same Configuration Manager window, click the dropdown box under the Platform header label.
      If there is x64, choose it, otherwise choose <New...>. In the new window, choose x64 option for
      New platform. Press OK and close the Configuration Manager.

     4. Once you complete the properties modification, press the OK button. Then press F7 to compile;

     5. 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 %PHP7%\ext if this directory exists.
        b) In php.ini file set the extension_dir variable and add CUBRID PHP Library to extension variable.