Tuesday, January 1, 2008

Dev environment on OSX

I feel like I'm behind at work recently so I didn't want to start the new year at the office spending time configuring the new notebook. The baby was nice to me tonight and went to bed early so it allowed me to have the chance to get my development environment on the new Macbook Pro with OSX Tiger configured. Thanks to M in Ohio who saved me hours of time by pointing me to the right solution.

The nice thing about the OSX is that it is build on top of UNIX which is a developer's OS. You'll find that most open source tools are available and if not then getting it compiled from source is usually possible. I used compile everything from source including the kernel, but now that I am a lazy old man, I tend to prefer using some sort of package management solution that has the dependencies resolved. For Linux, I like the yum package management tool that sits on top of RPM. It beats the hell out of downloading the source and figuring out all the dependencies.

M pointed me to MacPorts as a similar repository/package management solution for OSX open source packages. It's really easy to use. Simply download the install package from the site, run it and you're ready to go. I did ran into one bug where it didn't create a .profile file for me so the path to "port" couldn't be found. I'm not sure why, but a quick look on the site and I knew which directories to add to my $PATH variable.

export PATH=/opt/local/bin:/opt/local/sbin:$PATH

Don't forget to "source ~/.profile" to pick up the change.

With MacPorts installed, it was only a matter of grabbing the programs I needed for a web development environment: Apache2, MySQL, PostgreSQL, PHP5.

Installing Apache2:

  • sudo port install apache2

  • cp /opt/local/apache2/conf/httpd.conf.sample /opt/local/apache2/conf/httpd.conf

  • sudo /opt/local/apache2/bin/apachectl start

  • point your browser to http://localhost to see that everything is running.

If you want to automatically start apache at boot-up then do then:

sudo launchctl load -w /Library/LaunchDaemons/org.macports.apache2.plist

Installing MySQL and PostgreSQL:

  • sudo port install mysql5 mysql5-server; sudo -u mysql mysql_install_db5 (to start the daemon: cd /opt/local ; /opt/local/lib/mysql5/bin/mysqld_safe &)
  • To automatically have mysql start: sudo launchctl load -w /Library/LaunchDaemons/org.macports.mysql5.plist
  • sudo port install postgresql84 postgresql84-server
    To create a database instance, after install do
    sudo mkdir -p /opt/local/var/db/postgresql84/defaultdb
    sudo chown postgres:postgres /opt/local/var/db/postgresql84/defaultdb
    sudo su postgres -c '/opt/local/lib/postgresql84/bin/initdb -D /opt/local/var/db/postgresql84/defaultdb'
    (to start: /opt/local/lib/postgresql84/bin/postgres -D /opt/local/var/db/postgresql84/defaultdb)

Installing PHP5 with support for MySQL, PostgreSQL:

  • sudo /opt/local/apache2/bin/apachectl stop
  • sudo port install php5 +apache2 +postgresql +pear
  • sudo port install php5-mysql php5-sqlite
  • sudo cp /opt/local/etc/php5/php.ini-development /opt/local/etc/php5/php.ini
  • sudo vi /opt/local/apache2/conf/httpd.conf
    • add "Include conf/extras-conf/*.conf" to /opt/local/apache2/conf/httpd.conf

  • sudo /opt/local/apache2/bin/apachectl start

Installing Eclipse IDE:

  • Download the IDE from Eclipse.
  • unarchive it to whichever location you want to run it from (I put it in /Applications/eclipse).

With that, the an Unix development environment capable of doing web development with PHP, MySQL and/or PostgreSQL as well as Java/C/C++ development is all ready!

For a little more detail about the set up process, I stumbled on this nice post.

No comments:

Post a Comment