Paul Ruffle at Starry Night
tools apps links disk images x11 ssh parallels tools cron .bashrc apache php/mysql/ssi virtual hosts

Mac OS X - Hints and Tips

Open Quotes Unfortunately, although Max OS X gives you Unix under the hood, you don't necessarily get a fully functioning Unix environment in the same way that you do from a standard Linux install. So these are my hints and tips for getting the full monty on your Mac. It's a combination of various configuration settings and the installation of additional open source utilities. I also list various software tools, utilities and applications that I find particularly useful. If you are interested in using Fortran functions in your C/C++ programmes, see my notes on Calling Fortran functions from C, which is on the Xgear web site. Close Quotes

Paul Ruffle

Tools and Utilities

XCode Developer Tools
In order to build applications from source code, you need compilers like g95, so install "XcodeTools.mpkg", which you should find in the "Xcode Tools" folder on your installation DVD.

X11 SDK
If you are building X11 applications like XEphem, you need to install the X11SDK package, which will be on your installation DVD. It should get installed with XCode Developer Tools, but you need to check.

Fink brings Unix open source software to Mac OS X (includes Fink Commander GUI). Good for Mac versions of xephem, xemacs, wget, ghostscript, gv and so much more. Indispensable really.

eps2png eps2gif eps2jpg converts files from EPS format (Encapsulated PostScript) to PNG (Portable Network Graphics), JPEG or GIF formats. It is a perl script that uses Ghostscript to produce the images.

ps2pdf - work-alike for nearly all the functionality (but not the user interface) of Adobe's Acrobat Distiller product: it converts PostScript files to Portable Document Format (PDF) files (not the same as pstopdf) and is part of Ghostscript.

Remote Buddy enables you to use your Apple remote to control applications such as PowerPoint, Keynote, NeoOffice, Adobe Reader or Preview.

Make Symlink makes proper symbolic links from the contextual menu (not free, but a non-registered version gives the basic functionality).

TinkerTool gets at all sorts of hidden settings.

HandBrake is an open-source, GPL-licensed, multiplatform, multithreaded DVD to MPEG-4 converter.

ffmpegX is a GUI designed to easily operate more than 20 powerful Unix open-source video and audio processing tools.

Audacity is free, open source software for recording and editing sounds.

RecoverTrasher is a small Applescript application that automatically removes the recovered files folder that Tiger dumps into the trash can.

Berlios Desktop Manager gives Tiger users multiple desktops, i.e. Leopard's Spaces.

Applications

iWork consists of Pages for the creation of documents, Numbers for the creation of spreadsheets and Keynote for the creation of presentations. Unlike Word, Excel and PowerPoint they let you do what you want, and for a lot less money! However, I still like Excel, but it was originally written for the Mac!

BBEdit is the best Mac editor in the known Universe, but it's not free!

Aquamacs is an Aqua-native build of the powerful Emacs text editor.

NeoOffice is an Aqua version of OpenOffice.

Parallels Desktop for Mac enables you to run Windows or Linux virtual machines on an Intel based Mac without rebooting. It even allows shared folders under Linux.

CentOS is a free and open source Linux distribution based on Red Hat Enterprise Linux. It installs easily under Parallels Desktop, and Parallels Tools work properly (see install note oposite).

XEphem is a scientific-grade interactive astronomical ephemeris software package, used by many professional astronomers.

Fugu is a graphical frontend to SFTP and supports SCP file transfers (free license).

Fetch is an easy-to-use FTP and SFTP client (free license to educational institutions).

MacTeX distribution from TUG contains the complete TeX Live 2007 distribution of TeX, Ghostscript, ImageMagick, as well as TeXShop, LaTeXiT, BibDesk and Excalibur.

TeXShop is a TeX previewer for Mac OS X, that uses "pdftex" and "pdflatex" rather than "tex" and "latex" to typeset.

Excalibur is free spell checker designed for LaTeX documents.

