Installing Oracle Database, PHP, and Apache On Microsoft Windows XP

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

Installing Oracle Database, PHP, and Apache on Microsoft Windows XP

1 of 2

Sign In/Register Help Country

Products
Oracle Technology Network

Articles

Solutions

Communities

Downloads

http://www.oracle.com/technetwork/articles/dsl/inst-php-apache-window...

I am a...

Store

Search

I want to...

Support

Training

Partners

About

Dynamic Scripting Languages

Installing Oracle Database, PHP, and Apache on Microsoft Windows XP

Updated for PHP 5.4 and Oracle Database 11g Release 2


by Rob Clevenger & Christopher Jones
Updated April 2012

Are you ready to start using PHP to talk to an Oracle Database? Let's walk through the steps required to install the Oracle Database, Apache HTTP
Server, and PHP on Windows. We will be using Windows XP Professional for this example.

Software Requirements

Software
VersionSoftware Description
Oracle Database 11g Release 2 Express Edition for Windows x3211.2 www.oracle.com/technetwork/products/express-edition/overview
Apache HTTP Server
2.2
httpd.apache.org
PHP Hypertext Processor
5.4
php.net

Installing Oracle
You have a choice where to install Oracle Database. You may either install it locally on this Windows machine, or you may decide to use a database
located on another machine. If your database is not on your machine, jump to the article on Installing PHP and the Oracle Instant Client for Linux and
Windows.
Otherwise, if this is your first time with Oracle, installing Oracle Database 11g Express Edition (commonly known as "XE") only takes a few minutes.
Download the Express Edition ZIP file OracleXE112_Win32.zip, unzip it, navigate to the DISK1 folder, and run setup.exe to start the
installation wizard. The XE Installation Guide covers this in detail.

Starting and Stopping Oracle


Oracle XE will be running after installation. You can test it by opening your browser to the administration page. When you click on any of the red
button links you will be prompted to login. Use the username "SYSTEM" and the password you chose during database installation.
If you need to restart the database at any time use the Start Database and Stop Database items on the Windows Start->All Programs->Oracle
Database 11g Express Edition menu.

Installing Apache HTTP Server


Installation steps:
Download httpd-2.2.22-win32-x86-no_ssl.msi from httpd.apache.org/download.cgi
Double click the MSI file to start the installation wizard.
Install "for All Users, on Port 80" because the "only for the Current User" alternative clashes with Oracle XE's default port 8080.
Do a typical install into the default destination folder: C:\Program Files\Apache Software Foundation\Apache2.2.
Download the FastCGI component mod_fcgid-2.3.6-win32-x86.zip from httpd.apache.org/download.cgi#mod_fcgid
Unzip it to the installed Apache 2.2 directory. The C:\Program Files\Apache Software Foundation\Apache2.2\modules directory
should now have mod_fcgid.so and mod_fcgid.pdb files.
Edit C:\Program Files\Apache Software Foundation\Apache2.2\conf\httpd.conf and add the line:
LoadModule fcgid_module modules/mod_fcgid.so
In httpd.conf, locate the section for htdocs and add ExecCGI to the Options:
<Directory "C:/Program Files/Apache Software Foundation/Apache2.2/htdocs">
...
Options Indexes FollowSymLinks ExecCGI
...
</Directory>

Starting and Stopping Apache


As part of installation, the web server will be started. You should now test your machine by opening your web browser to http://localhost/. You should
see a page saying 'It works!'.
Your system tray has an Apache Monitor control that makes it easy to stop and re-start the HTTP Server when needed. Alternatively use the Apache
options that were added to your Windows Start->All Programs->Apache HTTP Server 2.2 menu.

Installing PHP
Installation steps:
Download the PHP 5.4.0 "VC9 x86 Non Thread Safe" ZIP package php-5.4.0-nts-Win32-VC9-x86.zip from windows.php.net/download.
In Windows Explorer unzip the PHP package to a directory called C:\php-5.4.0
In C:\php-5.4.0 copy php.ini-development to php.ini

