Developing Software in J2EE

Developing Software in J2EE

HSQLDB – What a piece of …..

First, I know I haven’t posted in a while… I’ve been extremely busy.  Will there be more posts sooner rather than later?  Probably not.  But I’ve not abandoned this project.  I just need to find some time and I don’t have any right now.

Now, on to the post.

I needed a small lightweight database that I could embed in an application that I was writing.  I looked around (not very hard) and came across HSQLDB and just picked it at random more or less.  What a piece of crap this database is and here’s why:

1. I’d had the database up and my tables created and I needed to add a new column.  The database would not let me.  Gave me some ridiculous error message about “String data right truncation”. I don’t have the full error message, and would rather not post it to be honest in case a search engine picks it up (and some poor soul thinks I have the answer) but it was esoteric and useless.  I saw some post somewhere about copying the data out of the table into a temp table and then back.  Crazy.

2. I use NetBeans for my IDE.  I also use it for manipulating my databases.  It’s not the best but it does most of my work for me.  When you do a simple select, NetBeans limits the number of rows to 20.  Every time I tried to do a select, with an HSQLDB database, with NetBeans, and the table had more than 20 rows, it would crash. CRASH!  Some form of nullpointerexception.  If I changed the number (20) to greater than the number of rows in the table, everything was fine.

3. The final straw was when it started dropping data.  The application I wrote, would start up the database, put data in it and then shut it down.  If there were 2 rows, the final row would get lost.  To be fair, this could have been my application that did this (although I don’t think so).  Because it really felt like it wasn’t flushing the data from memory into the database.  I say this because if the database was just “running” and I would run the application then both rows would get put into the database.  Again, I don’t think so though.  The database shouldn’t drop data.

So, I’m done with it.  HSQLDB is a complete piece of crap as far as I’m concerned.  I’m looking at Derby at the moment.  It seems much more stable.

June 15, 2010 Posted by | Database, Java | , , | Leave a Comment

Environment Consistency – Apache HTTP Server (Windows)

We need to make our life easier by creating consistency for every machine. What this means is every machine you try to use, whether it be yours or your colleagues, the environment will be the same when you sit down to help them with something. This is very important if you’re a Development Manager and you’re trying to help one of your staff.

This is one of several posts in regards to this subject.

Here we’re going to be install the Apache HTTP Web Server.  We are going to download the HTTP Server from Apache’s website.  The file I downloaded is “apache_2.2.14-win32-x86-no_ssl.msi”.

After downloading the file, double click on it and start the installer which will show this dialog box:

Installing Apache Screen

Installing Apache Screen

Click “Run” and you’ll see this dialog box:

Apache Installation Wizard Screen

Apache Installation Wizard Screen

Click “Next” and this dialog box will appear:

Apache Installation Wizard License Screen

Apache Installation Wizard License Screen

Click “I accept the terms in license agreement” and then click “Next” to show this dialog box:

Apache Installation Wizard Read Me Screen

Apache Installation Wizard Read Me Screen

Click “Next”

Apache Installation Wizard Server Configuration

Apache Installation Wizard Server Configuration

On this screen you may want to edit the items.  I just left it as the defaults and clicked on “Next”

Apache Installation Wizard Setup Type Screen

Apache Installation Wizard Setup Type Screen

Click on “Custom” and then click “Next”

Apache Installation Wizard Custom Setup Screen

Apache Installation Wizard Custom Setup Screen

Again, just leave the defaults and click “Next” to see this dialog box:

Apache Installation Wizard Install Screen

Apache Installation Wizard Install Screen

Click “Install” to start the installation process and you should see a window like the following:

Apache Installation In Progress Screen

Apache Installation In Progress Screen

You may see some DOS boxes pop up during the installation process as well.  They’re harmless.

After the installation completes, you’ll see the following dialog box:

Apache Installation Wizard Completed

Apache Installation Wizard Completed

Click Finish.

Apache is now installed and is started automatically.  You’ll see a little icon down in the task bar that looks like this:

Apache Icon

Apache Icon

You can stop and start the server using this.  But the server is already started so let’s confirm that it’s running by going to http://localhost.  You should see the following in your browser when you do this:

Apache Installation Confirmation

Apache Installation Confirmation

You’re done!

January 25, 2010 Posted by | Development Environment | , | Leave a Comment

Environment Consistency – MySQL (Windows)

We need to make our life easier by creating consistency for every machine. What this means is every machine you try to use, whether it be yours or your colleagues, the environment will be the same when you sit down to help them with something. This is very important if you’re a Development Manager and you’re trying to help one of your staff.

This is one of several posts in regards to this subject.

I really don’t use MySQL too much.  At work, I have Oracle and Sybase.  But I think I’m going to use it in the example code that I post later.  Because we’ll be using Hibernate, for the most part, it really doesn’t matter.  Hibernate hides the nuances of each type of database from us (for the most part).  Anyway, the real reason has to do with the fact we’ll be installing PHP (which we’ve already done for the Apple Macintosh in an earlier post and we’ll be doing for Windows in a later post).  We’ll also need it for WordPress which we’ll also be addressing in a later post.

