Development Tools-Running Through Apache
If you are accessing your application with URLs that look like http://localhost:45437/cgi-bin/WebObjects/AppName.woa/ (with the xxx:portnum instead of xxxx/-portnum) ... then you are using the Evil Direct Connect. See that page for why you don't want to be using Direct Connect. See this page for how to stop.
Turning on Apache
Go to System Preferences > Sharing > Services and turn on Personal Web Sharing if it is not already on.
When you turn on your web server, Apache will listen on the network interfaces that were configured when it starts. If you change networks, you may need to manually restart apache. You can do this by either stopping and restarting Personal Web Sharing, or you can run "apachectl restart" from the commandline as the root user. Because this can get annoying if you are working on a laptop, or periodically using VPN's, there are a couple ways to make this process easier.
Restarting Apache Fix #1: Explicitly Setting Your Hostname
Edit Apache Config
Edit /etc/httpd/httpd.conf, find the line containing ServerName and change it to this:
ServerName localhost
That line may be commented out by default. You can simply uncomment it (remove the leading pound sign) and then restart apache:
sudo apachectl restart
Tell wotaskd to Use Localhost Too
Edit /System/Library/WebObjects/JavaApplications/wotaskd.woa/Contents/Resources/Properties
Add this line after the WOPort=1085 one:
WOHost=localhost
Now you need to restart wotaskd:
sudo systemstarter stop "WebObjects Services"
sudo systemstarter start "WebObjects Services"
or
restart wotaskd and womonitor with launchctl if your WebObjects install launches that way.
Finally, Configure your Application
Add or edit these launch parameters:
-WODirectConnectEnabled false
-WOHost localhost
-WOAdaptorURL http://localhost/cgi-bin/WebObjects
-WOPort 5555
The WOPort is optional, but useful if you want consistent URLs for bookmarks and such. You can use any number you want, but it needs to be unique for each application you launch (or rather, you can only run one app instance on a given WOPort at a time). In WOLips, WOPort, WODirectConnectEnabled, and WOAdaptorURL already exist and just need to be updated. WOHost does not, and needs to be added. The dash in front of the name ("-WOHost") is important and must be in the name for the setting to work properly.
You may want to set this in your global WOLips settings so you don't have to set it every time you make a new launch configuration. You will need to go back and modify existing launch configurations with these settings even if you set it globally. Global settings only apply to newly created launch configurations.
Restarting Apache Fix #2: Kickstart
The alternative way to restart apache is to have a script run any time your network changes. It turns out that OS X supports such a capability already via Kickstart.
Making a restart script
Create a script named /usr/local/bin/restartApache and set the contents to:
#!/bin/bash
/usr/sbin/apachectl stop
sleep 1
/usr/sbin/apachectl start
Modifying Kicker
- Edit /System/Library/SystemConfiguration/Kicker.bundle/Contents/Resources/Kicker.xml
- At the end of the <array> section, add the following block of XML:
<dict>
<key>execCommand</key>
<string>/usr/local/bin/restartApache</string>
<key>execUID</key>
<integer>0</integer>
<key>keys</key>
<array>
<string>State:/Network/Global/DNS</string>
<string>State:/Network/Global/IPv4</string>
<string>State:/Network/Global/IPv6</string>
<string>State:/Network/Global/NetInfo</string>
</array>
<key>name</key>
<string>restart_apache</string>
</dict>
Restart
Restart your machine (you may be able to get away with just logging out and back in). Any network changes will now automatically restart Apache.
Extra Credit
I also like to have a growl notification fire when my Apache restarts. To do this:
- grab the growl shell script from http://www.macosxhints.com/dlfiles/growl_sh.txt.
- next, at the end of your /usr/local/bin/restartApache script, you can add:
export G_APPLICATION_ICON=EOModeler.app
export G_TITLE=WebObjects
/usr/local/bin/growl "Apache Restarted"