05/08/14 12:38

Installing Oracle Database, PHP, and Apache on Microsoft Windows XP

2 of 2

http://www.oracle.com/technetwork/articles/dsl/inst-php-apache-window...

Edit php.ini to make the following changes:


Add a timezone line like:
date.timezone = America/Los_Angeles
Use your local timezone name.
Add the line:
extension_dir = C:\php-5.4.0\ext
This is the directory containing the PHP extensions.
Remove the semicolon from the beginning of the line:
extension=php_oci8_11g.dll
This extension works with any Oracle 11.2 client libraries, including those in Oracle XE.
Edit C:\Program Files\Apache Software Foundation\Apache2.2\conf\httpd.conf and add the following lines. Make sure you use
forward slashes '/' and not back slashes '\':
FcgidInitialEnv PHPRC "c:/php-5.4.0"
AddHandler fcgid-script .php
FcgidWrapper "c:/php-5.4.0/php-cgi.exe" .php
You must now restart the Apache Server so that you can test your PHP installation. Use the system tray Apache Monitor or the Start menu option.
If there are any problems, check the log file C:\Program Files\Apache Software Foundation\Apache2.2\logs\error.log. Double
check your httpd.conf and php.ini files. Make sure you rebooted the machine after installing Oracle Database XE so that the PATH environment
variable includes the Oracle libraries.

Testing Apache and PHP with Oracle


Testing PHP with Oracle is easy. You simply need to place PHP files into your document root directory C:\Program Files\Apache Software
Foundation\Apache2.2\htdocs
Here are two files that test PHP.
phpinfo.php
The first file tests basic PHP installation. Open it in a browser with http://localhost/phpinfo.php. If PHP is installed correctly you should see a large
page full of PHP configuration information.
<?php
phpinfo();
?>
Check there is a section titled "oci8" with the version number and the OCI8 directives.
oci8test.php
Edit the script and change the password to the one you chose for SYSTEM. Load the script in a browser with http://localhost/oci8test.php.
For Oracle Database XE the database connection string is simply "localhost/XE". You may need to replace "localhost" with the IP address
127.0.0.1 or your machine's DNS name if you are behind a firewall or if localhost does not resolve for some other reason. If you are not using XE then
change the connection string to the Oracle Network entry for your database.
<?php
$c = oci_connect("system", "your_password", "localhost/XE");
$s = oci_parse($c, "select table_name from all_tables where owner = 'HR'");
$r = oci_execute($s);
echo "<table border='1'>\n";
$ncols = oci_num_fields($s);
echo "<tr>\n";
for ($i = 1; $i <= $ncols; ++$i) {
$colname = oci_field_name($s, $i);
echo " <th><b>".htmlentities($colname, ENT_QUOTES)."</b></th>\n";
}
echo "</tr>\n";
while (($row = oci_fetch_array($s, OCI_ASSOC+OCI_RETURN_NULLS)) != false) {
echo "<tr>\n";
foreach ($row as $item) {
echo " <td>".($item!==null?htmlentities($item, ENT_QUOTES):"&nbsp;")."</td>\n";
}
echo "</tr>\n";
}
echo "</table>\n";
?>
This script displays the tables that the HR user owns. The HR sample schema comes with Oracle Database XE. You can unlock access and set a
password by following the Unlocking the Sample User Account manual section. You could then edit the script to connect as 'HR' and query one of the
sample tables such EMPLOYEES.

Conclusion
You should now have the Oracle Database, Apache HTTP Server, and PHP installed and configured. At this point you are ready to start writing PHP
applications on the Oracle platform.
Oracle's free Underground PHP and Oracle Manual contains more detail on using PHP with Oracle Database.
For more information about PHP and Oracle, visit the OTN PHP Developer Center.
There is also a PHP Forum to post any questions.

05/08/14 12:38

You might also like