Mac OS X Setting Up Initial Tools for a Web Developer

About an year ago I bought a Macbook Pro Retina and completely switched from Ubuntu (older PC) to Mac. In this guide (for starters) I’ll quickly show how to install and setup various important softwares and tools that are essential for web development like apache, php, mysql, ruby, python, node, redis, mongo, git, wget via Homebrew which is a package manager for OS X. It is similar to the Advanced Packaging Tool (APT) on Debian or Ubuntu.

Installing Homebrew

Getting homebrew is easy:

What's the one thing every developer wants? More screens! Enhance your coding experience with an external monitor to increase screen real estate.

ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)"

Note: You need Xcode or just the Xcode command line tools (consumes lesser space) for the installation.

Installing git, htop, wget, tmux, pv

$ brew install git htop wget tmux pv

Installing MySQL

$ brew install mysql
==> Downloading https://downloads.sf.net/project/machomebrew/Bottles/mysql-5.6.1
######################################################################## 100.0%
==> Pouring mysql-5.6.10.mountain_lion.bottle.tar.gz
==> /usr/local/Cellar/mysql/5.6.10/bin/mysql_install_db --verbose --user=rishabh
==> Caveats
A "/etc/my.cnf" from another install may interfere with a Homebrew-built
server starting up correctly.

To connect:
    mysql -uroot