Here we’re going to install MySQL for Windows.  We’ve already installed it for the Apple Macintosh in an earlier post.

First off, we need the binary.  We’ll go to the MySQL website to download the 5.1 MySQL version file called “mysql-essential-5.1.41-win32.msi”.  After we’ve gotten the file downloaded double click it and we’ll see this window.

Note: You may have downloaded the 64 bit version of MySQL which is completely fine.

Open File - Security Warning MySQL AB

Open File - Security Warning MySQL AB

Click “Run” and you’ll see this window:

MySQL 5.1.41 Installer Welcome Screen

MySQL 5.1.41 Installer Welcome Screen

Click “Next >” and you’ll see this window:

MySQL Server 5.1 - Setup Wizard

MySQL Server 5.1 - Setup Wizard

Click on the “Custom” radio button and click “Next >”.  You will see this window:

MySQL 5.1.41 Installer Welcome Screen (Custom Setup)

MySQL 5.1.41 Installer Welcome Screen (Custom Setup)

There’s no reason not to leave the defaults so click “Next >” and you’ll see this window:

MySQL 5.1.41 Installer Welcome Screen (Custom Setup)

MySQL 5.1.41 Installer Welcome Screen (Custom Setup)

Click “Install” and you’ll see a window similar to the following:

MySQL 5.1.41 Installer (Installing)

MySQL 5.1.41 Installer (Installing)

Once the software has completed installing you’ll see the following window:

MySQL Enterprise Ad

MySQL Enterprise Ad

Click “Next >” here and you’ll see this window:

MySQL Enterprise Monitor Ad

MySQL Enterprise Monitor Ad

Click “Next >” again and now you’ll see this window:

MySQL Setup Wizard Finished

MySQL Setup Wizard Finished

I deselect the “Register the MySQL Server now” but you can leave it checked.  It’s up to you.  Now click “Finish” and you’ll see this window which is the configuration wizard:

MySQL Server Configuration Instance

MySQL Server Configuration Instance

Click “Next >” and you’ll see this window:

MySQL Instance Configuration Wizard (Type)

MySQL Instance Configuration Wizard (Type)

Leave “Detailed Configuration” checked and click “Next >” and you’ll see this window:

MySQL Instance Configuration Wizard (Detailed Configuration)

MySQL Instance Configuration Wizard (Detailed Configuration)

Leave “Developer Machine” checked and click “Next >” and you’ll see this window:

MySQL Instance Configuration Wizard (Multifunction Database)

MySQL Instance Configuration Wizard (Multifunction Database)

Leave “Multifunctional Database” checked and click “Next >” and you’ll see this window:

MySQL Instance Configuration Wizard (InnoDB Database)

MySQL Instance Configuration Wizard (InnoDB Database)

I’m leaving the defaults selected on my machine but you may want to put the database on a different disk if you have one.  Click “Next >” and you’ll see this window:

MySQL Instance Configuration Wizard (Connections)

MySQL Instance Configuration Wizard (Connections)

Leave the default of “Decision Support (DSS)/OLAP” selected as we won’t be making a lot of concurrent connections to our machine while we’re developing software.  Click “Next >” and you’ll see this window:

MySQL Instance Configuration Wizard (Network)

MySQL Instance Configuration Wizard (Network)

You’re probably behind a firewall on a corporate LAN so you should be OK to leave these defaults (the port specifically).  Click “Next >” and you’ll see this window:

MySQL Server Instance Configuration (Character Set)

MySQL Server Instance Configuration (Character Set)

We may do some multi-lingual development so let’s change this to “Best Support for Multilingualism” and the window will look like this:

MySQL Server Instance Configuration (Character Set)

MySQL Server Instance Configuration (Character Set)

Click “Next >” and you’ll see a window like this:

MySQL Server Instance Configuration (Windows Service)

MySQL Server Instance Configuration (Windows Service)

We want to keep “Install As Windows Service” checked so that MySQL will start up for us automatically.  And we’re also going to check “Include Bin Directory in Windows PATH”.  The window should look like this:

MySQL Server Instance Configuration (Windows Service)

MySQL Server Instance Configuration (Windows Service)

Click “Next >” and you should see this window:

MySQL Server Instance Configuration (Accounts)

MySQL Server Instance Configuration (Accounts)

Enter a “New root password:” and “Confirm:”.  We then click “Next >” and will see this window:

MySQL Server Instance Configuration (Ready to Execute)

MySQL Server Instance Configuration (Ready to Execute)

Click “Execute” and you’ll see a window similar to this:

MySQL Server Instance Configuration (Executing)

MySQL Server Instance Configuration (Executing)

When it’s finished, you should see this window:

MySQL Server Instance Configuration (Executing)

MySQL Server Instance Configuration (Finished Executing)

Click “Finish”.  Let’s reboot and the system should come up with MySQL started and everything in place.

