Friday, July 07, 2006

Install & Configure Apache+PHP+ZendFramework+OracleDbXe On Windows In Minutes

Let's say you want to install Apache+PHP+ZendFramework+OracleDbXe (Oracle Database Express Edition)
and play around with the spanky new Zend Framework made available by the folks over at Zend Corporation.
It's actually quite easy and painless.

This article gives you a easy and practical guide to installing,
configuring and testing Apache2.2.2+PHP5.1.4
+ZendFramework0.1.4+OracleDb10gXe10.2.0.1.0 on Windows OS.
Set up your development environment with Zend Framework in minutes!

1. Download and Install the S/Ws.
(1) Download OracleDb10gXe10.2.0.1.0 from http://otn.oracle.com and
install it.
(2) Then use the command “sqlplus / as sysdba” to
connect to the db, and execute “alter user hr account
unlock” to unlock the user “hr”.
(3) Download Apache2.2.2 from http://www.apache.org and install it.
E.g, install it at C:\Programs\Apache2.2.
(4) Download PHP5.1.4 from http://www.php.net and install it. E.g.,
install it at C:\Programs\php-5.1.4-Win32.
(5) Download ZendFramework0.1.4 from http://framework.zend.com and
install it. E.g, install it at C:\Programs1\ZendFramework-0.1.4.

2. Configure Apache and PHP.
(1) Make sure you have a folder for your website, e.g.,
C:\ProgDemo\WebSiteDemo.
(2) Setup the Apache conf file C:\Programs\Apache2.2\conf\httpd.conf as
follows:
21) DocumentRoot "C:/ProgDemo/WebSiteDemo"
22) <Directory "C:/ProgDemo/WebSiteDemo">
Options Indexes FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
23) <Directory "C:/Programs/php-5.1.4-Win32">
AllowOverride All
Order allow,deny
Allow from all
</Directory>
24) DirectoryIndex index.html index.php
25) ScriptAlias /php/ "C:/Programs/php-5.1.4-Win32/"
26) AddType application/x-httpd-php .php
27) Action application/x-httpd-php "/php/php-cgi.exe"
SetEnv PHPRC "C:/Programs/php-5.1.4-Win32"
(3) Rename the PHP config file C:\Programs\php-5.1.4-Win32\php.ini-dist
to C:\Programs\php-5.1.4-Win32\php.ini. Then setup the
file php.ini as follows:
31) include_path = ".;C:\Programs1\ZendFramework-0.1.3\library"
32) doc_root = "C:\ProgDemo\WebSiteDemo"
33) extension_dir = "./ext"
34) extension=php_oci8.dll

Ok, everything is installed, just a couple more steps to tie them up. :)

3. Test operating OracleDbXe via PHP and Zend Framework.
(1) Create a file named “index.php” in the folder
C:\ProgDemo\WebSiteDemo.
(2) Edit the file “index.php” as follows:
<?php print
"This is a Demo that PHP operates OracleDB10gXe via PHP Plus Zend
Framework!<br><br>\n" ?>

<?php
require_once 'Zend/Db.php';
$params = array ('host'=>'localhost','username'=>'hr','password'=>'hr','dbname'=>'xe');
$db=Zend_Db::factory('Oracle', $params);
$querysql = 'select last_name, salary from employees where salary > 11000';
$result = $db->query($querysql);
$rowset = $result->fetchAll();
$n=max(count($rowset["LAST_NAME"]),count($rowset["SALARY"]));
print '<table border="1"><tr><td>Name</td><td>Salary</td></tr>';
for($i=0;$i<$n;$i++)
{
print "<tr><td>".htmlspecialchars($rowset["LAST_NAME"][$i])."</td><td>".htmlspecialchars($rowset["SALARY"][$i])."</td></tr>";
}
?>
(3)Key in http://localhost and you will see the results of your query, which goes through Zend libraries.

Viola! :)

Do let us have your comments.

3 comments:

yo4rker said...

Your website has a useful information for beginners like me.
»

Anonymous said...

I didnt find thing that i need... :-(
google

Kianhui said...

What were you looking for ?