The leading edge of scripting languages and Oracle Database brought to you by the Data Access Development team

  • php |
    February 23, 2018

Installing XAMPP on Windows for PHP and Oracle Database

Christopher Jones
Senior Principal Product Manager

Today's guest post comes from Tianfang Yang who's been working with the Oracle Database extensions for PHP.

This post shows how to install XAMPP on Windows to run PHP applications that connect to a remote Oracle Database.

XAMPP is an open source package that contains Apache, PHP and many PHP 'extensions'. One of these extension is PHP OCI8 which connects to Oracle Database.

To install XAMPP:

  1. Download "XAMPP for Windows" and follow the installer wizard. I installed into my D: drive.

  2. Start the Apache server via the XAMPP control panel.

    screenshot of XAMPP control panel
  3. Visit http://localhost/dashboard/phpinfo.php via your browser to see the architecture and thread safety mode of the installed PHP. Please note this is the architecture of the installed PHP and not the architecture of your machine. It’s possible to run a x86 PHP on an x64 machine.

    screenshot of PHP configuration showing the PHP OS architecture as x86
  4. [Optional] Oracle OCI8 is pre-installed in XAMPP but if you need a newer version you can download an updated OCI8 PECL package from pecl.php.net. Pick an OCI8 release and select the DLL according to the architecture and thread safety mode. For example, if PHP is x86 and thread safety enabled, download "7.2 Thread Safe (TS) x86". Then replace "D:\xampp\php\ext\php_oci8_12c.dll" with the new "php_oci8_12c.dll" from the OCI8 PECL package.

    screenshot of PECL OCI8 download page

  5. Edit "D:\xampp\php\php.ini" and uncomment the line "extension=oci8_12c". Make sure "extension_dir" is set to the directory containing the PHP extension DLLs. For example,

  6. Download the Oracle Instant Client Basic package from OTN.

    Select the correct architecture to align with PHP's. For Windows x86 download "instantclient-basic-nt-" from the Windows 32-bit page.

    screenshot of Oracle Instant Client download page
  7. Extract the file in a directory such as "D:\Oracle". A subdirectory "D:\Oracle\instantclient_12_2" will be created.

    Add this subdirectory to the PATH environment variable. You can update PATH in Control Panel -> System -> Advanced System Settings -> Advanced -> Environment Variables -> System Variables -> PATH. In my example I set it to "D:\Oracle\instantclient_12_2".

  8. Restart the Apache server and check the phpinfo.php page again. It shows the OCI8 extension is loaded successfully.

    screenshot of PHP configuration page showing a section for OCI8

    If you also run PHP from a terminal window, make sure to close and reopen the terminal to get the updated PATH value.

  9. To run your first OCI8 application, create a new file in the XAMPP document root "D:\xampp\htdocs\test.php". It should contain:

    ini_set('display_errors', 'On');
    $username = "hr";                  // Use your username
    $password = "welcome";             // and your password
    $database = "localhost/orclpdb";   // and the connect string to connect to your database
    $query = "select * from dual";
    $c = oci_connect($username, $password, $database);
    if (!$c) {
        $m = oci_error();
        trigger_error('Could not connect to database: '. $m['message'], E_USER_ERROR);
    $s = oci_parse($c, $query);
    if (!$s) {
        $m = oci_error($c);
        trigger_error('Could not parse statement: '. $m['message'], E_USER_ERROR);
    $r = oci_execute($s);
    if (!$r) {
        $m = oci_error($s);
        trigger_error('Could not execute statement: '. $m['message'], E_USER_ERROR);
    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>".htmlspecialchars($colname,ENT_QUOTES|ENT_SUBSTITUTE)."</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>";
            echo $item!==null?htmlspecialchars($item, ENT_QUOTES|ENT_SUBSTITUTE):"&nbsp;";
            echo "</td>\n";
        echo "</tr>\n";
    echo "</table>\n";

    You need to edit this file and set your database username, password and connect string. If you are using Oracle Database XE, then the connect string should be "localhost/XE".

    The SQL query can also be changed. Currently it queries the special DUAL table, which every user has.

  10. Load the test program in a browser using http://localhost/test.php. The output will be the single value "X" in the column called "DUMMY".

You can read more about PHP OCI8 in the PHP manual, and in the free Underground PHP and Oracle Manual from Oracle.

Enjoy your coding with OCI8!

Join the discussion

Comments ( 17 )
  • Sricharan Friday, April 20, 2018
    Hello, I have followed the above instructions, but OCI8 module is not showing up in phpinfo() page.

    Please help me to fix this issue.

  • Christopher Jones Friday, April 20, 2018
    The best place to ask for help is the PHP forum https://community.oracle.com/community/development_tools/php You will need to post more details about what steps you followed and what errors you see.
  • manjula Sunday, September 16, 2018
    Fatal error: Uncaught Error: Call to undefined function oci_connect() in C:xampphtdocstestOracle.php:12 Stack trace: #0 {main} thrown in C:xampphtdocstestOracle.php on line 12

    Followed as explained, but still getting error
  • Christopher Jones Sunday, September 16, 2018
    See my previous comment about asking on a forum where it's easier to discuss.
  • Maciej Sunday, September 16, 2018

    All works find but one thing: National characters are missing (I am polish). Can you please advise?

    Thank you for great guide!
  • Christopher Jones Sunday, September 16, 2018
    Pass a character set to your connection call or set NLS_LANG in the process that starts PHP.

    Something like:

    $c = oci_connect("hr", "welcome", "localhost/XE", "AL32UTF8");

    See the globalization chapter of http://www.oracle.com/technetwork/topics/php/underground-php-oracle-manual-098250.html
  • Alessandro Porto Wednesday, December 12, 2018
    After all configurations one message is show when I try start Apache. Message is about file PHP7.dll is not exists in my computer.
  • Christopher Jones Wednesday, December 12, 2018
    See my previous comments about asking on a forum where it's easier to discuss!
  • luis tribuna Wednesday, January 9, 2019
    I have the Oracle 10g database and I follow all the steps as you described:
    However, when I restart Apache, I receive the following error message::
    Can not find the entry point of the OCIStmtFetch2 procedure in the dynamic link library (DLL) c: xammp php ext php_oci8_12c.dll
  • Christopher Jones Wednesday, January 9, 2019
    You need to upgrade your Oracle release to at least 11g and then make sure you use the matching OCI8 DLL. Or you can compile OCI8 from source code yourself to work with Oracle 10.

    You can get a few DB from https://www.oracle.com/technetwork/database/database-technologies/express-edition/downloads/index.html
  • Luis Tribuna Wednesday, January 9, 2019
    And if i cant update de database engine? i cant use php with oracle 10g database?
  • Luis Tribuna Wednesday, January 9, 2019
    The version of the snap-in client has to be the same as that of the database. or can it be 11g database and 12 client?
  • Christopher Jones Wednesday, January 9, 2019
    The version of the Oracle client libraries (e.g. Instant Client) can be different to the version of the Oracle Database. Oracle provides cross-version interoperability, see Oracle Support’s Doc ID 207303.1 for all the details. For example you can use Oracle client 11.2 with PHP to connect to Oracle Database 10.1. If your database and PHP are on the same computer, you need to be careful to use different PATH settings for each.

    If you have anymore questions, please use the PHP forum https://community.oracle.com/community/groundbreakers/database/developer-tools/php
  • Luis Tribuna Friday, January 11, 2019
    Can you help me with the creation of different PATH settings for each?
  • Christopher Jones Friday, January 11, 2019
    @Luis, a blog comment section is not the best place to answer detailed tech questions. Please use the help forum I mentioned.
  • DAVID Wednesday, January 23, 2019
    Hello my friend, I followed your step by step, and when I run de php script, the following alert is launched: Fatal error: Uncaught Error: Call to undefined function oci_connect()
  • Christopher Jones Wednesday, January 23, 2019
    See previous comments about where to ask for help.
Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.Captcha

Integrated Cloud Applications & Platform Services