When that’s done, let’s start up a command window by clicking on “Start” and then “Run” and typing “Cmd”.  You should see a window like this:

Windows Run Window

Windows Run Window

Click “OK” and you should see a window like this:

Windows CMD Window

Windows CMD Window

Type in the following

mysql -u root -p

and you should see a window like this:

mysql -u root -p

mysql -u root -p

Enter the password that you chose for your root password and you should see a screen like this:

Logged into MySQL

Logged into MySQL

And you’re done!  You’ve now got MySQL installed.

December 21, 2009 Posted by | Development Environment, MySQL | , | Leave a Comment

MAMP

We have now created a MAMP (Macintosh, Apache, MySQL, PHP) environment.  This posting is just to group those particular posts together:

Environment Consistency – PHP (Apple Macintosh)

Environment Consistency – MySQL (Apple Macintosh)

Environment Consistency – PHP/MySQL Configuration (Apple Macintosh)

Environment consistency – Verify PHP to MySQL Connectivity (Apple Macintosh)

December 13, 2009 Posted by | Development Environment, MySQL, PHP | , , , | Leave a Comment

Environment Consistency – Verify PHP to MySQL Connectivity (Apple Macintosh)

We need to make our life easier by creating consistency for every machine. What this means is every machine you try to use, whether it be yours or your colleagues, the environment will be the same when you sit down to help them with something. This is very important if you’re a Development Manager and you’re trying to help one of your staff.

This is one of several posts in regards to this subject.

This post will show how to do a verification that PHP is talking to our MySQL database for the Apple Macintosh.  We’ll go back and show how to do it for Windows in a later post.

So, to do a test, to make sure we’re talking to the database, we start up NetBeans and click on “File”, “New Project” which will give us this dialog box:

New Project PHP Application

New Project PHP Application

Now click on “PHP”, “PHP Application” and click “Next” which will give us a dialog box that looks like this:

New PHP Project

New PHP Project

We’re entering “PhpDbTest” for the “Project Name:” and need to make sure that our “Sources Folder:” is “PhpDbTest” as well.  Click “Next >” and you should see this dialog box:

New PHP Project (Project URL)

New PHP Project (Project URL)

As noted when we set up PHP, I run my applications out of my “/Users/thcampbell/Sites” directory so I click the “Copy files from Sources Folder to another location” and “Browse…” to that directory so that it shows up in the “Copy to Folder:” area of the dialog box.  I also change the “Project URL:” so that it reads “http://localhost/~thcampbell/PhpDbTest”. 

You’ll need to substitute your username where I’m using “thcampbell”

After making these changes the dialog box should look like this:

Project URL Modification

Project URL Modification

Click “Finish”

Now NetBeans is going to start up and automatically opens an “index.php” file for us and we’re going to add the following (highlighted) between “<?php” and “?>”

PHP Database Connectivity Code

PHP Database Connectivity Code

What’s going on here is that we are setting up a couple of variables for connecting to our database:

$dbhost = ‘localhost’;
$dbuser = ‘root’;
$dbpass = ‘xxxxxx’;

You would, of course, want to change the ‘xxxxxx’ to your database password from when we hooked up MySQL for our Apple machine.

The following line will do the actual connection to our database and if there is an error it will quit and throw an error message:

$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die (‘Error connecting to mysql’);

The following line does a select query of “Host” and “User” from the “mysql.user” table in our database:

$result = mysql_query(“SELECT Host,User from mysql.user”);

The “mysql.user” table is always there and holds the information of users that have access to our database as we saw when we hooked up our database in an earlier post.

These lines will display the data to our browser when we run the program:

while($row = mysql_fetch_array($result)) {
echo $row['Host'] . ” ” . $row['User'];
echo “<br />”;
}

and finally, let’s be a good boy or girl and close our database connection:

mysql_close($conn);

So, let’s run it from NetBeans by right clicking on our Project Name “PhpDbTest” and clicking on “Run”.  The default browser should start up and you should see a screen similar to the following:

PHP/MySQL Successful Test

PHP/MySQL Successful Test

If you see this screen then you’re done!  You connected to the database without any problem.

However, maybe you see this screen:

PHP/MySQL Unsuccessful Test

PHP/MySQL Unsuccessful Test

It’s probably your username or password for your database that is incorrect.  It is also possible you don’t have your PHP talking to MySQL properly but that’s fairly unlikely if you did the steps in this post.

If you can’t figure it out or something else went wrong post something in the comments section and maybe I or someone else can help.

I used information from the following sites for this posting

http://www.w3schools.com/PHP/php_mysql_select.asp

http://www.php-mysql-tutorial.com/wikis/mysql-tutorials/connect-to-mysql-database.aspx

December 13, 2009 Posted by | Development Environment, MySQL, PHP | , , , , | Leave a Comment

Environment Consistency – PHP/MySQL Configuration (Apple Macintosh)

