Home Blog Tags OS X
Tags >> OS X
Jul 21
2010

Couple of useful OS X Tricks

Posted by: Marko Tomic

Tagged in: OS X , HOWTO

I just stumbled upon 30 Fantastic Geeky Tricks To Get The Most From Your Mac and I thought I'd write down a couple of tricks I found useful.

Recent Items Stack

Type this in terminal window to show a stack of your 'recent applications'.

defaults write com.apple.dock persistent-others -array-add '{ "tile-data" = { "list-type" = 1; }; "tile-type" = "recents-tile"; }'

Show Hidden Files

The following command will show all hidden files in your Finder.

defaults write com.apple.Finder AppleShowAllFiles YES

Similarly, change the last bit to 'NO' to re-hide the files.

Enable Safari Inspector

I didn't know that Safari had an Inspector that looks like the one in Google Chrome. As a web developer, I can say that this is music to my ears. Enable it in Terminal:

defaults write com.apple.Safari IncludeDebugMenu 1

Better Screen Sharing

When I first saw Screen Sharing on a Mac, I thought it was the best thing since sliced bread. Apparently, there are more nifty Screen Sharing features that are hidden by default.  This includes a number of options for adjusting quality and allowed input on each side of the screen share. To turn them on, type this in your Terminal:

defaults write com.apple.ScreenSharing \
'NSToolbar Configuration ControlToolbar' -dict-add 'TB Item Identifiers' \
'(Scale,Control,Share,Curtain,Capture,FullScreen,GetClipboard,SendClipboard,Quality)'

May 20
2010

Startup Script for Apache Tomcat on Snow Leopard HOWTO

Posted by: Marko Tomic

Tagged in: Tomcat , Railo , OS X , HOWTO , Apache

I have just set up Apache Tomcat startup script on Snow Leopard and I thought I'd blog about it while it's still fresh in my head.  Assuming you have installed Tomcat in /usr/local/tomcat directory, you can do the following to start Tomcat on system startup.

1. Create your startup script:

sudo nano /usr/local/tomcat/bin/tomcat

#!/bin/sh # Tomcat Startup Script
 
CATALINA_HOME=/usr/local/tomcat; export CATALINA_HOME
JAVA_HOME=/Library/Java/Home; export JAVA_HOME
TOMCAT_OWNER=root; export TOMCAT_OWNER
 
start() {
        echo -n "Starting Tomcat:  "
        su $TOMCAT_OWNER -c $CATALINA_HOME/bin/startup.sh
        sleep 2
}
stop() {
        echo -n "Stopping Tomcat: "
        su $TOMCAT_OWNER -c $CATALINA_HOME/bin/shutdown.sh
}
 
# See how we were called.
case "$1" in
  start)
        start
        ;;
  stop)
        stop
        ;;
  restart)
        stop
        start
        ;;
  *)
        echo $"Usage: tomcat {start|stop|restart}"
        exit
esac

Set your TOMCAT_OWNER correctly.  You should run it as a valid system user.


2. Create a symbolic link in /usr/bin for easier access

sudo ln -s /usr/local/tomcat/bin/tomcat /usr/bin/tomcat


3. Create the startup daemon which will start Tomcat when the system boots up

sudo mkdir /Library/StartupItems/tomcat
sudo nano /Library/StartupItems/tomcat/tomcat

#!/bin/sh
. /etc/rc.common
 
# The start subroutine
StartService() {
    # Insert your start command below.  
    tomcat start
}
 
# The stop subroutine
StopService() {
    # Insert your stop command(s) below.
    tomcat stop
}
 
# The restart subroutine
RestartService() {
    # Insert your start command below.
    tomcat restart
}
 
RunService "$1"


4. Create your startup parameters plist file

sudo nano /Library/StartupItems/tomcat/StartupParameters.plist

<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist SYSTEM "file://localhost/System/Library/DTDs/PropertyList.dtd">
<plist version="0.9">
    <dict>
        <key>Description</key>
        <string>Tomcat web server</string>
        <key>OrderPreference</key>
        <string>Late</string>
        <key>Provides</key>
        <array>
                <string>Local Web Services</string>
        </array>
        <key>Uses</key>
        <array>
                <string>SystemLog</string>
        </array>
    </dict>
</plist>

Restart your Mac and you should be sweet.

For more info on how to install Tomcat, e.g. Railo on Tomcat via Apache see my blog post on Learnosity Website. Also, have a look at Mark's version using Apache mod proxy 
 
Marko

May 19
2010

MySQL startup script on Mac OS X Snow Leopard

Posted by: Marko Tomic

Tagged in: OS X , MySQL , HOWTO