Flip4Mac allows you to play, import, and export Windows Media video and audio files on your Mac using QuickTime.

PHP Apache Module is a PHP module for the Apache web server included in Mac OS X. However, Apple has included PHP 5 since Leopard (10.5), and it can be enabled by editing httpd.conf (more).

MySQL can be installed on 10.4.x or newer using a binary package instead of the binary tarball distribution (more).
Download MySQL Community Server
Other MySQL Downloads

phpMyAdmin is an excellent and easy to use free software tool written in PHP for handling the administration of local or remote MySQL databases via your web browser.

Useful Links

SourceForge

GNU MAC OS X Public Archive.

OSXFAQ Technical News and Support.

Mac OS X Hints

Apple - Mac OS X - Downloads

Apple - Downloads - UNIX & Open Source

Configuration and Settings

Burning ISO Disk Images

By default Snow Leopard burns a CD/DVD formatted as an HFS+/UDF hybrid (UDF supplanted ISO9660). However, if you want to burn an ISO9660 disk image to CD (or DVD) that can be read by any system (especially older versions of Windows), first make a disk image with Disk Utility (the default settings will be fine with a size to suit), then mount the image and copy whatever files you want to the disk image (you can change the volume name at this point too). Then unmount the disk image, open a terminal and use Apple's command line utility for working with disk images hdiutil:

    hdiutil makehybrid -iso -joliet -o cd-image.iso cd-image.dmg

This will create an ISO/Joliet .iso disk image file that you can burn to disk with Disk Utility. In fact you can do a lot more with hdiutil. Type man hdiutil in a terminal to get the full documentation. Here are a couple of useful examples:

Create a disk image from a folder:

    hdiutil create cd-image.dmg -srcfolder /path/to/folder/

Burn an ISO to CD (or DVD):

    hdiutil burn cd-image.iso

X11 Server

You need an X11 server running in the background, in order to run any open source applications that use the X11 Windows environment (like OpenOffice). If X11 is not already installed in your Applications/Utilities folder, install from "Optional Installs" on your installation DVD. For Leopard users X11 automatically starts the first time it is needed. If you are running Tiger add X11 to your System Preferences > Accounts > Login Items (see X-windows on OS X by William Scott).

Terminal or Xterm?

Now that Leopard automatically starts X11 the first time it is needed, you can use the Mac's own Terminal which is easy to configure and use. However, Tiger users may still need to use xterm, so edit the xterm command in your .xinitrc file and in the Customize Menu in X11:

    xterm -b 5 -bd red -cr blue -geometry 90x25 
          -fa Monaco -fs 11 -sb -sl 1000 -T $USER@$HOSTNAME &

The Customize Menu in X11 does not need the trailing &, and you can define different size terminals by changing the -geometry and -fs options. Most of the other options are self explanatory, use 'man term' for those you don't understand. If you do not have an .xinitrc file in your home directory, copy the default file /etc/X11/xinit/xinitrc to $HOME/.xinitrc.

X11 Forwarding

If you want to forward/receive X11 sessions to/from another host via SSH, check that you have "X11Forwarding yes" in the files /etc/sshd_config and /etc/ssh_config respectively.

Transparent yellow X11 cursor on Intel Macs

Tiger users may have noticed that when running some X11 applications from a Linux server, but viewing the application's session windows on your Intel Mac, the cursor becomes a transparent yellow outline. There is a fix at Mac OS X Hints, but note that it is for Intel Macs only.

SSH using RSA protocol version 2

To automatically login to a regularly used host you can create an RSA key pair by running ssh-keygen on your Mac:

    ssh-keygen -t rsa -f identity

(where identity could be your name or other identifyer)

Store the private key in $HOME/.ssh/identity
Store the public key in $HOME/.ssh/identity.pub

Then copy identity.pub to $HOME/.ssh/authorized_keys on the remote host (i.e. append the contents of identity.pub to the file authorized_keys).

