Open Source RDBMS - Seamless, Scalable, Stable and Free

한국어 | Login |Register

Installing NGINX, PHP, and CUBRID PHP Driver

In this article, I will show how to install NGINX, PHP and CUBRID-PHP Driver from source code in order to establish the web server environment. There are other ways to accomplish the same task, for instance, via the package manager of you operating system.

Configure PHP

First, let's get PHP Engine installed.

1. Download PHP source package.

The PHP source package can be downloaded in the PHP official site.

The PHP version needs to be 5.3 or 5.4. For example, php-5.4.11.tar.gz. When using PHP with NGINX, the FASTCGI is needed to process the PHP requests. The PHP-FPM is a FastCGI implementation, and the current PHP 5.3 and 5.4 already include the FPM part in the source code. More infomation about PHP-FPM can be found here.

2. Build PHP.

The concise build command is as below. You can add other options if neccessary. The --enable-fpm, in our case, is the important option that enables the PHP-FPM.

tar zxvf php-<version>.tar.gz (or tar jxvf php-<version>.tar.bz2) 
cd php-<version> 
./configure --prefix=/home/<user>/php/ --enable-fpm
make install

After installation, you will find the php-fpm executable in /home/<user>/php/sbin/

3. Configure PHP FPM.

When the php-fpm is started, it will read the configuration, such as the IP address and port to listen, and then run as daemon. So before starting it, we need to get its configuration ready.

Run the below command to create the php-fpm.conf by making a copy of the default template file:

cd /home/<user>/php/etc 
cp php-fpm.conf.default php-fpm.conf

The below line in php-fpm.conf configures the IP address on which to accept FastCGI requests:

listen =

The above listening address is important because NGINX needs this infomation to communicate with PHP-FPM. When configuring NGINX, this listening address will be set to fastcgi_pass parameter.

4. Run PHP FPM.

Run the following command to start the PHP-FPM.

cd /home/<user>/php/ 

Install CUBRID PHP Library

We have previously written several thorough tutorial on how to install CUBRID PHP driver. Please refer to CUBRID PHP Driver Installation Instructions for details.

Configure NGINX

1. Download NGINX.

The NGINX source package can be downloaded in the NGINX download page.

2. Build.

The FASTCGI is supported in NGINX by default. You can simply build as below. If necessary, you can add other configuration options.

tar zxvf nginx-<version>.tar.gz
cd nginx-<version> 
./configure --prefix=/home/<user>/nginx/
make install

3. Configure the fastcgi section in nginx.conf.

After NGINX is installed, we need to configure the FASTCGI related parameters. The NGINX configuration file can be found at /home/<user>/nginx/conf/nginx.conf. You can refer to the below simple configuration for fastcgi.

You can read more about NGINX configuration at NGINX wiki site.

    server {
        listen       80; 
        server_name  localhost;
        root         html;

        # pass the PHP scripts to FastCGI server listening on
        location ~ \.php$ {
            root           html;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        fastcgi_params;

Test CUBRID PHP Driver

1. Create a test.php file with the following contents, and put it into the NGINX's document root:

<?php phpinfo(); ?>

2. Use your web browser to navigate to http://localhost/test.php to see the contents as shown below which will mean the CUBRID PHP driver is successfully installed and enabled.

CUBRID support


Driver Version

CCI Version


3. Create a test2.php file with the following contents, and put it into the NGINX's document root as well.

    <title>PHP Test for CUBRID</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <h1>PHP Test for CUBRID</h1>
    <p> An Example of PHP in Action <br />
        <?php echo "The Current Date and Time is: <br />";
            echo date("g:i A l, F j Y.");?>

    $host = "localhost";
    $port = 33000;
    $db = "demodb";
    $user = "public";
    $passwd = ""; 
    $connect_url = "CUBRID:$host:$port:$db:::";
    $conn = cubrid_connect($host, $port, $db, $user, $passwd);
    $sql = "select * from db_class";
    $req = cubrid_execute($conn, $sql);
    printf("%10s<br />\n", "class_name");
    print "=====================<br />";
    while ($row = cubrid_fetch_row($req)) {
        printf("%10s<br />\n", $row[0]);

4. Use your web browser to navigate to http://localhost/test2.php to retrieve the sample data from a database. Note that the db_class table is a system table in CUBRID that exists in every database, so no need to create it manually.

This concludes this tutorial on how to install NGINX, PHP, and CUBRID PHP driver. If you have questions, feel free to ask at CUBRID Q&A site, Facebook, or Twitter.

comments powered by Disqus
Page info
viewed 26994 times
translations en
posted 4 years ago by
updated 4 years ago by
View revisions
Share this article