We need to make our life easier by creating consistency for every machine. What this means is every machine you try to use, whether it be yours or your colleagues, the environment will be the same when you sit down to help them with something. This is very important if you’re a Development Manager and you’re trying to help one of your staff.

This is one of several posts in regards to this subject.

We’ve installed PHP and MySQL but we haven’t “connected” the two of them.  We’re going to do that today and it’s actually pretty easy to do.  All we have to do is tell PHP where the MySQL socket file is located.  The PHP we installed, thinks it is going to be at “/var/mysql/mysql.sock”.  However, on our Apple Macintosh it isn’t located there.  It’s located at “/tmp/mysql.sock”.  All we have to do is start up a “Terminal” session and edit our “php.ini” file using “sudo” like so:

sudo vi /etc/php.ini

sudo vi /etc/php.ini

and we then find the line that starts “mysql.default_socket” like so (it’s highlighted):

mysql.default_socket

mysql.default_socket (before)

and change it from “/var/mysql/mysql.sock” to “/tmp/mysql.sock” like so (again highlighted):

mysql.default_socket (after)

mysql.default_socket (after)

now we have another line that starts “pdo_mysql.default_socket” that we also need to change.  We’re changing it in the same way.  From “/var/mysql/mysql.sock” to “/tmp/mysql.sock”.  Here are two screen shots of the before and after:

pdo_mysql.default_socket (before)

pdo_mysql.default_socket (before)

pdo_mysql.default_socket (after)

pdo_mysql.default_socket (after)

save it and you’re done!

Reboot to make sure everything gets re-initialized.  This may be unnecessary but what’s it hurt?

Next week, I’ll show you how to verify that you’re talking to the database.

December 6, 2009 Posted by | Development Environment, MySQL, PHP | , , | Leave a Comment

Environment Consistency – MySQL (Apple Macintosh)

We need to make our life easier by creating consistency for every machine. What this means is every machine you try to use, whether it be yours or your colleagues, the environment will be the same when you sit down to help them with something. This is very important if you’re a Development Manager and you’re trying to help one of your staff.

This is one of several posts in regards to this subject.

I really don’t use MySQL too much.  At work, I have Oracle and Sybase.  But I think I’m going to use it in the example code that I post later.  Because we’ll be using Hibernate, for the most part, it really doesn’t matter.  Hibernate hides the nuances of each type of database from us (for the most part).  Anyway, the real reason has to do with our earlier PHP post and a post about WordPress that I’ll be making later.  ]

Here we’re going to install MySQL for the Macintosh.  We’ll go back and do it for Windows in a later post.

First off, we need the binary.  We’ll go to the MySQL website to download the 5.1 MySQL version file called “mysql-5.1.41-osx10.5-x86.dmg”.  After we’ve gotten that downloaded double click it and we’ll see this window after the image has been mounted:

Mounted MySQL Package

Mounted MySQL Package

Now click on the icon for “mysql-5.1.41-osx10.5-x86.pkg” and you should see this window:

MySQL 5.1.41 Installer Welcome Screen

MySQL 5.1.41 Installer Welcome Screen

click “Continue”

MySQL 5.1.41 Installer Important Information

MySQL 5.1.41 Installer Important Information

click “Continue”

MySQL 5.1.41 Installer Software License Agreement

MySQL 5.1.41 Installer Software License Agreement

click “Continue” and a window will drop down

MySQL 5.1.41 Installer Agree to Software

MySQL 5.1.41 Installer Agree to Software

click “Agree”

MySQL 5.1.41 Installer Select A Destination

MySQL 5.1.41 Installer Select A Destination

click “Continue”

MySQL 5.1.41 Installer Confirm Install Location

MySQL 5.1.41 Installer Confirm Install Location

click “Install”

MySQL 5.1.41 Installer Enter Password

MySQL 5.1.41 Installer Enter Password

you’ll need to type in your password so that you’ll have permission to install the software and after you’ve done that, the software should start to install

MySQL 5.1.41 Installer Installing

MySQL 5.1.41 Installer Installing

and when it’s done you’ll see this window:

MySQL 5.1.41 Installer Successful Install

MySQL 5.1.41 Installer Successful Install

Now you have the MySQL database installed.  But you don’t want to have to start it by hand every time your system boots.  You’d rather it start automatically for you.  We have an app for that. :)   Go back to this window

Mounted MySQL Package

Mounted MySQL Package

and this time click on “MySqlStartupItem.pkg” and you’ll see this window

MySQL 5.1.41 Startup Item Installer Welcome Screen

MySQL 5.1.41 Startup Item Installer Welcome Screen

click Continue

MySQL 5.1.41 Startup Item Installer Welcome Screen

MySQL 5.1.41 Startup Item Installer Welcome Screen

click Continue

MySQL 5.1.41 Startup Item Installer Select Destination

MySQL 5.1.41 Startup Item Installer Select Destination

click Continue

MySQL 5.1.41 Startup Item Installer Confirm Destination

MySQL 5.1.41 Startup Item Installer Confirm Destination

click Install