Then run SSH as:

    ssh -i $HOME/.ssh/identity user@remotehost

or set up an alias to make life even easier:

    alias logmein="ssh -i $HOME/.ssh/identity user@remotehost"

You will then never have to type a password for that host, but make sure your system is secure first!

This is really useful for remote rsync (see below) backup shell scripts like:

    rsync -avr -e "ssh -i $HOME/.ssh/identity" 
          --rsync-path=/usr/local/bin/rsync  
          user@remotehost:somedir/ $HOME/bkup/somedir

(the above is typed as one single rsync command).

Parallels Tools under Linux

To install Parallels Tools in CentOS under Parallels Desktop, you need to be logged in as root, so open a terminal window in CentOS and use the su command to do this:

    su root

and enter the root password. Now unmount the current disk image:

    umount /dev/hdb

Create a folder named Parallels Tools in the /media/ folder (this folder will serve as a mount point - note the backslash that escapes the space character):

    mkdir /media/Parallels\ Tools

To mount the image enter:

    mount -o exec /dev/hdb /media/Parallels\ Tools

Change the directory to the CD/DVD-ROM directory using:

    cd /media/Parallels\ Tools/

In the CD/DVD-ROM directory, enter the following to launch Parallels Tools installation:

    ./install

and follow the on-screen prompts to install Parallels Tools. After this you should be able to share your Mac folders within CentOS, and have seamless mouse integration between the two systems.

For Fedora Linux use this to mount the image:

    mount -o exec /dev/sr0 /media/Parallels\ Tools

However, under Fedora 11 the tools don't actually work (as of September 2009). Hopefully the Parallels folk will fix this.

CRON

Your crontab resides in /var/cron/tabs/username, and this is an example of an entry that runs an rsync backup at 4:30 am every day:

# min   hour  mday  month wday  command
  30    4     *     *     *     /Users/username/bin/rsyncmymac

Also add/edit crontab for full paths, etc.

    SHELL=/bin/bash
    PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11R6/bin
    EDITOR=emacs
    MAILTO=username@mydomain.me.uk
    HOME=/Users/username

(Put an editable copy of your crontab somewhere like $HOME/Documents/myconfigs/username.cron).

Load your crontab with:

    cd $HOME/Documents/myconfigs
    crontab username.cron

List your current crontab with:

    crontab -l

Remove your current crontab with:

    crontab -r

Finally, don't forget to set System Preferences > Energy Saver to:

Put computer to sleep > Never

(you can put display and hard disc to sleep).

Note: cron can't run if the computer is asleep (or shutdown!) BUT see next item!

Backup to an External Drives

Unattended backup of files to an external drive may be a problem, as since 10.3.4 external drives unmount themselves when all users have logged out. Fortunately, Dantz documented a solution on their support site:

"When backing up to a file backup set on an external hard drive under Mac OS X 10.3, users may notice an error -43 (file/folder not found) referring to the backup set catalog when the backup is run during a time when all users are logged out. This problem occurs because mac os X 10.3 unmounts all non-boot, non-ide drives when no users are logged in.

The following unsupported workaround should cause Mac OS X to not unmount the volumes. As root, create the following file:

/Library/Preferences/SystemConfiguration/autodiskmount.plist

The file should contain the following:

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" 
     "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
    <plist version="1.0">
    <dict>
     <key>AutomountDisksWithoutUserLogin</key><true/>
    </dict>
    </plist>

Then, reboot the system. Volumes should now stay mounted regardless of whether a user is logged in."

Locate

Updating the locate database:

    sudo /usr/libexec/locate.updatedb

or add to your crontab:

    0 1 * * * root /usr/libexec/locate.updatedb

.BASHRC

When I last checked, Mac OS X appears to ignore any .login or .profile scripts in your home directory.

Paths

Paths should look something like this:

    PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/X11R6/bin:/usr/local/bin
    MANPATH=/usr/man:/usr/X11R6/man:/usr/share/man:/usr/local/man
    INFOPATH=/usr/share/info:/usr/local/info

