Appendix A. Installing PHP and Oracle Software

To follow the examples provided throughout this book, you need to have a few pieces of software installed and working properly, so that you have the following servers up and running in your system:

  • Oracle database server

  • Web/PHP server

To achieve this, you have to install the following software components:

  • Oracle Database Server software

  • Oracle database

  • SQL command-line tool to interact with the database

  • Oracle Client libraries

  • Web server with activated support for PHP

While Chapter 1 briefly discusses the above software components, this appendix provides a quick-and-dirty guide to obtaining, installing, and configuring them to work together.

Installing Oracle Database Software

As discussed in Chapter 1 Getting Started with PHP and Oracle in the Obtaining Oracle Database Software section, although most of the Oracle products are available on a commercial basis, you can download them from Oracle Technology Network at http://www.oracle.com/technology/software/index.html for free. Then, you can use the downloaded software for free while developing and prototyping your applications, and buy the license only for those Oracle products that will be used in your final product.

Note

The Oracle Technology Network Developer License can be found at http://www.oracle.com/technology/software/htdocs/devlic.html.

As you learned in Chapter 1 in the section Choosing Between Oracle Database Editions, Oracle Database is available in several editions. An important thing to consider when choosing between Oracle Database editions is what edition best suits your needs and budget.

Once you have decided which edition of Oracle Database to use, it's time to download the appropriate installation archive file and then walk through the installation process. The following section describes the basic installation steps for Oracle Database 10g Enterprise/Standard editions on both Windows and Unix systems. It is followed by a section that describes the basic installation steps for Oracle Database 10g Express Edition.

Note

For detailed information on how to install Oracle Database software, see Oracle documentation: Oracle Database Installation Guide for your operating system platform. Oracle documentation is available from the documentation section of the OTN website at: http://www.oracle.com/technology/documentation/index.html.

Installing Oracle Database Enterprise/Standard Editions

Once you have downloaded the installation archive file, you can extract it on your hard disk and then start the installation.

Most installation steps are common to all operating system platforms and involve running the Oracle Universal Installer, a Java-based graphical user interface tool that is used to install and remove Oracle software.

Here are the basic installation steps for Oracle Database 10g Enterprise/Standard Editions. By following these steps, you will not only install Oracle Database Server software but also an Oracle database, Oracle Client libraries, and SQL*Plus—an SQL command-line tool to interact with the database.

  • Log on to the computer as a user with the administrative privileges so that you can install Oracle Database software and run the database.

  • Navigate to the directory where you downloaded the installation archive file, extract it, and then execute setup.exe to start Oracle Universal Installer on Windows. On Linux, run the following command: $ ./runInstaller

The following figure shows what the first screen of the Oracle Universal Installer looks like on Windows.

Installing Oracle Database Enterprise/Standard Editions
  • On the first screen of the Oracle Universal Installer, select either Basic Installation to quickly install Oracle Database software or Advanced Installation to have advanced installation choices.

    Note

    Selecting the Advanced Installation option allows you to customize your installation. For information about advanced installation choices, see Oracle Database Installation Guide for your platform.

From now on, it is assumed that you have chosen the Basic Installation option.

  • On the same screen, specify the full path to the directory where you want to install the database.

  • On the same screen, choose what database product you want to install: Enterprise Edition, Standard Edition, Personal Edition, or Custom Installation.

  • On the same screen, check the Create Starter Database box to create a database during installation. This option is available on this screen when you select Basic Installation. Having checked the Create Starter Database box, you have to specify the Global Database Name and the password for the SYS, SYSTEM, SYSMAN, and DBSNMP administrator accounts.

    Note

    A global database name consists of the database name and database domain, and must be unique within the same network. So, you may find it convenient to use the network domain name as the database domain, but generally speaking you don't have to follow this rule. For simple cases, you need not specify a database domain at all—you may use only the database name.

  • On the same screen, click Next to continue.

  • (For Unix and Linux only) On the Specify Inventory Directory and Credentials screen, specify the full path to a directory for installation files and make sure to specify an operating system group that has "write" permission to this directory.

    Note

    This screen appears only during the first installation of Oracle software on this computer.