MySQL 5.1.41 Startup Item Installer Successful Install

MySQL 5.1.41 Startup Item Installer Successful Install

and you’re done.  Click Close.

We could go through the process of starting MySQL by hand but it’s just as easy to reboot our machine.  That way we’ll know it starts automatically for us as well.  So, reboot!

After you’ve rebooted, let’s start up a “Terminal” window.  Once that’s done, type in the following command:

ps -aef | grep mysql

and you should see results that look similar to this:

MySQL 5.1.41 Confirm Install

MySQL 5.1.41 Confirm Install

MySQL doesn’t have a Graphical User Interface so a lot of what we’ll be doing is via the command line.  Because of this, we need to put the /usr/local/mysql/bin in our PATH environment to make life easier for us.  We do this by cd-ing to the /etc directory and then editing the profile file using vi (via sudo).  We’ll be executing these commands:

cd /etc
sudo vi profile

and our window should look like this:

MySQL 5.1.41 Edit /etc/profile

MySQL 5.1.41 Edit /etc/profile

In this file, you should see a line that says PATH.  You want to put the line “/usr/local/mysql/bin:” right after the = sign of that line.  You should see a window that looks like this:

MySQL 5.1.41 Change PATH

MySQL 5.1.41 Change PATH

Save it and end your Terminal session and start a new one so that this will take effect for you.

Now that the MySQL server is started, we need to get in and do some things for security reasons.  The server starts with no password for the “root” user and it also has an anonymous account.  We need to fix those issues.  So we start up a “Terminal” window again and we’ll be executing the following command to get us into the MySQL interface:

mysql -u root

and the first thing we’re going to do is delete the anonymous users by running this command:

DELETE FROM mysql.user WHERE user=”;

your window will look like this:

MySQL 5.1.41 Delete Anonymous Users

MySQL 5.1.41 Delete Anonymous Users

And finally we need to get in and change the password for our root user.  Start up a “Terminal” window and get in MySQL by this command:

mysql -u root

then run the following command

UPDATE mysql.user SET password = PASSWORD=(‘xxxxxx’);

Be aware here though.  First off, you’re changing ALL the passwords of ALL the users in your database.  This is a fresh install so that’s OK but if for some reason you’re following this and it’s not a fresh install then be aware.  Secondly, I’m changing the password to ‘xxxxxx’, you’ll want to change it to something real.

How will we know that our password has been changed?  We now have to add the “-p” argument when we try to get into MySQL from now on else we can’t get in.  So we’ll be executing a command like this

mysql -u root -p

and the server will now ask you for the password when you try to get into your server.

The window for this will look like the following for these commands:

MySQL 5.1.41 Change root Password

MySQL 5.1.41 Change root Password

We now have MySQL installed on our Apple Macintosh.

November 22, 2009 Posted by | Development Environment, MySQL | , , | Leave a Comment

Environment Consistency – PHP (Apple Macintosh)

We need to make our life easier by creating consistency for every machine. What this means is every machine you try to use, whether it be yours or your colleagues, the environment will be the same when you sit down to help them with something. This is very important if you’re a Development Manager and you’re trying to help one of your staff.

This is one of several posts in regards to this subject.

Where I work, I’m asked to work on other technologies all the time.  My main focus is to work in JAVA/J2EE but sometimes I have to work in other programming languages.  PHP is one of those languages.

Today we’re going to set up our Apple Macintosh for working and debugging PHP in NetBeans.  I’ll show you how to set up PHP for Windows use in a later post.

In this file I’m going to refer to “<username>”.  This will be your username on your laptop similar to how mine is “thcampbell”

If you didn’t know it already, your Apple Macintosh already has an Apache HTTP web server on it.  You can get to it by going to “System Preferences” and then clicking on “Sharing”.  From there you’ll see something that says “Web Sharing” and it is probably off.

Web Sharing on Apple

Web Sharing on Apple

Click on the check box next to the Web Sharing line to turn it on:

Web Sharing on Apple

Web Sharing on Apple

After you’ve done that, click on the link that’s presented on this page or go to “http://localhost/~<username>” in your favorite browser.  You should see a screen like this:

Apache HTTP Web Server on Apple

Apache HTTP Web Server on Apple

Ok, we have the server running and believe it or not, PHP is also on your Apple Macintosh already.  We just have to enable it.  So start up a “Terminal” session and cd to the “/etc/apache2″ directory.  Then execute (via sudo) the vi command to edit the file “httpd.conf”:

Edit httpd.conf using sudo/vi

Edit httpd.conf using sudo/vi

After you’re editing the file, find the line that looks like the following:

#LoadModule php5_module libexec_apache2/libphp5.so