but, for example, fink asks you to add:

    . /sw/bin/init.sh

to the end of your .bashrc so that it can add fink's paths to your path settings. However, to avoid adding these paths more than once (which tends to happen because .bashrc gets called at login and then again each time you start a terminal) do the following (the actual extra paths are up to you):

if test -z "$MYPATHS" ; then
    export PATH=.:$HOME/bin:/usr/local/bin:$PATH
    export MANPATH=$MANPATH:/usr/share/man:/usr/local/man
    export INFOPATH=$INFOPATH:/usr/local/info
    . /sw/bin/init.sh                           # for fink
    export MYPATHS=true
fi

Also make sure there are no "echo" commands in these login scripts. Such user friendly interactive output can completely screw SFTP connections to your Mac (see www.snailbook.com/faq/sftp-corruption.auto.html).

To get a prompt that tells who and where you are
(e.g. username@mymac:~/bin>) add:

    export PS1="\u@\h:\w> "

Alias

Some useful alias commands to add to your .bashrc:

    alias ssh="ssh -X"
    alias md="mkdir -p"
    alias rd="rmdir"
    alias df="df -h"
    alias mv="mv -i"
    alias slink="ln -s"
    alias sed='sed -E'
    alias l='ls -1'
    alias la='ls -lhAF'
    alias ll='ls -lhF'
    alias lt="ls -lhtrF"
    alias l.="ls -lhtrdF .*"
    alias dir="lt"
    alias dot="l."
    alias cd..="cd .."
    alias cd...="cd ../.."
    alias cd....="cd ../../.."
    alias ..="cd .."
    alias ...="cd ../.."
    alias ....="cd ../../.."

SENDMAIL/POSTFIX

(Tiger onwards actually uses postfix)

Edit the postfix configuration file /etc/postfix/main.cf to define myorigin, i.e. the domain of your web/php server:

    myorigin = mydomain.me.uk

Otherwise sendmail and PHP's mail() may bounce email to the mail file /var/mail/username, rather than send mail to your intended recipient.

APACHE 2.2

Your Mac's main web site (yourhostname.local) is in /Library/WebServer/Documents and your personal web site (yourhostname.local/~username) is in /Users/username/Sites (you can change these directories to symbolic links to elsewhere if you like).

Apache HTTP Server Version 2.2 Manual:

Browse yourhostname.local/manual/ or httpd.apache.org/docs/2.2/

Restarting Apache after configuration changes:

Check Web Sharing: On or Off in System Preferences > Sharing.

Running PHP under Apache

Apple has included PHP 5 since Leopard (10.5), so you don't need to install it separately. Enable it by uncommenting the line

    LoadModule php5_module    libexec/apache2/libphp5.so
in /etc/apache2/httpd.conf. You can also implement a php.ini file in /etc if you want to overide any of PHP's default behavior (start with the template file /etc/php.ini.default). In particular you might want to fix a warning appearing in phpinfo() by uncommenting date.timezone and inserting your time zone, e.g.
    date.timezone = "Europe/London"

Using MySQL with PHP under Apache

Download the appropriate MySQL package for OS X (32 or 64 bit depending on your system). Install everything in the package in this order: MySQL, MySQL Startup Item, MySQL Pref Pane. Start MySQL in the Preference Pane. Test that it's working:

    /usr/local/mysql/bin/mysql
(type exit to quit the MySQL monitor).

Fix mysql.sock location in php.ini. In /etc/php.ini, replace the three occurences of /var/mysql/mysql.sock with /tmp/mysql.sock.

Thanks to Jérôme Jaglale for PHP/MySQL tips.

Server Side Include (SSI) Configuration:

Apache's configuration file is /etc/apache2/httpd.conf (or /etc/httpd/httpd.conf for Apache 1 under Tiger), but edit with care!

The following link gives the pertinent configuration instructions:

