You are now on my Technical Blog. My other sites: Personal Blog - Genealogy Blog - Genealogy Site

DLMax Max Westen's ramblings on OSX and PHP

Blog Category: osx


Developing in PHP with NetBeans 6.8

Nov 25, 2009

The problem:

I love Textmate as an editor period.

There are some things though that I started missing while developing:

  • Code completion
  • Inline documentation
  • instant error checking
  • debugging from my editor
  • must have strong syntax highlighting support for dark themes like my favourite Sunburst

So I started looking around for an IDE(or Editor) that would work for me and that I could adhere to.

The contestants:

VIM:

I’ve heard a lot on VIM and really like the application. When you add a couple of plugins like Project, PHP-Doc, DelimitMate, SnipMate and Sunburst you can accomplish most of these tasks. An added feature is that you can configure VIM to work the same on your remote systems too, so it virtually doesn’t matter if you’re on Mac, Windows or Linux or working trough an SSH connection; your editor functions and looks the same. Most features from my list can be accomplished in VIM, but I can’t get used to the shortcuts. There are a lot of them and all of them are new compared to windows/mac users. If you’re in a full-time development job I think it’s very difficult to learn the new way of working and still deliver on time. So for me VIM isn’t something that can be used out of the box.

Eclipse PDT:

Eclipse with PDT 2.1 is another IDE I hear a lot of good comments on. All of the things I want to see in an alternative editor/IDE is there, except for the strong Syntax highlighting and easy themeing. Colours can be changed, but have to be changed on a lot of different locations, making it hard to do consistently. The PDT plugin has some nice features, but the syntax highlighting could be much better. Eclipse with PDT isn’t my thing because of the lack of syntax highlighting features, the difficult themeing (especially to darker themes) and the high memory consumption.

Aptana

Aptana Studio 2.0 is a good IDE (I’ve used it before) with a very nice PHP plugin, but changed to use the PDT eclipse plugin. There is a way to use the older PHP plugin, but because development on that plugin has ceased, I don’t recommend it. The PDT plugin with Aptana has lacks the same points as discussed above under "Eclipse PDT".

Zend Studio:

Zend Studio 7.1 basically is Eclipse with the PDT plugin and some added features; specifically focussed on "Zend Framework", "Zend Server" and "Zend Debugger". Zend Studio isn’t a fit for me, because the problems I have with the Eclipse PDT plugin are the features taken from this plugin. If these points would improve it would be a good choice for me. The price could be a turnoff though if a free IDE is available that can do most you need.

Komodo IDE:

Komodo IDE 5.2 is a stable IDE and has a smaller memory footprint then the eclipse based tools. It has support for a multitude of languages, VCS(=Version Control Systems). The support for PHP and debugging are good and this is one of the few IDEs that are quite easy to style in a dark background. There are only 2 downsides for me; the price and the syntax highlighting could be even better. The price isn’t that high for a business, but I found an alternative that fits me better.

NetBeans:

Netbeans 6.8 (currently in beta) is like Komodo a stable IDE with smaller memory footprint. It fits my wish-list and I can adapt quite easily to the shortcuts and natural for me. It’s a full featured IDE with all the bells and whistles. Room for improvement would be: More VCS plugins (Git), support for the Zend Debugger, scriptable (regexp) like syntax highlighting support, to be able to add custom highlighting.

NetBeans Tips:

Font rendering in NetBeans on OSX:

I love the anti-aliasing done by TextMate to my coding fonts. If you want to achieve the same effect in NetBeans, you need to add 2 parameters to the application startup-file.

  1. Open the finder and go to the NetBean.app file.
  2. Press the right mouse-button (or ctrl+click) and select the option "Show Package Contents".
  3. In the new opened finder window, go to the following location: "Contents/Resources/NetBeans/etc/"
  4. Edit the file: "netbeans.conf"
  5. add the following to the end of the line starting with: "netbeans_default_options=" -J-Dsun.java2d.noddraw=true -J-Dapple.awt.graphics.UseQuartz=true
  6. save the file and start NetBeans.

The font will be like you used to see in TextMate.

Preventing Java crashes on OSX 10.6:

Update: I’ve updated to the final 6.8 release now and it runs fine on Java 6, so this workaround is probably not needed….

If you are working on OSX Snow Leopard (10.6) and NetBeans crashes randomly, it’s worth a try to downgrade your Java from 6 to 5. This probably greatly improves stability for NetBeans and other Java applications running on OSX. To downgrade, I followed the steps outlined on the oneswarm wiki and put them up here too.

Get the java 5 that was included in 10.5 "leopard" and unpack

cd /tmp/
curl -o java.1.5.0-leopard.tar.gz http://www.cs.washington.edu/homes/isdal/snow_leopard_workaround/java.1.5.0-leopard.tar.gz
tar -xvzf java.1.5.0-leopard.tar.gz

Move it to your System java folder (password needed)

sudo mv 1.5.0 /System/Library/Frameworks/JavaVM.framework/Versions/1.5.0-leopard

Tell OS X that java 5 actually is java 5

cd /System/Library/Frameworks/JavaVM.framework/Versions/
sudo rm 1.5.0
sudo ln -s 1.5.0-leopard 1.5.0
sudo rm 1.5
sudo ln -s 1.5.0 1.5

Open Java Preferences

open "/Applications/Utilities/Java Preferences.app"

Change the properties to use Java 5 32-bit by default:

Start NetBeans and you’re done !

Themed Tab Terminal for OSX Leopard

Dec 28, 2008

If you’re working a lot with remote sessions like I do, you inevitably type a command in the wrong window… Most of the time it’s something harmless like an ls or an cd command, but if you’re trying to clean stuff up with an rm command things can get bad.

The easiest way to differentiate between local and remote sessions or different remote sessions is changing the background-color. When switching terminal, you immediately see/know where you are, without looking at the prompt or the window-title. So how do we implement this in the standard OSX Leopard Terminal.app ?

I like the terminal in OSX Leopard a lot but it doesn’t have support for some simple things like opening themed tabs or use the bookmark function like in iTerm. Because I prefer Terminal over iTerm, I tried hacking some scripts together

First I pick a theme I’d like to use on a daily basis from the Preferences - Settings window. In my case it’s "IR Black". Then I select the theme and duplicate it by pressing the small "cog" icon and selecting "Duplicate Settings". Duplicate the theme Rename the duplicated theme to something useful; I’m using one to connect to a server named "Pentagon", so I name it this way. Note that the duplicated theme automatically gets the Default theme being used when pressing ⌘T. You can select another theme and then click the "Default" button to set the original "IR Black" as default again. Set the default theme

Select the newly created "Pentagon" theme, go to the "window" tab and press the "Background Color" selector. Pick a color of your liking here. Because I like a darker background, I choose a very subtle tint of red in my black; just enough to notice it when in the terminal. Change the backgroundcolor Select the color

Right now we can manually open a new terminal window by going into the "Shell" "New Tab" menu and select the "Pentagon" theme there. If you like you can tweak the background color with the theme selected to see the changes immediately applied to your terminal screen.

Right now you have a different background-color, so you can start an ssh connection with the pentagon server, but I don’t like to use the mouse first and then start the ssh session manually. Create a tab with the new theme While looking around I came across a modification of Marc Liyanage’s "open terminal here" plugin, by Geoff using an applescript by Jacob Rus to open the menus and submenus from OSX apps programmatically.

I’ve mixed-and-matched the scripts and the ttterm (Themed Tab Terminal) script is the result. For the script to work, you need to enable "Access for assistive devices" on the "Universal Access" screen in "System Preferences". Access Assistive Devices If this script is placed in your path, it can be called in two ways:

1) Opens a new tab with the selected [themename]

ttterm [themename]

2) Opens a new tab with the selected [themename] and runs the [command] in the new terminal.

ttterm [themename] [command]

So if I want an ssh connection with pentagon, I can call:

ttterm Pentagon ssh max@pentagon

This is still quite long, so I add an alias to my .bashrc file and off we go.

CakePHP: Calling bake from every dev-app install folder

May 08, 2007

If you use a setup like I explained in my previous post calling the bake script involves a lot of typing with the core and app parameter paths.

If I want to call the bake script from the /Users/mwesten/Sites/dev/myapp cake app folder, it has to be done like this:

php /Users/mwesten/Sites/cake1.2.x.x/cake/scripts/bake.php -core /Users/mwesten/Sites/cake1.2.x.x/cake  -app /Users/mwesten/Sites/dev/myapp

To make things easier on myself I use the following alias and shell script. First I edit /etc/profile (or ~/.bash_profile)

sudo mate -w /etc/profile

and add the following line:

alias bake="/Users/mwesten/cake12bake.sh"

After this I create the shell script:

mate /Users/mwesten/cake12bake.sh

add the following 2 lines:

#!/bin/sh
php /Users/mwesten/Sites/cake1.2.x.x/cake/scripts/bake.php -core /Users/mwesten/Sites/cake1.2.x.x/cake -app $PWD

Now you can execute the bake script from the app folders.

UPDATE: If you are using the latest version (bleeding edge dev install of CakePHP 1.2) you can do the following instead: edit /etc/profile or ~/.bash_profile and add the following folder to the path statement: /Users/mwesten/Sites/cake1.2.x.x/cake/console

After this you can call the bake script like this:

cake bake

or just "cake" for all possible options….

Hmmm….. For some reason it now still calls the wrong app folder, but I think it will be fixed in no-time ;)

CakePHP: Central cake core install with multiple apps

May 08, 2007

When developing on my system I like to use only one version of the core files. If I update the core files from svn it gets updated for all apps I’m working on.

The way I’m using this is explained below:

In my web-root I do an svn export of cake latest:

cd /Users/mwesten/Sites
svn export https://svn.cakephp.org/repo/branches/1.2.x.x/ cake1.2.x.x

Now we have the latest core files on our system.

If I like to create an app I’ll do the following:

cp -R /Users/mwesten/Sites/cake1.2.x.x/app /Users/mwesten/Sites/dev/myapp

Then I change the following file to point to the correct core files:

mate /Users/mwesten/Sites/dev/myapp/webroot/index.php

Then add the line

define('CAKE_CORE_INCLUDE_PATH', '/Users/mwesten/Sites/cake1.2.x.x');

before the part saying:

/**
 * Do not change
 */

If you go to the page http://localhost/dev/myapp/ it then shows the cakephp welcome page.

CakePHP on OSX: Problem using Bake.php script

May 08, 2007

If you are getting the following errors while trying to bake something on osx 10.4:

"Warning: mysql_connect(): Can't connect to local MySQL server through
socket '/var/mysql/mysql.sock' (2) in /Library/WebServer/Documents/development/bakery/cake/libs/model/dbo/dbo_mysql.php
on line 117" 

try doing the following:

sudo ln -s /tmp /var/mysql

Or you could follow the instruction given by Apple: Mac OS X Server 10.4: Issues connecting PHP to MySQL

Newer