To have launchd start mysql at login:
    ln -sfv /usr/local/opt/mysql/*.plist ~/Library/LaunchAgents
Then to load mysql now:
    launchctl load ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
Or, if you don't want/need launchctl, you can just run:
    mysql.server start
==> Summary
   /usr/local/Cellar/mysql/5.6.10: 9245 files, 351M

$ ln -sfv /usr/local/opt/mysql/*.plist ~/Library/LaunchAgents
/Users/rishabhpugalia/Library/LaunchAgents/homebrew.mxcl.mysql.plist -> /usr/local/opt/mysql/homebrew.mxcl.mysql.plist

$ launchctl load ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist

Installing Apache

Apache is installed by default on Mac.

Installing PHP 5.4

$ brew tap homebrew/dupes
Cloning into '/usr/local/Library/Taps/homebrew-dupes'...
remote: Counting objects: 894, done.
remote: Compressing objects: 100% (488/488), done.
remote: Total 894 (delta 489), reused 797 (delta 406)
Receiving objects: 100% (894/894), 155.44 KiB | 115 KiB/s, done.
Resolving deltas: 100% (489/489), done.
Tapped 41 formula

$ brew tap josegonzalez/homebrew-php
Cloning into '/usr/local/Library/Taps/josegonzalez-php'...
remote: Counting objects: 3185, done.
remote: Compressing objects: 100% (1649/1649), done.
remote: Total 3185 (delta 1810), reused 2765 (delta 1430)
Receiving objects: 100% (3185/3185), 554.99 KiB | 84 KiB/s, done.
Resolving deltas: 100% (1810/1810), done.
Tapped 118 formula

$ brew install php54 --with-mysql
==> Downloading http://www.php.net/get/php-5.4.15.tar.bz2/from/this/mirror
Already downloaded: /Library/Caches/Homebrew/php54-5.4.15
==> ./configure --prefix=/usr/local/Cellar/php54/5.4.15 --localstatedir=/usr/loc
==> make
==> make install
==> /usr/local/Cellar/php54/5.4.15/bin/pear config-set php_ini /usr/local/etc/ph
==> Caveats
To enable PHP in Apache add the following to httpd.conf and restart Apache:
    LoadModule php5_module    /usr/local/opt/php54/libexec/apache2/libphp5.so

The php.ini file can be found in:
    /usr/local/etc/php/5.4/php.ini

✩✩✩✩ PEAR ✩✩✩✩

If PEAR complains about permissions, 'fix' the default PEAR permissions and config:
    chmod -R ug+w /usr/local/Cellar/php54/5.4.15/lib/php
    pear config-set php_ini /usr/local/etc/php/5.4/php.ini

✩✩✩✩ Extensions ✩✩✩✩

If you are having issues with custom extension compiling, ensure that this php is
in your PATH:
    PATH="$(brew --prefix josegonzalez/php/php54)/bin:$PATH"

PHP54 Extensions will always be compiled against this PHP. Please install them
using --without-homebrew-php to enable compiling against system PHP.
==> Summary
   /usr/local/Cellar/php54/5.4.15: 485 files, 38M, built in 2.3 minutes

Make sure you go through the common issues here, especially the Xcode command line tools one. Make sure they’re installed else you might fall into the same trap as demonstrated here.

Adjust .bash_profile:

export PATH="$(brew --prefix php54)/bin:$PATH"

Just find LoadModule php5_module in /etc/apache2/httpd.conf and after that line (which is commented) add this:

LoadModule php5_module /usr/local/Cellar/php54/5.4.15/libexec/apache2/libphp5.so

Finally, change your document roots in the same file (I made mine at ~/www):

#DocumentRoot "/Library/WebServer/Documents"
DocumentRoot "/Users/rishabhpugalia/www"

and

#<Directory "/Library/WebServer/Documents">
<Directory "/Users/rishabhpugalia/www">

If you want to add vHosts then the proper way of doing it is to first uncomment this line in httpd.conf:

# Virtual Hosts
#Include /private/etc/apache2/extra/httpd-vhosts.conf

Then in the same file, add your virtual host definitions at the end, for instance like these:

# Virtual hosts added by rishabh

<VirtualHost *:80>
  DocumentRoot "/Users/rishabh/www"
  ServerName localhost
</VirtualHost>

<VirtualHost *:80>
  DocumentRoot "/Users/rishabh/www/temp/public
  ServerName temp.org
</VirtualHost>

<VirtualHost *:80>
  DocumentRoot "/Users/rishabh/www/temp/public/sandbox"
  ServerName s.temp.org
</VirtualHost>

If you’ve to compile a PHP extension later (after the installation) then here’s an example of how to do that – http://danbarber.me/postgresql-php-on-snow-leopard/. This post explains how to install the PostgreSQL extension for PHP.

Some extra resources on the same topic for reference –

Installing phpmyadmin

$ brew install phpmyadmin
==> Installing phpmyadmin dependency: mcrypt
==> Downloading http://sourceforge.net/projects/mcrypt/files/Libmcrypt/2.5.8/lib
######################################################################## 100.0%
==> ./configure --prefix=/usr/local/Cellar/mcrypt/2.5.8 --mandir=/usr/local/Cell
==> make install
   /usr/local/Cellar/mcrypt/2.5.8: 12 files, 348K, built in 3.5 minutes
==> Installing phpmyadmin dependency: php54-mcrypt
==> Downloading http://www.php.net/get/php-5.4.15.tar.bz2/from/this/mirror
######################################################################## 100.0%
==> /usr/local/Cellar/php54/5.4.15/bin/phpize
==> ./configure --prefix=/usr/local/Cellar/php54-mcrypt/5.4.15 --with-php-config
==> make
==> Caveats
To finish installing mcrypt for PHP 5.4:
  * /usr/local/etc/php/5.4/conf.d/ext-mcrypt.ini was created,
    do not forget to remove it upon extension removal.
  * Restart your webserver.
  * Write a PHP page that calls "phpinfo();"
  * Load it in a browser and look for the info on the mcrypt module.
  * If you see it, you have been successful!
==> Summary
   /usr/local/Cellar/php54-mcrypt/5.4.15: 3 files, 56K, built in 3.6 minutes
==> Installing phpmyadmin
==> Downloading http://downloads.sourceforge.net/project/phpmyadmin/phpMyAdmin/3
######################################################################## 100.0%
==> Caveats
Note that this formula will NOT install mysql. It is not
required since you might want to get connected to a remote
database server.

Webserver configuration example (add this at the end of
your /etc/apache2/httpd.conf for instance) :
  Alias /phpmyadmin /usr/local/share/phpmyadmin
  <Directory /usr/local/share/phpmyadmin/>
    Options Indexes FollowSymLinks MultiViews
    AllowOverride All
    Order allow,deny
    Allow from all
  </Directory>
Then, open http://localhost/phpmyadmin

More documentation : file:///usr/local/Cellar/phpmyadmin/3.5.7/share/phpmyadmin/Documentation.html
==> Summary
   /usr/local/Cellar/phpmyadmin/3.5.7: 1002 files, 21M, built in 5.2 minutes

As suggested above add the following piece of config snippet in your /etc/apache/httpd.conf:

Alias /phpmyadmin /usr/local/share/phpmyadmin
<Directory /usr/local/share/phpmyadmin/>
  Options Indexes FollowSymLinks MultiViews
  AllowOverride All
  Order allow,deny
  Allow from all
</Directory>

Installing Node

$ brew install node

When using homebrew to install node, NODE_PATH needs to be pointed to the correct place to find Node modules. More on NODE_PATH here. So lets do that:

export NODE_PATH="/usr/local/lib/node"

Finally, we also need to change our our $PATH to access executable files of globally installed node modules

export PATH="/usr/local/share/npm/bin:$PATH"

All these exports can go to .bash_profile.

Installing MongoDB

$ brew install mongodb
==> Downloading http://fastdl.mongodb.org/osx/mongodb-osx-x86_64-2.4.3.tgz
######################################################################## 100.0%
==> Caveats
To have launchd start mongodb at login:
    ln -sfv /usr/local/opt/mongodb/*.plist ~/Library/LaunchAgents
Then to load mongodb now:
    launchctl load ~/Library/LaunchAgents/homebrew.mxcl.mongodb.plist
Or, if you don't want/need launchctl, you can just run:
    mongod
==> Summary
   /usr/local/Cellar/mongodb/2.4.3-x86_64: 20 files, 315M, built in 35.1 minutes

$ ln -sfv /usr/local/opt/mongodb/*.plist ~/Library/LaunchAgents
/Users/rishabhpugalia/Library/LaunchAgents/homebrew.mxcl.mongodb.plist -> /usr/local/opt/mongodb/homebrew.mxcl.mongodb.plist

$ launchctl load ~/Library/LaunchAgents/homebrew.mxcl.mongodb.plist

Installing Redis, Ruby, Python

These are easy:

$ brew install redis ruby python3

… and follow any instructions provided at the end of installations, especially those for auto-starting redis.

Since OS X ships with ruby and python already I added this to .bash_profile so that the newly installed binaries (latest version) takes precedence:

export PATH="/usr/local/bin:$PATH"
$ ruby --version # before export
ruby 1.8.7 (2012-02-08 patchlevel 358) [universal-darwin12.0]

$ ruby --version # after export
ruby 2.0.0p0 (2013-02-24 revision 39474) [x86_64-darwin12.2.1]

Installing luajit

$ brew install luajit
$ sudo ln -s /usr/local/bin/luajit /usr/bin/luajit # need symlinking for scripts with hashbangs to work

Hope that helps some of you who are a web software developer and just beginning your journey on a Macintosh.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download

Author: Rishabh

Rishabh is a full stack web and mobile developer from India. Follow me on Twitter.

Leave a Reply

Your email address will not be published. Required fields are marked *