On the Product-Specific Prerequisite Checks screen, make sure that your system meets the minimum requirements for installing the chosen products. Once all the checks have been successfully completed, click Next to continue.

Note

You can proceed with the installation only if the status of each check performed in this stage is Succeeded or Warning.

  • On the summary screen, review the installation information and click the Install button to start the installation. This opens the Install screen that shows installation progress.

  • On the Configuration Assistants screen, review the status information for the configuration assistants that are started automatically and used to configure the software and create a database.

  • (For Unix and Linux only) On the Execute Configuration Scripts screen, read the instructions and then run the scripts mentioned on this screen as the root user.

  • On the End screen, note the information and exit the Installer.

That is it. Your database is up and ready for use now.

Installing Oracle Database Express Edition (XE)

If you want to use an Oracle database for free even in the final product, consider Oracle Database Express Edition—a lightweight Oracle database that is free to develop, deploy, and distribute. This section describes the basic installation steps for this Oracle Database edition.

Note

One word of warning before you proceed with Oracle Database Express Edition. Note that some Oracle Database features are not available in this lightweight edition of Oracle Database. For example, the XQuery feature discussed in Chapter 8 in the Querying Data with Oracle XQuery section is not available in Oracle Database XE. Also, the Oracle Virtual Private Database (VPD) feature discussed in Chapter 6 in the Row-Level Security Using VPD section is available only in Enterprise Edition of Oracle Database.

Once you have completed the following installation steps, you will have an Oracle Database XE Server (including an Oracle database), Oracle Database XE Client, and SQL*Plus installed on your computer.

Installing Oracle Database XE on Windows

Here are the installation steps for Oracle Database 10g Express Edition on Windows:

  • Log in to Windows as a user of the Administrators group.

  • Make sure that the ORACLE_HOME environment variable is not set in your system. Otherwise delete it. This can be done from the System Properties dialog, which can be invoked from Control Panel|System.

  • Double-click the Oracle Database XE installation executable downloaded from OTN to run Oracle Database XE Server installer.

The following figure shows what the screen of the Oracle Database XE Server installer looks like after you run it.

Installing Oracle Database XE on Windows
  • In the Welcome window of the Wizard, click Next.

  • In the License Agreement window, click I accept and then click Next.

  • In the Choose Destination Location window, choose the directory for installation and click Next.

  • If at least one of the following port numbers: 1521, 2030, 8080 is already in use in your system, you will be prompted to enter an available port number. Otherwise, the above numbers will be used automatically.

  • In the Specify Database Passwords window, enter the passwords for the SYS and SYSTEM database accounts and click Next.

  • In the Summary window, click Install to proceed to installation, or Back to turn back and modify the settings.

  • After the installation is complete, click Finish.

That is it. Your database is up and ready for use now.

Installing Oracle Database XE on Linux

Here are the installation steps for Oracle Database 10g Express Edition on Linux:

  • Log in to your computer as root.

  • Change directory to the one in which you downloaded the Oracle Database XE oracle-xe-10.2.0.1-1.0.i386.rpm installation executable and install the RPM: $ rpm -ivh oracle-xe-10.2.0.1-1.0.i386.rpm

  • When prompted, run the following command to configure the database: $ /etc/init.d/oracle-xe configure

  • When entering configuration information, accept the default port numbers for the Oracle Database XE graphical user interface and Oracle database listener: 8080 and 1521 respectively. Also, enter and confirm the passwords for the SYS and SYSTEM default user accounts.

    Note

    If, when configuring the database, you select Yes to the question of whether you want the database to automatically start along with the computer, then the database is up and ready for use now. Otherwise you have to start it manually as follows: $ /etc/init.d/oracle-xe start

Installing Apache HTTP Server

Before you can install PHP, you must have a web server installed and working in your system. Although PHP has support for most of the web servers worth mentioning, Apache/PHP remains the most popular combination among developers.

The Apache HTTP server is distributed under the Apache License, a free software/open-source license whose current version can be found on the licenses page of the Apache website at: http://www.apache.org/licenses/.

You can download the Apache HTTP server from the download page of the Apache website at: http://httpd.apache.org/download.cgi.

