Open Source RDBMS - Seamless, Scalable, Stable and Free

English | Login |Register

Using CUBRID with Apache, PHP in LINUX - Installation with phpize

Introduction: This chapter introduces how to install PHP CUBRID module with phpize to use CUBRID after installing Apache Web server and PHP in LINUX, and provides simply how to interwork with CUBRID. For more information about interworking, see section " PHP API " of the manual.

Applicable to: LINUX, CUBRID2008, Apache2.2.10, PHP5.2

Installing Apache

This chapter introduces how to install Apache Web server in LINUX. You can download the Apache Web server from Apache download. Usually, download Unix Source below " Apache HTTP Server 2.2.1 0 is the best available version ", and then uncompress the downloaded file (ex. httpd-2.2.1 0.tar.gz) and install the server.

In this example, the server is installed under user account in general account. If you install it under root account, you can use the default installation location (--prefix is not necessary and the installation location is usually /usr/local/apache2).

# Move the downloaded file to a user's home directory for installation. You can move it to any directory you want.  	A user's home directory is assumed to be /home/web.
# The downloaded file name is assumed to be httpd-2.2.10.tar.gz.
# Uncompress the file and extract tar.
tar xvfz httpd-2.2.10.tar.gz
or gzip -d httpd-2.2.10.tar.gz; tar xvf httpd-2.2.10.tar
# After extracting tar, the httpd-2.2.10 directory is created and you can see installation files in it.
cd httpd-2.2.10
# You need to complie for installation. Make sure to configure the modules to make them support dynamic loading before compiling.
./configure --enable-mods-shared=most --enable-modules=so --with-mpm=worker --enable-so --prefix=/home/web/apache2
# If there is no error, start compiling.
make
# If the compiling is successful, start installation.
make install
# After installation, register the mail account of an administrator and the server name to the configuration file.
vi /home/web/apache2/conf/httpd.conf
# Set ServerAdmin web_admin@cubrid.com (the e-mail address of a Web server administrator).
# Register as ServerName my_hostname(server name or IP address).
# Listen 8000 (If a installed user account is not root, the default port of the installed Apache Web server cannot be 80.  	It must be changed. Usually, 8000 is used.)
# If you want to use 80, you need to change configuration to make the Web server work as the root account. Of course,  	you can run it as your current account. With the below configuration, the server works as root account although it is started  	in a general account.
cd /home/web/apache2/bin
chown root httpd
chmod +s httpd
cd /home/web/apache2/bin
apachectl start

After running the Web browser, enter http://localhost:8000 (for LINUX) or http://192.168.2.1:8000 (for PC. LINUX server IP is assumed to be 192.168.2.1) in the address bar . If 'It works!' is displayed, it means the server is successfully installed.

image1.jpg

^ Top of page

Installing PHP

Stop the Apache Web server to install PHP.

cd /home/web/apache2/bin
apachectl stop

You can download PHP from PHP download. Usually, you can see the most recent version. Download PHP under Complete Source Code (ex. php-5.3.8.tar.gz).

# It is assumed the downloaded file for installation is located in a user's home directory.
# The downloaded file name is assumed to be php-5.3.8.tar.gz.
# Uncompress PHP installtion module and extract tar.
tar xvfz php-5.3.8.tar.gz
# Execute configure. (For PHP4.3, 4.4, use --enable-experimental-zts instead of --enable-zmaintainer-zts.)
./configure --prefix=/home/web/php --enable-zmaintainer-zts --with-apxs2=/home/web/apache2/bin/apxs
# If there is no error, start compiling.
make
# If the compiling is successful, start installation.
make install
# After installation, copy php.ini-dist into /home/web/php/lib directory.
cp php.ini-dist /home/web/php/lib/php.ini
# Register PHP extension to the Apache.
vi /home/web/apache2/conf/httpd.conf
AddType application/x-httpd-php .php .phtm

If it is installed successfully, run the Apache web server as follows:

cd /home/web/apache2/bin
./apachectl start

^ Top of page

Checking whether PHP and CUBRID PHP module work

Create phpinfo.php in documents root of Apache Web server (e.g. /home/web/apache2/htdocs) with the following.

<? phpinfo.php ?>

After running the Web browser, enter http://localhost:8000/phpinfo.php (for LINUX) or http://192.168.2.1:8000/phpinfo.php (for PC. LINUX server IP is assumed to be 192.168.2.1) in the address bar. If you can see PHP as below, it is successfully installed.

image2.jpg

^ Top of page

Running CUBRID

Make sure CUBRID service is running to interwork with CUBRID. For LINUX, log in as CUBRID admin account and start the service.

cubrid service start

Now, use the CUBRID Manager Client to run database as follows: Note that JAVA Runtime Environment is needed to run the CUBRID Manager Client that is developed in JAVA. You can download JAVA Runtime Environment from JAVA download . Java SE Runtime Environment (JRE).

Run $CUBRID/cubridmanager/cmclient because CUBRID Manager Client can run in LINUX GUI environment.

If you want to install it on your PC, download the CUBRID Manager Client for Windows from the CUBRID homepage. And if you want to install only the CUBRID Manager Client, just select " CLIENT_ONLY " in the installation option.