I've had problems starting up MySQL database server on startup on Snow Leopard.  MySQL preference pane seems to be flaky and it often fails to start MySQL server.

I created this startup script myself and it seems to work nicely.

sudo nano /System/Library/LaunchDaemons/org.mysql.mysqld.plist

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>RunAtLoad</key>
<true/>
<key>Umask</key>
<integer>7</integer>
<key>UserName</key>
<string>_mysql</string>
<key>Disabled</key>
<false/>
<key>WorkingDirectory</key>
<string>/usr/local/mysql</string>
<key>GroupName</key>
<string>_mysql</string>
<key>KeepAlive</key>
<true/>
<key>Program</key>
<string>/usr/local/mysql/bin/mysqld</string>
<key>Label</key>
<string>org.mysql.mysqld</string>
<key>ProgramArguments</key>
<array>
<string>--user=_mysql</string>
</array>
</dict>
</plist>

Now make sure file permission is correct and load the daemon.

sudo chown root:wheel /System/Library/LaunchDaemons/org.mysql.mysqld.plist
sudo launchctl load /System/Library/LaunchDaemons/org.mysql.mysqld.plist
sudo launchctl start org.mysql.mysqld

Restart your Mac and your MySQL server should be running.

Marko

Nov 04
2009

SSH Tunneling - Add secondary address to your loopback interface HOWTO

Posted by: Marko Tomic

Tagged in: SSH , Shell , OS X

I'm writing this one for my own reference because almost everything I do for work, is done through SSH port forwarding. If you're not familiar with SSH port forwarding, you'll have to read up on it elsewhere. And the reason why we use SSH port forwarding is because it is secure and powerful.

I generally set up my port forwards to run on my local computer on an arbitrary port and configure SSH to create a proxy connection to the normal port on a remote computer. Then I configure my application to connect to my local computer on the chosen arbitrary port.

For example, I would create my virtual hosts in /etc/hosts:

sudo nano /etc/hosts

127.0.0.1 local1A.fwd
127.0.0.1 local1B.fwd
127.0.0.1 local1C.fwd

let's say I want to forward my local requests on ports 6800, 6801, 6802 to remote servers on ports 3012, 3013, 3014. Start by modifying your ssh config:

nano .ssh/config

add the following:

host remote1A
hostname 111.111.111.111 #remote IP address goes here
user my_username #server username goes here
localforward local1A.fwd:6800 111.111.111.111:3012

host remote1B
hostname 111.111.111.111 #remote IP address goes here
user my_username #server username goes here
localforward local1B.fwd:6801 111.111.111.111:3013

host remote1C
hostname 111.111.111.111 #remote IP address goes here
user my_username #server username goes here
localforward local1C.fwd:6802 111.111.111.111:3014

You should now be able to ssh to remote machines:

ssh remote1A

and similarly for 1B and 1C.

Now, lets say you want to create another 3 local hosts and simultaneously port forward to another 3 remote machines via exact same port numbers. This is where you'll run into problems, because you can only use one local port at a time on 127.0.0.1. The workaround it is to create secondary addresses to your loopback interface 127.0.0.2, 127.0.0.3 and so on. The command to add the secondary IP address is:

ifconfig lo0 alias 127.0.0.2/32

Now you can add new set of hosts:

127.0.0.2 local2A.fwd
127.0.0.2 local2B.fwd
127.0.0.2 local2C.fwd

And use the same set of port numbers to tunnel through another set of remote servers:

host remote2A
hostname 222.222.222.222 #remote IP address goes here
user my_username #server username goes here
localforward local1A.fwd:6800 222.222.222.222:3012

host remote2B
hostname 222.222.222.222 #remote IP address goes here
user my_username #server username goes here
localforward local1B.fwd:6801 222.222.222.222:3013

host remote2C
hostname 222.222.222.222 #remote IP address goes here
user my_username #server username goes here
localforward local1C.fwd:6802 222.222.222.222:3014

Marko

Nov 02
2009

MAMP vs Entropy PHP on OS X

Posted by: Marko Tomic

Tagged in: PHP , OS X , MySQL , Apache

Following my post on Snow Leopard Gotchas, I discovered another problem you might run into. SL comes with currently the latest version of PHP 5.3.0. However, not all PHP projects will play nice on v5.3.0. What you could do is:

1. build and configure an older version of PHP from source - e.g. 5.2.11
2. Install Entropy PHP (note: this will modify your SL Apache config files).
3. Or just be lazy and install MAMP (Macintosh, Apache, MySQL, PHP) in a few seconds.

I chose the last option for 5 reasons:
1. I'm lazy
2. Comes with PHP 4.4.9 & 5.2.10
3. It installs a complete package in one directory
4. It doesn't mess with my existing apache config files
5. it's easy to uninstall.

This is particularly useful for content editors who have phobia of terminal windows (I don't blame them). Hopefully some developers will find this useful too.

After you've downloaded and installed MAMP, you'll notice that the installer created /Applications/MAMP directory. Launch your MAMP Control Center, start your services and away you go.

By default, your Apache web server will run on port 8888. You can change this to port 80 in Preferences, but if you do that you will have to make sure that your OS X Web Sharing is stopped. You can stop it in System Preferences=>Sharing=>Web Sharing.

Normally your Apache virtual would be here:

/etc/apache2/users/*.conf or /etc/apache2/extra/httpd-vhosts.conf

MAMP keeps virtual hosts separately in:

/Applications/MAMP/Library/vhosts

If you ever want to uninstall MAMP, all you need to do is Trash /Applications/MAMP directory and you're done. It's simple and clean.

For more info see MAMP documentation.

Problems you may have with Entropy PHP

NOTE: always backup any .conf file you are going to modify or remove.

Entropy PHP will add a new config file in /etc/apache2/other and possibly modify your httpd.conf. If you're having problems running PHP, there could be various symptoms. The one I was seeing in apache error logs was this one:

child pid 7563 exit signal Segmentation fault (11)

I'm not sure what this means exactly, but it happens when your Entropy config file:

/etc/apache2/other/+entropy-php.conf

tries to load the problematic php module:

LoadModule php5_module /usr/local/php5/libphp5.so

To solve this, I would recommend removing all Entropy stuff and go back to your native PHP 5.3.0. You could try removing, or backing up +entropy-php.conf and uncomment the following line in your httpd.conf

LoadModule php5_module libexec/apache2/libphp5.so

Also check that this file exists:

/etc/apache2/other/php5.conf

and that it contains

<IfModule php5_module>
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps

DirectoryIndex index.html index.php
</IfModule>

 

Oct 25
2009

Snow Leopard Gotchas

Posted by: Marko Tomic

Tagged in: OS X , MySQL , Apache

I recently upgraded to Snow Leopard from 10.5 and everything went relatively smoothly. I was particularly pleased to see extra 13GB of hard drive space.

However, I noticed a couple of things that I wasn't so pleased about:

  1. Apache unable to start
  2. PHP disabled
  3. MySQL unable to start

I've already walked a couple of people through this, so if you run into the same problem you can try the following:

1. For some reason Snow Leopard modified the following file:

/etc/apache2/extra/httpd-ssl.conf

I was using a self-signed SSL certificate for one of my local sites, which was stored in my custom "SSL" directory. The path to my SSL cert was specified in httpd-ssl.conf, but after upgrading to Snow Leopard, that path was replaced with the default path:

SSLCertificateFile "/private/etc/apache2/server.crt"
SSLCertificateKeyFile "/private/etc/apache2/server.key"

The default .crt and .key files didn't exist on my system, hence Apache failed to start. The error I got was:

Syntax error on line 99 of /private/etc/apache2/extra/httpd-ssl.conf SSLCertificateFile: file '/private/etc/apache2/server.crt' does not exist or is empty

You actually have to type 'httpd' in your terminal window to see those errors.

2. PHP disabled.  This problem is closely related to the previous one and it is very simple to fix.  In your httpd.conf file uncomment the following line:

LoadModule php5_module libexec/apache2/libphp5.so


For some reason Snow Leopard upgrade commented this line out for me.

3. MySQL unable to start.  This one scared me a little bit as I do all of my development work on my local machine running against a local MySQL database.   I typically start my MySQL server in terminal:

sudo mysqld -u root


To my surprise, I go this:

mysqld: command not found


The problem was that the following symbolic link was deleted: {/xtypo_code}/usr/local/mysql{/xtypo_code}
mysql symbolic link points to your current version of MySQL install, typically in the same directory. In my case, that directory is here:

/usr/local/mysql-5.0.45-osx10.4-i686/


All you need to do is recreate the symbolic link and you should be able to start your MySQL server again. You can create the symbolic link in your terminal window by typing the following:

sudo ln -s /usr/local/mysql-5.0.45-osx10.4-i686/ mysql

Note: You need to cd into /usr/local/ before running the command above.

Stalk Me

Facebook: marko.tomic Twitter: mtomic Twitter: SydneyScuba YouTube: migonyourtail Linked In: tomicmarko MySpace: markomedia Google Wave: marko2009 blip.fm: markotomic Flickr: markotomic FeedBurner: markomedia

Site Login

Tag Cloud

Browser Poll

What browser do you use?