As mentioned in Chapter 1 in the Apache HTTP Server section, Oracle recommends that you install a web server on another machine but on the same network as the database server. However, for simplicity you can have both the Oracle database server and web server on the same machine.

In fact, installing Apache is a very easy process: On Windows, if you have downloaded the version of Apache for Windows with the .msi extension (the recommended way), you just run the Apache .msi file and then follow the wizard. On Unix-like systems, once you have downloaded a source version of the Apache HTTP server, you perform standard operations that you normally deal with when it comes to installing new software from sources: extract, configure, compile, and install.

Once you have Apache installed and configured, you can start it. On Windows, Apache is normally run as a service. You can configure service startup by choosing Automatic, Manual, or Disabled. On Unix-like systems, Apache, the httpd program, is run as a demon. It is recommended that you use the apachectl control script to invoke the httpd executable:

# /usr/local/apache2/bin/apachectl start

To make sure that your web server is up and running on your machine, open your web browser to the URL http://localhost/.

The following figure shows what the default page of Apache web server looks like.

Installing Apache HTTP Server

Now that you have your web server up and running, you can move on to the next step, obtaining and installing PHP.

Installing PHP

The current recommended releases of PHP are available for download from the downloads page of the php.net site at:

http://www.php.net/downloads.php

From this page, you can download the latest stable release of PHP 5 and then follow the steps below to install PHP in your system. For further assistance along the way, you may consult the Installation and Configuration manual available on the php.net web site at: http://www.php.net/manual/install.php. Alternatively, you might read the install.txt file that is shipped with PHP.

Installing PHP on Windows

Here are the basic installation steps for PHP 5 on Windows:

  • Extract the distribution file into the c:php directory.

  • Add the C:php directory to the PATH to make php5ts.dll available to the web server modules.

  • Rename php.ini-recommended to php.ini.

  • In php.ini, set the doc_root to your htdocs directory of Apache. For example:

    doc_root = c:Program FilesApache GroupApache2htdocs
    
  • In the Apache httpd.conf configuration file, to install PHP as an Apache module, insert the following two lines:

    LoadModule php5_module "c:/php/php5apache2.dll"
    AddType application/x-httpd-php .php
    
  • In the Apache httpd.conf configuration file, configure the path to php.ini:

    PHPIniDir "C:/php"
    
  • Restart Apache.

As an alternative to the above manual installation, you might use the Windows PHP installer that is also available from the downloads page of the php.net website.

Note

Although the Windows PHP installer is the fastest way to make PHP work, it doesn't allow you to set every option as you might want to. So, using the installer isn't the recommended method for installing PHP.

Once you have PHP installed on your Windows system, you might want to set some extensions for added functionality. It is important to note that many extensions are built into the Windows version of PHP. To use these extensions, you just uncomment them in the php.ini configuration file—no additional DLLs are required. However, some of the extensions require extra DLLs to work. For example, the PHP OCI8 extension needs the Oracle Client libraries.

Installing PHP on Unix-Like Systems

Here are basic installation steps for PHP 5 on Unix-like systems:

  • Extract the distribution file:

    # gunzip php-5xx.tar.gz
    # tar -xvf php-5xx.tar
    
  • Change dir to the directory containing the PHP sources:

    # cd php-5xx
    
  • Configure your PHP installation:

    # ./configure --with-apxs2=/usr/local/apache2/bin/apxs
    

    Note

    You cannot configure PHP to support the PHP OCI8 extension until you install the Oracle Client libraries required to run OCI applications (unless you have PHP and Oracle installed on the same computer). You'll need to recompile PHP for OCI8 support once you have these libraries installed. See the Oracle Instant Client section for details.

  • Compile and then install PHP:

    # make
    # make install
    
  • Set up php.ini.

    # cp php.ini-dist /usr/local/lib/php.ini
    
  • Edit the httpd.conf Apache configuration file to load the PHP module into Apache:

    LoadModule php5_module modules/libphp5.so
    
  • In httpd.conf, add handlers for files with the .php and .phps extensions:

    AddType application/x-httpd-php .php
    AddType application/x-httpd-php-source .phps
    
  • Restart Apache:

    # usr/local/apache2/bin/apachectl start
    