and uncomment it (remove the # sign).  When you’re done the file will look like the following:

Editing LoadModule line

Editing LoadModule line

Save it!

Now we need to restart our Apache HTTP web server.  Easy enough, go back to “System Preferences” and then “Sharing”, from there uncheck the check box for “Web Sharing” and then check it again.  This will stop and restart your server.

But how do we know PHP is running properly?

Go to your “Terminal” session and “cd ${HOME}/Sites”.  This will be the “Sites” directory under your username on the system.  In this directory create a file (using vi) called “phpinfo.php”.  In this file put the following line

<?php phpinfo(); ?>

Your file will look like this:

phpinfo.php

phpinfo.php

Save it.

Now go to your browser at “http://localhost/~<username>/phpinfo.php” and you should see a screen that looks like the following:

http://localhost/~<username>/phpinfo.php

http://localhost/~/phpinfo.php

The next thing we need to do is set up PHP so that we can debug our software easily.  We do this by using Xdebug.  Get the Xdebug source files from http://www.xdebug.org/download.php.  You want to get the latest source and download it to your machine.  After you’ve done that, go to a “Terminal” session and go to the directory where you downloaded the files.  (More than likely ${HOME}/Downloads)  Now run gunzip and tar on the file like so:

gunzip and tar xvf xdebug

gunzip and tar xvf xdebug

After you’ve done that, you need to cd into the directory where the sources are kept.  In the case of the file I downloaded they are in “xdebug-2.0.5″ and from here I’m going to run “sudo phpize” and “./configure –enable-Xdebug” like so:

phpize and configure of xdebug

phpize and configure of xdebug

and finally I’m going to run make:

make xdebug

make xdebug

Now we should have a file in the modules subdirectory called xdebug.so:

xdebug.so

xdebug.so

We need to copy this file to our extensions directory.  Where is that at?  We go back to our phpinfo program that we ran in the browser at “http://localhost/~<username>/phpinfo.php”.  The information displayed in the browser should have a section labeled Core which should have an entry for “extension_dir”.

Core and extension_dir in phpinfo.php

Core and extension_dir in phpinfo.php

We want to put the “xdebug.so” file in this directory.  We’ll do this using “sudo” like so:

Move xdebug.so into extension_dir

Move xdebug.so into extension_dir

We now need to edit our “php.ini” file.  But where is it?  Well PHP doesn’t have to have a php.ini file to run and on our Apple Macintosh there’s not one.  If you again, look at the phpinfo program that we ran in the browser at “http://localhost/~username/phpinfo.php” you’ll notice a line that says “Configuration File (php.ini) Path”.  Mine says “/etc” and if you look in “/etc” for “php.ini” the file is not there.  But there is a file called “php.ini.default”.  Just copy it (using “sudo”) and then we’ll edit it (using “sudo vi”) like so:

cp php.ini.default to php.ini

cp php.ini.default to php.ini

At the bottom of this file we want to put the following lines:

; Xdebug config for Mac OS X and NetBeans IDE
zend_extension=/usr/lib/php/extensions/no-debug-non-zts-20090626/xdebug.so
xdebug.remote_enable=on
xdebug.remote_handler=dbgp
; xdebug.remote_mode=req
xdebug.remote_host=localhost
xdebug.remote_port=9000
; xdebug.idekey=

and our file will look like this (the lines we added are highlighted):

php.ini file edited with xdebug information

php.ini file edited with xdebug information

Now, we need to stop and restart our server again.  Again, this is done by going to “System Preferences”, “Sharing” and unchecking and checking the box next to “Web Sharing”.

Now, how do we know if our debug mode is ready?  Again, we go to “http://localhost/~<username>/phpinfo.php” and in this file there should be a section title “XDebug” like so:

XDebug in phpinfo.php

XDebug in phpinfo.php

Ok, now we’ve got PHP running, in debug mode, but we want to be able to create and debug programs in NetBeans.  This is pretty simple to do as well, let’s do a test.

Click on File and New Project and the following dialog box should come up

New PHP Project

New PHP Project

Click Next and you may see the following dialog box as well:

Activating PHP

Activating PHP

I had some problems with this on the Apple Macintosh (it just stayed on this screen).  Give it a few minutes and then hit the “< Back” button.  Everything seemed to be OK for me when I did this.

So, now (if we had to, we clicked on File and New Project again) we should see the following dialog box where we will enter “TestPHPProject” in as the “Project Name” and “/NetBeansProjects/TestPHPProject” as the “Sources Folder:”

TestPHPProject

TestPHPProject

Now, click “Next >” and you’ll see this dialog box:

PHP Project Configuration

PHP Project Configuration

Change the Project URL to be “http://localhost/~<username>/TestPHPProject”

Click on the “Copy files from Sources Folder to another location” button and then click the “Browse” button.  You want to browse to “/Users/<username>/Sites”.  The resulting dialog box will look like the following:

TestPHPProject Edited Configuration

TestPHPProject Edited Configuration

After that’s done, NetBeans will open up the “index.php” file for your Project.  Put the following line

phpinfo();

in this file so that it looks like this:

index.php in NetBeans with phpinfo();

index.php in NetBeans with phpinfo();

Now, you’re ready to go.  In NetBeans, click on “Debug” and then “Debug Project (TestPHPProject)” and the program should start and it will stop at the first line like so:

NetBeans index.php file being debugged

NetBeans index.php file being debugged

You can now step through this file or any other PHP file you create.

I’d like to credit the following articles that I used for research in regards to creating this post:

Configuring PHP, Apache, MySQL, and Xdebug for PHP development in MAC OS X

Debugging PHP Source Code in the NetBeans IDE for PHP Editor

Using Apache and PHP on Mac OS X

Working with PHP 5 in Mac OS X 10.5 (Leopard)

Where is php.ini under MAC OSX

November 18, 2009 Posted by | Development Environment, PHP | , , , | Leave a Comment

Environment Consistency – Sync Directories

We need to make our life easier by creating consistency for every machine. What this means is every machine you try to use, whether it be yours or your colleagues, the environment will be the same when you sit down to help them with something. This is very important if you’re a Development Manager and you’re trying to help one of your staff.

This is one of several posts in regards to this subject.

OK, this week we’re going to sync up our directories.  There are two directories that we care about (actually 3 if you count the “NetBeansProjects” directory separately).

On our Windows machine, we’re already done.  We mapped in a previous post the “\\snake\developers$” directory to our Q: drive.   This is where our third party libraries will be stored on Windows.  We also have the “My Documents” directory that resides on our Windows file server and under that directory is the “NetBeansProjects” directory.  So we’re set on the Windows side of things.

On the Apple Macintosh though, it’s not that easy.  We need to use a utility called rsync to sync up our Libraries directory from the file server.  The way that we do that is to first set up a rsync directory for our rsync scripts.  We do this by starting up a terminal window which will start in the ${HOME} directory and execute the command “mkdir rsync” like so:

mkdir rsync

mkdir rsync

Now I’m going to create a script in that directory so I cd into it and using vi create a file called “syncLibrary.sh” like so:

vi syncLibrary.sh

vi syncLibrary.sh

We’re going to do a couple of things here.  The first thing we’re going to do is mount our Windows file server “snake”.  That is done using the mount command like so:

mount -t smbfs //thcampbell:<mypassword>@snake.mydomain.com:/Departments /nfs/Departments

This command will mount, using the smb protocol, the “Departments” directory on the Windows file server “snake.mydomain.com” using my username “thcampbell” and my password “<mypassword>”.  It will mount that at the “/nfs/Departments” mount point on my Apple Macintosh.  The “Departments” directory on snake.mydomain.com is a file shared created by my Windows Administrator.

Ok, after that’s done, I want to do my rsync.  Here’s my rsync command:

rsync -auv –delete /nfs/Departments/IT/Developers/ /NetBeansLibraries

This executes the rsync command with the options “-auv” and “-delete” while will sync the files from the directory “/nfs/Departments/IT/Developers” to the “/NetBeansLibraries” directory that we created in a previous post.

I’m not going to go into options “-auv” and “-delete” in detail but basically what’s going on is that the directory “/NetBeansLibraries” will be an exact duplicate of the “/nfs/Departments/IT/Developers” directory.  It will delete files and make changes to the “/NetBeansLibraries” directory each time you run it; so don’t make changes to the “/NetBeansLibrary” directory.  If a change needs to be made, make it in the “/nfs/Departments/IT/Developers” directory and then run your script “syncLibrary.sh”.

So after the rsync is done we have to umount our mount point by doing the following:

umount /nfs/Departments

Ok, so here’s what we have in our file:

syncLibrary.sh

syncLibrary.sh

Save it!  And set the permissions on it to be an executable using

chmod 755 syncLibrary.sh

and run it

./syncLibrary.sh

Execute syncLibrary.sh

Execute syncLibrary.sh

Depending on how many changes you have to your Libraries directory this could take a while to run.  I store other things in the “/NetBeansLibraries” directory such as Software that I need (like tomcat) and some Documentation, and you can do this too if you’d like.  My third party libraries are in a sub directory called Libraries and you’ll see me reference it when I talk about managing Libraries in a later post.

But we’re not done yet.  We have another couple of directories we want to sync.

We have to rsync the “${HOME}/NetBeansProjects” directory.  This directory is where we store our projects and we’ll want to rsync it to the Windows file server so that a) we have access to it from our Windows machine and b) even though we’ll be using Subversion, it never hurts to have a backup of our projects.

We do pretty much the same thing as we did above.  We are going to edit a file using vi called “syncNetBeans.sh”.

In this file, we first mount “snake” but this time we’re mounting the “Home” directory instead of the “Departments” directory.  We’ll be mounting this directory at “/nfs/Home” on our Apple Macintosh.  Again, the “Home” directory on snake, is a share that our Windows Administrator set up for us:

mount -t smbfs //thcampbell:<mypassword>@snake.mydomain.com:/Home /nfs/Home

Next we’re going to rsync our “${HOME}/NetBeansProjects” directory to “/nfs/Home/My Documents/”.  This directory “/nfs/Home/My Documents” will correspond to the “My Documents” directory on our Windows machine so that when we use that machine, we’ll have access to our files without any effort.

rsync -auv –delete /Users/thcampbell/NetBeansProjects /nfs/home/thcampbell/My\ Documents

And just like before, we’re going to umount snake:

umount /nfs/Home

This is our finished file.

syncNetBeans.sh

syncNetBeans.sh

It’s important to note that we’re syncing to snake in this script instead of from snake like we did in the previous script.

Just like before, save it, chmod it and execute it.

Execute syncNetBeans.sh

Execute syncNetBeans.sh

Finally I have one more directory that I want to sync.  As I’m using my Apple Macintosh as my master computer, I want to edit my files in my “${HOME}/Documents” directory but have them show up in my “My Documents” directory on my Windows machine.  So, we edit a file called “syncHome.sh” using vi.

Just like in the previous script, we mount “/Home” on snake to our “/nfs/Home”:

mount -t smbfs //thcampbell:<mypassword>@snake.mydomain.com:/Home /nfs/Home

Our rsync command is a little different this time though:

rsync -auv –delete –exclude=NetBeansProjects /Users/thcampbell/Documents/ /nfs/home/thcampbell

This time you’ll notice a –exclude=NetBeansProjects.  What this tells rsync is that it should not do anything with the “NetBeansProjects” directory.  We manage this directory using the script up above so we don’t want to mess with it here.

Then, just like before we umount snake:

umount /nfs/Home

Here’s what our finished script looks like

syncHome.sh

syncHome.sh

Save it, chmod it and run it!

Execute syncHome.sh

Execute syncHome.sh

Now that you have your scripts created, you can run them by hand or you could run them using a cron job.  It’s up to you but I’ll leave figuring out how to set up cron to you.

November 9, 2009 Posted by | Development Environment | , , , , | Leave a Comment

Environment Consistency – Directories (Windows)

We need to make our life easier by creating consistency for every machine. What this means is every machine you try to use, whether it be yours or your colleagues, the environment will be the same when you sit down to help them with something. This is very important if you’re a Development Manager and you’re trying to help one of your staff.

This is one of several posts in regards to this subject.

As I mentioned, I support both a Windows environment and an Apple Mac environment and we have a different way of handling our “directories” for each environment.  We’re going to talk about Windows here.

There are two “directories” that are important when developing our software.  There is the “NetBeansProjects” directory and the “NetBeansLibraries” directory.

When NetBeans installs for Windows, it creates a directory called “NetBeansProjects” in your “My Documents” directory.  Now to keep things consistent we need to do something extra on each machine.

Windows has an old DOS command called SUBST which “Associates a path with a drive letter.”  Using this command we can fix it so that where ever our NetBeansProjects directory is created we can consistently associate it with the driver letter X:.  This is done by executing the following command at the command line:

SUBST X: “H:\My Documents\NetBeansProjects”

TheSUBST Command

The SUBST Command

You’ll notice that my “My Documents” directory is located on the H: drive.  Fortunately for me, this directory is located on the main file server at my work place and is synchronized each time I log on to the network.  This means when I disconnect from the network, I can still work on my projects and then when I connect, everything will be backed up to the file server (which then goes to tape).  I don’t want to go into further detail about this here, talk to your System Administrator about setting this up for you.

If you can’t get them to create this for you, then you’ll be putting your files (probably) on your C drive somewhere.  I’ll show you in a later post how to set up Subversion to manage your source code but even then, you could have a hard drive failure and lose a couple of days of work.  Having your files synced to the file server is the best way to go.

Now, everyone that uses Windows, when they are using NetBeans, should create projects in X:\NetBeansProjects, NOT in H:\My Documents\NetBeansProjects.  Sounds stupid but it helps, trust me.

Now typing in the SUBST command each time you reboot your machine isn’t exactly my idea of fun.  So create a batch file for it (put that line in a file and save the file at c:\substx.bat) and then create a “Windows Shortcut” to c:\substx.bat in your Startup folder.  That way it’ll run each time you reboot.

The NetBeansLibraries directory is going to be associated with our Q: drive.  Our Windows Administrator helped us out again here by creating a special share for us called developers$.  Our file server is called “snake” so our special share is located at \\snake\developers$.  We map this drive using Windows Explorer.  So start Windows Explorer and click on Tools and then click on Map Network Drive.  A Window will come up and the information in it should look similar to the following:

Windows - Map Network Q Drive

Windows - Map Network Q Drive

After you’ve done this, you need to make sure it’s going to synchronize and be available offline.  Again in Windows Explorer, right click on the Q drive and there should be an option for “Make Available Offline”.  Make sure it’s checked like so:

Windows - Make Available Offline

Windows - Make Available Offline

If you don’t see this option go talk to your Windows Network Administrator so, he can “hook you up”.  We’ll talk about managing the Libraries in a later posts.

November 1, 2009 Posted by | Development Environment | , , | Leave a Comment

Follow

Get every new post delivered to your Inbox.