To run the CUBRID Manager Client on your PC, right-click the CUBRID icon in the Windows system tray, then select [Tools] > [CUBRID Manager] in the context menu. If only CUBRID Client is installed, go to [Start] > [CUBRID] and select [CUBRID Manager Client] to run.

image3.jpg image4.jpg

Select localhost and login. If this is first installation, just click [ Connect ] .

image5.png

If you connect your PC to a LINUX server, click [Add Host] to register a new host. Enter a name into the [Host name ] box (e.g. web server), the IP address of LINUX into the [Address ] box, a user name into the [ User name ] box, user password into the [ Password ], and then click [ Connect ]. This saves the information you entered and connects to LINUX server. You can just select the name you registered (e.g. web server) in [Host name ] box from the next time.

image6.png

When you double-click a database at the left side of the screen, you can see the login dialog for the database. You can just click [ OK ], because there is no database user password at the first installation.

image7.png

After login to the database, right-click the database and then select [ Start database server ] in context menu to start the database.

image8.png

^ Top of page

Simple examples

This is a simple example that shows actual interworking between PHP and CUBRID. There are only the most basic functions and some special cautions.

To perform this example, the database and CUBRID BROKER you want to connect must be running. Here, we just use "demodb" database that is automatically created during installation.

Create the following source in the DOCUMENT_ROOT (e.g. /home/web/apache2/htdocs).

The IP address of LINUX server in an example is assumed to be 192.168.2.1. You can enter your actual IP address. Test just like http://192.168.2.1/select.php in a Web browser.

^ Top of page

select.php

<html><head><meta http-equiv='content-type' content='text/html; charset=euc-kr'></head>
<body>
<center>
<table border=2>
<?

// Set server information for CUBRID connection. The IP address is the one where the CUBRID (CUBRID BROKER) server is  	installed (localhost in this example), and the port is the port number through which you want to connect to the CUBRID (CUBRID BROKER) server.  	The port number is the default during installation. For more accurate information, see the CUBRID Administrator's Guide.
    $host_ip = "192.168.2.1";
    $host_port = 33000;
    $db_name = "demodb";

// Connect to CUBRID server.
    $cubrid_con = @cubrid_connect($host_ip, $host_port, $db_name);
    if (!$cubrid_con) {
        echo "Database Connection Error: " . cubrid_error_msg();
        exit;
    }
?>

<?
$sql = "select code, name, players from event";
// Request the CUBRID Server for the results of the SQL statement.
$result = cubrid_execute($cubrid_con, $sql);
if ($result) {
        // Get the column names from the result set created by the SQL query.
        $columns = cubrid_column_names($result);
// Get the number of columns in the result set created by the SQL query.
        $num_fields = cubrid_num_cols($result);
       // List the column names of the result set on the screen.
                echo("<tr>");
        while (list($key, $colname) = each($columns)) {
                 	echo("<td align=center>$colname</td>");
        }
                echo("</tr>");

       // Get the results rows from the result set.
        while ($row = cubrid_fetch($result)) {
                echo("<tr>");
                 	for ($i = 0; $i < $num_fields; $i++) {
                    	     echo("<td align=center>");
                    	     echo($row[$i]);
                    	     echo("</td>");
                }
                echo("</tr>");
        }
}

/ / CUBRID runs in 3-tier architecture. Even when calling select for transaction processing, it is processed as a part of the  	transaction. Therefore, the transaction needs to be committed or rolled back even though SELECT was called for smooth performance.  	For more information, see CUBRID Administrator's Guide.
        cubrid_commit($cubrid_con);
cubrid_disconnect($cubrid_con);
?>

  </body></html>

image9.jpg

^ Top of page

insert.php

<html><head><meta http-equiv='content-type' content='text/html; charset=euc-kr'></head>
<body>
<center>
<table border=2>
<?
// Set server information for CUBRID connection. The IP address is the one where the CUBRID (CUBRID CAS) server is  	installed (localhost in this example), and the port is the port number through which you want to connect to the CUBRID (CUBRID BROKER) server.  	The port number is the default during installation. For more accurate information, see the CUBRID Administrator's Guide.
    $host_ip = "192.168.2.1";
    $host_port = 33000;
    $db_name = "demodb";

// Connect to CUBRID Server.
    $cubrid_con = @cubrid_connect($host_ip, $host_port, $db_name);
    if (!$cubrid_con) {
        echo "Database Connection Error";
        exit;
}
?>

<?
$sql = "insert into event(code, sports, name, gender, players) values(10000, 'TaeKwonDo','Unlimited Weight', 'M', 2)";
// Request the CUBRID Server for the query of the SQL statement.
$result = @cubrid_execute($cubrid_con, $sql);
if ($result == true) {
        // It is successful, so commit it.
        cubrid_commit($cubrid_con);
        echo(" Successfully inserted");
} else {
        // Error occurred, so error message is displayed and rollback is called.
        echo(cubrid_error_msg());
        cubrid_rollback($cubrid_con);
}
cubrid_disconnect($cubrid_con);
?>
</body></html>

image10.jpg




You are either using a very old browser or a browser that is not supported.
In order to browse cubrid.org you need to have one of the following browsers:



Internet Explorer: Mozilla Firefox: Google Chrome: