Sunday, October 25, 2009

Installing Oracle 10g Express Edition + ZendCoreForOracle PHP + Java + Tomcat 6 on Ubuntu 9.04



I recently wanted to see what all the hype over Oracle was all about. I will say i was very pleasantly surprised! They have a fantastic suite of utilities and products to make real database work and administration a breeze. So after some digging i found out they offer their 10g EE for free with a few limitations. Here's the basic run down taken from:

http://www.oracle.com/technology/products/database/xe/pdf/dbxe_faq.pdf

    * What is Oracle Database 10g Express Edition?
          o Oracle Database 10g Express Edition (Oracle Database XE) is an entry-level, small footprint starter database which is:
          o Free to download
          o Free to develop & deploy
          o Free to distribute (including ISVs)
          o Oracle Database XE is built using the same code base as Oracle Database 10g Release 2 product line—Standard Edition One, Standard
            Edition, and Enterprise Edition—and is available on 32-bit Windows and Linux platforms.

    * Who should use Oracle Database XE?
          o Oracle Database XE is the perfect choice for many different groups, including:
          o Developers working on PHP, Java, .NET, and other applications that require a database
          o DBAs who need a free starter database for training and deployment
          o Independent Software Vendors (ISVs) who want to embed an Oracle database in their application or product to extend customer value at no
            additional cost
          o Educational institutions and students who need a free starter database for their curriculum.

    * Can I use Oracle Database XE for free development?
          o Yes. There are no database license costs associated with developing applications for Oracle Database XE which offers the complete
            integrated set of Oracle Database programming interfaces including:
          o SQL, PL/SQL
          o Java, C, and PHP
          o Windows .Net
          o Oracle Application Express
          o C++, ODBC, OLE DB

    * Can I use Oracle Database XE for free deployment?
          o Oracle Database XE is free for runtime usage with the following limitations:
          o Supports up to 4GB of user data (in addition to Oracle system data)
          o Single instance only of Oracle Database XE on any server
          o May be installed on a multiple CPU server, but only executes on one processor in any server
          o May be installed on a server with any amount of memory, but will only use up to 1GB RAM of available memory

    * Can I distribute Oracle Database XE?
          o Yes. Oracle Database XE can be freely distributed as a standalone database or as part of a third-party application or product, provided
            the criteria defined above is adhered to.

So as you can see for someone like myself who's just starting out in the world of Enterprise Class database administration and hopefully someday development, what Oracle offers here is outstanding. I doubt any of my home test projects will come close to 4GB of data, and yet i still get a rich, full featured RDBMS to boot, not bad.

So my motivation? Well as stated i'd like to learn about managing large Enterprise Scale datasets. I'd like to continue at my current job and advance in that direction, ultimately leading to actual development of in house or 3rd party applications. Since my favorite languages are C and PHP (and learning Java) that's what i set my focus on. Developing in C with Oracle is very easy, PHP connectivity to Oracle with ZendCoreForOracle
is easy, or using Java and Tomcat6. So i set out to get this running on my Ubuntu 9.04 development box. I had to tweak here and there so i decided to write my steps down incase someone could make use of them. Unfortunately there were way to many late night Google searches to remember all my sources. The bulk of this is from each packages own install documentation with tidbits from various Open Source communities. For those who continue to contribute, thank you for all your hard work.

BEFORE WE BEGIN:
- For this example i installed Ubuntu 9.04 Desktop in a Virtual Machine using VirtualBox from Sun Microsystems.
    15GB HD
    384MB RAM
    64MB Video RAM
(NOTE: To install Oracle 10g XE you need at least a 768MB swap file. I recommend doing custom partitions, adding 1GB swap file, and simply assigning the rest to /)

- So first of all lets grab the files we'll need, just save them to your desktop:
 
    http://www.zend.com - Navigate to "Downloads > Zend Core For Oracle" and
    (NOTE: You will HAVE to sign up to download, it is fast and free.)
 
    http://www.oracle.com - Oracle has some of the best documentation and tutorials i've ever seen.
    (NOTE: You will HAVE to sign up to download, it is fast and free.)
      * From Homepage > Database > Express Edition (under "Oracle Database Editions and Options" section)
      * FREE DOWNLOAD - Here is where you actually download Oracle 10g XE
      * You'll want this version: Oracle Database 10g Express Edition (Western European) (unless you're out of the US or don't speak English,
        in which case how are you reading this 0_o?!)
      * Since we're on Ubuntu and it uses Debian's package management system, we simply grab the *.deb file AFTER clicking that we Accept the
        license agreenment up top.

- Update apt

    sudo apt-get update

- Run ALL Ubuntu updates and restart if needed before beginning this tutorial.
- Version i'm using:
    * Ubuntu 9.04              
      (NOTE: I've also installed Ubuntu 9.10 Karmic RC on my Aspire One netbook (Netbook Remix edition) this same tutorial worked flawlessly.)
    * Oracle 10g XE            
      oracle-xe_10.2.0.1-1.0_i386.deb
    * ZendCore for Oracle      
      ZendCoreForOracle-2.5.0-linux-glibc21-i386.tar.gz
- Once that's complete and we've saved our files to our desktop, lets begin!

WARNING:
- This tutorial installs several services with no mention of securing them. I don't offer a firewall tutorial or anything else that would make these "secure." Please understand this setup is on my HOME completely internal virtual image which is only on while i'm developing. If you plan on putting this on an actual physical server you have in your home that should be fine, but i would still try and secure it especially if you have a WAP of any kind connected to your LAN. If you plan on putting this on a corporate\company Intranet most definitely learn to secure the box and it's services before deploying, even in a test environment. If you're putting this on a box that's WAN exposed, i really hope you're not reading this message for advice. Consider yourself warned, these tools are great out of the box, but there's always potential to be broken into. I make no claim that this tutorial will prevent that, you're using it at your own risk!

- Open a terminal window:

      Applications > Accessories > Terminal

- First we need to ensure we do NOT have Apache2 or libapache2-mod-php5 installed, these conflict with the ZendCoreForOracle PHP version that we downloaded (they may offer a multi-threaded version for purchase, free appears single threaded only). Please ensure if you're NOT doing this in a VM be cautious. Backup your web server and ALL config. files for it before just trashing things.

      dpkg -l | grep apache2
      dpkg -l | grep php

does either return a value? If so, the following two commands are ALL we care to remove, otherwise move on:

      sudo apt-get remove apache2
      sudo apt-get remove libapache2-mod-php5

- Next we want to navigate to our desktop and install a dependency, libaio1 and Oracle 10g XE.

      cd Desktop ; ls
      sudo apt-get install libaio1
      sudo dpkg -i oracle-xe_10.2.0.1-1.0_i386.deb

- Now we setup inital Oracle configuration. For me when i'm testing something in a virtual machine i use an easy pw like:  pass123 , or similar. Obviously if you're deploying this on a more public server, even internally, please choose SANE passwords.

      sudo /etc/init.d/oracle-xe configure


      * Leave default port (8080)
      * Leave default listener port (1521) 
      * Enter and confirm your Oracle password

      (NOTE: This is used to log into the sys and system administration accounts)

      * Leave default 'y' to startup on boot 
      * It'll startup the Oracle Net Listener, and say, "Configuring Database...."

      (NOTE: Configuring the database may take a while, especially in a VM on a slow host PC)

- Now we test our new installation. Point your browser to the following URL:

      http://localhost:8080/apex

      You should see a web page titled "Application Express Login" and "ORACLE Database Express Edition" on the top.

- If you don't, you b0rk3d something, go back and re-install it. Now since i'm sure we remembered our password we set, lets login as the sys user:

      sys
      pw (whatever you set)

      Should see "Administration", "Object Browser", "SQL" etc...

- Next since the free version of ZendCoreForOracle PHP is single threaded lets install and test a single threaded version of Apache for Ubuntu:

      sudo apt-get install apache2-mpm-prefork

      (NOTE: When starting and stopping Apache2 it may complain about being unable to determine servers fully qualified domain name and wants to use
      127.0.1.1 for 'ServerName' that's fine, it will function fine.)

- Verify Apache installed ok by going to the following URL:

      http://localhost/

      Should see "It Works!" if so move on.

- Now lets install and test ZendCoreForOracle

      tar -xvzf ZendCoreForOracle-2.5.0-linux-glibc21-i386.tar.gz
      cd ZendCoreForOracle-2.5.0-linux-glibc21-i386/
      sudo ./install -g

      (NOTE: -g is a graphical install. Run ./install , alone for a list of options)

      * (hit enter)
          (Read agreement)
      * (hit enter)
          (Next)
      * (hit enter)
          (Yes to accept license)
      * (hit enter)
          (Leave default install location to /usr/local/Zend)
      * (enter web gui pw)
          (I make it same as Oracle for testing, use down arrow to navigate to "Verify Password" box)
      * (hit enter)
      * (hit enter)
      * (hit enter)
          (Leave install / configure at defaults)
          (NOTE: Here you can install Zend Core bundled Apache, however i prefer to install what comes with Ubuntu, i know
          it's been tested in THIS environment)
      * (hit enter)
          (Since we have apache and /etc/init.d/apache2 is it, and it's default just hit enter)
      * (hit enter)
          (Leave it on Yes, to auto detect and configure Apache2)
      * (hit enter)
          (Yes Apache2 start command is: /etc/init.d/apache2 start)
      * (change htdocs)
          (By default Apache2 serves files from /var/www ZendCoreForOracle just needs that value. Use down arrow to change fields)
      * (hit enter)
          (Keep default Apache Module, as installation method)

  Now it's going to download the components it needs and install them, shouldn't take but a few moments on a moderately fast connection.

      * (select Finish installation)
      * (hit enter)

- Now that ZendCoreForOracle is installed we test it by going to:

      http://localhost/ZendCore

      Should see: Zend Core(tm) for Oracle login

- Again we should remember our password. One of the things Oracle tutorials will recommend is you turn on debugging info while developing, it does
  help greatly. Lets do that first. Log into Zend Core and navigate to:

      Configuration > (expand) Error Handling and Logging > (set to On) display_errors > Save Settings > Logout

  then restart Apache2:

      sudo /etc/init.d/apache2 restart

- Another thing Oracles tutorials have you do is make a public_html folder available from your home directory via the userdir module in Apache 2.2.
  So as you develop an application it's accessible from: http://localhost/~user/. In Apache 2.2 this is how you turn that on:

      sudo a2enmod userdir
      sudo /etc/init.d/apache2 restart

- Now we're going to create a couple test files and our directory to hold them in.

      cd ~
      mkdir public_html
      cd public_html
      nano index.html


            Add the following:
                <HTML>
                Hello World!
                </HTML>


      nano test.php


            Add the following:
                <?php
                phpinfo();
                ?>

- Now test our locally served directories are working, including PHP support (replacing 'user' with your user name):

      http://localhost/~user/
      http://localhost/~user/test.php

  (NOTE: You can also copy these files to /var/www , and see regular content is served just fine as well)

- Now lets get Java and Tomcat6 up and running. We need the full JDK for a full development environment, so lets start with Java:

      aptitude search jdk
        (mine is: sun-java6-jdk)
      sudo apt-get install sun-java6-jdk

      (Read license agreenment, tab to OK)
      (hit enter)
      (select Yes hit enter)
 
  to test:

      java -version
 
- To get tomcat:

      aptitude search tomcat
      sudo apt-get install tomcat6

  I've used Tomcat 6 before and it works great out of the box on Ubuntu. Only thing to keep in mind is Oracle is listening on port 8080
  (tomcats default). So we edit our Tomcat config to use a different port:

      sudo nano /etc/tomcat6/server.xml

  Look for the line:

      <Connector port="8080" protocol="HTTP/1.1"
          connectionTimeout="20000"
          ...
          ... />
 
  and change 'port' to something else, i use: 8081 to keep it simple. Restart
  tomcat:

      sudo /etc/init.d/tomcat6 restart

  (NOTE: I would highly recommend installing Tomcat6's examples and docs
   great resource)

      sudo apt-get install tomcat6-examples tomcat6-docs
  
- Last i use the following to make sure everything is up and running. BUT!!!! first things first! The scariest thing after a huge setup like this, reboot! :). After that each of the following should "just work" if not backtrack and see if you missed something:

      http://localhost/               (Default Apache2 served from /var/www should say "It Works!")
      http://localhost/~user/         (Our index.html file served from our ~/public_html folder)
      http://localhost/~user/test.php (Our test.php file served from our ~/public_html folder)
      http://localhost/ZendCore       (ZendCoreForOracle Web GUI Login)
      http://localhost:8080/apex      (Oracle 10g XE Login)
      http://localhost:8081/          (Tomcat6 instance)
  
- If you made it through all that, congrats! and enjoy!

Happy Coding,
FMorales...

EXTRAS:
- When starting Oracle Tutorials you have to unlock the HR account. I may have missed it but it wasn't to obvious so here's how to do it incase you want to "get ahead" and be ready to jump into their Application Express tutorials:

      http://localhost:8080/apex
        (Login as 'sys' with the system password)
    
      Administration > Manage Database User > HR
  
      Set PW to 'hr' and confirm
      Change "Account Status" to Unlocked
      Click Alter User
  
  Now when you start with tutorials your HR user will be setup correctly to grab and manipulate the default dataset that comes with the database.

- Helpful links:
  (NOTE: If you start with the first link, and head strait down, you'll have a VERY good grasp of all that you actally get with, and can do in Oracle 10g XE. It's truly amazing)

  * Getting started guide:
    http://download.oracle.com/docs/cd/B25329_01/doc/admin.102/b25610/toc.htm
 
  * Online self-study tutorial:
    http://st-curriculum.oracle.com/tutorial/DBXETutorial/index.htm
 
  * Create Oracle 10g XE application:
    http://www.oracle.com/technology/obe/xe/getstarted/getstarted.htm
 
  * All online docs in HTML\PDF form:
    http://www.oracle.com/pls/xe102/portal.all_books
 
  * PHP Manual:
    http://www.php.net/manual/en/
 
  * Tomcat6 Documentation and Examples:
    (If you installed Tomcat6 examples & docs)
    http://localhost:8081/docs/
    http://localhost:8081/examples/
    http://java.sun.com/products/servlet/docs.html
 
  * Beginning Java
    http://java.sun.com/new2java/

No comments:

Post a Comment