httpd.apache.org/docs/2.2/howto/ssi.html

I would recommend using the following settings:

mod_include must be installed and enabled (it usually is).

Also change the second instance of AllowOverride to All so that .htaccess works

    AllowOverride All

The following directives must be in the httpd.conf file or in .htaccess in the root directory or appropriate sub-directories of the site you want to allow SSI:

    Options Includes

Set the XBitHack directive:

    XBitHack on

XBitHack tells Apache to parse files for SSI directives if they have the execute bit set.

In fact it would be better to set:

    XBitHack Full

as this tells Apache to determine the last modified date by looking only at the date of the originally requested file, ignoring the modification date of any included files (useful for SSI that add a page's last modified date to the page).

Alternatively you can use the filename extension .shtml to tell Apache to parse files for SSI directives. To do this make sure that these two lines are uncommented in httpd.conf:

    AddType text/html .shtml
    AddOutputFilter INCLUDES .shtml

You also need to ensure that the various permutations of index.* are specified so that all home pages are seen by Apache:

    <IfModule mod_dir.c>
        DirectoryIndex index.html index.htm index.shtml index.php
    </IfModule>

You should also have a personal configuration file in /etc/httpd/users/username.conf if you intend to use your personal web site:

    <Directory "/Users/username/Sites/">
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Order allow,deny
        Allow from all
    </Directory>

You can control access to a site by using this in the appropriate directory's .htaccess file:

    AuthType Basic
    # name that appears in Login window
    AuthName "Sitename Administrator"
    # apache password file (you have to set this up)
    AuthUserFile /usr/local/apache/passwd/passwords
    # username(s) from password file that can login
    Require user username
    # deny first!
    Order Deny,Allow
    # stop everyone
    Deny from all
    # then allow chosen domains or IP addresses
    Allow from domainname

See httpd.apache.org/docs/2.2/howto/auth.html for how to create password file.

Enabling Virtual Hosts

Here's how to setup multiple sites on your Mac, with "root relative" calls for graphics, scripts, CSS, links, etc. and keep all of the files for any particular site together - and they don't even have to be in the default web server document root. The practice is called "Name-Based Virtual Hosts" as described in Apache's documentation.

First, use NetInfo Manager (Applications/Utilities) to create a pointer to localhost, to tell Apache what files to serve as the web site:

Open NetInfo Manager and browse to /machines/localhost.
Click on the lock, and enter your password so that you can make changes.
Duplicate "localhost" (Edit > Duplicate).
Select "localhost copy" and then select the name property in the lower window.
Change the value of "name" from localhost to whatever your development site will be, e.g. www.test.site (don't use a real domain name, as it won't work).
Click on one of the other directories in the list, and you will be asked if you want to save your changes. Save them!

You've now made an extra entry in your NetInfo Manager for a test site that points to your local machine. However, if you try to go to http://www.test.site with your web browser, you'll just see your Mac's main web site at http://localhost.

The second step is to create a VirtualHost entry in your Apache config file /etc/httpd/httpd.conf, using your test site's server name and an appropriate path to the location of the test site's files (you can set the site's options as well):

    NameVirtualHost 127.0.0.1:80
    <VirtualHost 127.0.0.1>
        DocumentRoot /Library/WebServer/Documents
        ServerName localhost    
    </VirtualHost>
    <VirtualHost 127.0.0.1>
        DocumentRoot /Users/username/webdev/test.site
        ServerName www.test.site
        <Directory "/Users/username/webdev/test.site">
            Options Indexes FollowSymLinks MultiViews Includes
            AllowOverride None
            Order allow,deny
            Allow from all
        </Directory>
    </VirtualHost>

Note that your Mac's main web site "localhost" must be defined first. You can create as many additional virtual hosts as you like.

Source text for Enabling Virtual Hosts by Bob Davis.


Last updated 20 August 2010 by Paul Ruffle

Home > Mac OS X > Return to Top