By now you should have a working Apache/PHP web server.

Testing PHP

Once you have finished the installation steps, you might want to test PHP. The easiest way to make sure that PHP works properly is by using the following simple PHP script:

<?php
phpinfo();
?>

Save this script as phptest.php in the htdocs directory of Apache and then run it in your browser by opening the following URL:

http://yourservername/phptest.php

Provided your Apache/PHP web server is up and running, the phptest.php script should output a large amount of information about the current state of PHP. Graphically it might look like the following figure.

Testing PHPPHPinstalling, on Unix-like systems

As expected, the phpinfo output doesn't contain an OCI8 section&mdash;we have installed PHP without OCI8 support. The next section discusses how to add the OCI8 support to an existing installation of PHP.

Bridging the Gap Between Oracle and PHP

By now you should have an Oracle database and Apache/PHP web server installed and working. However, before you can start developing PHP/Oracle applications, you have to enable the OCI8 extension in your PHP installation.

Oracle Instant Client

If you have both the database and web server installed on the same computer then you already have all the required Oracle components&mdash;no Instant Client is required, and so you can skip to the next section Enabling the OCI8 Extension in an Existing PHP Installation.

However, if you have the database and web server installed on different computers, you will need to install another piece of software, which will bridge the gap between Oracle and PHP. Specifically, you have to install the Oracle client libraries needed by the PHP OCI8 extension.

Consider Oracle Instant Client, a package containing Oracle client libraries required to run OCI, OCCI, and JDBC-OCI applications. Note that Oracle Instant Client comes with a free license for both development and production environments.

You can download a copy of Oracle Instant Client specific to your platform from the Instant Client web page on OTN at:

http://www.oracle.com/technology/tech/oci/instantclient/instantclient.html

From the above page, you should download the Basic Instant Client Package that includes all the files required to run OCI, OCCI, and JDBC-OCI applications.

On Windows, perform the following steps to install the Instant Client Package:

  • Download a copy of Oracle Instant Client from OTN.

  • Unzip the package into a single directory in your file system.

  • Add the path to the directory in which you unzipped the libraries to the PATH environment variable.

On UNIX-like platforms, perform the following steps:

  • Download a copy of Oracle Instant Client from OTN.

  • Unzip the package into a single directory in your file system.

  • Set LD_LIBRARY_PATH to the directory in which you unzipped the libraries.

Once you perform the above steps, you can move on and enable the OCI8 extension in your PHP installation.

Enabling the OCI8 Extension in an Existing PHP Installation

On Windows, perform the following steps to enable the OCI8 extension in your existing PHP installation:

  • In php.ini, uncomment the OCI8 extension line:

    extension=php_oci8.dll
    
  • In php.ini, set the extension_dir directive to the directory in which php_oci8.dll resides:

    extension_dir= c:phpext
    
  • Restart Apache.

On UNIX-like platforms, perform the following installation steps:

  • Run configure with Apache2 and OCI8 support:

    # cd php-5xx
    # ./configure --with-apxs2=/usr/local/apache2/bin/apxs 
    --with-config-file-path=$HOME/apache/conf 
    --with-oci8-instant-client=/home/instantclient10_2 
    --enable-sigchild
    
  • Rebuild PHP:

    # make
    # make install
    
  • Restart Apache:

    /usr/local/apache2/bin/apachectl start
    

To make sure that the OCI8 extension was successfully enabled, you might run the testphp.php script discussed in the Testing PHP section earlier in this appendix. This time the output should include the OCI8 section verifying that OCI8 support is enabled.

Installing SQL*Plus Instant Client

Most of the examples in this book assume that you will use SQL*Plus when it comes to performing database administration or creating database objects. Note that SQL*Plus is installed by default when you install the Oracle Database software. So, if you are going to use a local database, you don't need to install SQL*Plus since you already have it. Otherwise, you might take advantage of SQL*Plus Instant Client&mdash;the SQL*Plus command-line tool that allows you to communicate with a remote database.

To install SQL*Plus Instant Client on your computer, perform the following steps:

  • Download the SQL*Plus Instant Client Package specific to your platform from the Instant Client web page on OTN at:

    http://www.oracle.com/technology/tech/oci/instantclient/ instantclient.html

  • Unzip the package to the same directory where you unzipped the Basic Instant Client Package files.

  • Optionally, set a user environment variable NLS_LANG to an appropriate value.

    Note

    The NLS_LANG parameter is composed of three optional components: language, territory, and character set. To specify it, you use the following syntax: NLS_LANG = language_territory.charset. NLS_LANG defaults to AMERICAN_AMERICA.US7ASCII. For information about supported NLS_LANG settings, see Oracle documentation: Oracle Database Globalization Support Guide.

That is it. Now you can use SQL*Plus Instant Client to connect to a remote database.

Installing Zend Core for Oracle

As mentioned in Chapter 1, section Zend Core for Oracle, you might significantly speed up and simplify the process of making PHP and Oracle software work together by taking advantage of Zend Core for Oracle, a pre-built stack that delivers a rapid development and deployment foundation for Oracle-driven PHP applications, saving you the trouble of separately downloading and installing the required pieces of software.

Once you have completed the following installation steps, you will have a Web/PHP server ready to work with your Oracle database.

Installing Zend Core for Oracle on Windows

Here are the installation steps for Zend Core for Oracle on Windows:

  • Log in to your computer as a user of the Administrators group.

  • Download Zend Core for Oracle from Zend Network. You can start by visiting the following page:

    https://www.zend.com/core/oem_registration.php?access_ code=OracleDB
    
  • After you have downloaded the Zend Core for Oracle package, double-click it to start the installation wizard.

  • In the Welcome window, click Next.

  • In the License Agreement window, select I accept … and click Next.

  • In the Setup Type window, you can choose either Complete or Custom setup options. If you select Complete, all of the Zend Core for Oracle components will be installed. Otherwise, you will be able to choose a folder for Zend Core for Oracle installation and components to install. Click Next to continue.

  • In the Web Server Selection window, select the web server to be used. It is recommended that you select the default Apache installed on your computer. Then, click Next.

  • In the Web Server API window, accept the recommended Server API and click Next.

  • In the Extension Association window, choose the extensions that will be associated with the Core PHP installation and click Next.

  • In the Password window, enter a password for accessing the Zend Core for Oracle GUI and click Next.

  • In the Ready to Install the Program window, click Install to start installation.

  • In the Installation Complete window, choose Yes for the restart option and click Finish to complete the installation and restart the computer.

That is it. Now you should have a Web/PHP that is server ready to work with your Oracle database.

Installing Zend Core for Oracle on Linux

Here are the installation steps for Zend Core for Oracle on Linux:

  • Log in to your computer as root.

  • Download Zend Core for Oracle from Zend Network. You can start by visiting the following page:

    https://www.zend.com/core/oem_registration.php?access_ code=OracleDB
    
  • After you have downloaded the package, extract Zend Core for Oracle:

    $ tar -zxf ZendCoreForOracle-v1.3.1-Linux-x86.tar.gz
    
  • Change directory to ZendCoreForOracle-v1.3.1-Linux-x86:

    $ cd ZendCoreForOracle-v1.3.1-Linux-x86
    
  • Start installation:

    ./install
    
  • In the Welcome screen, click OK to continue.

  • In the License Agreement screen, click exit. Then, click Yes to accept the license agreement and continue with the installation.

  • When prompted, choose the directory for installing Zend Core for Oracle and click OK.

  • In the next screen, enter a password for accessing the Zend Core for Oracle GUI and click OK.

  • When prompted, select the web server for Zend Core installation and click OK. It is recommended that you select the default Apache installed on your computer.

  • In the next screen, accept the selected installation method for the PHP on the web server and click OK.

  • In the next screen, select a virtual server for the Zend Core GUI and click OK.

  • When prompted, select to restart the web server to apply the changes.

  • In the final screen, click Exit to complete the installation and restart the web server.

That is it. Now you should have a Web/PHP that is server ready to work with your Oracle database.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.191.135.224