Developing on OSX Yosemite
I shared how I configured Windows 10 for my web development needs. In this post, I will share how I configured OSX Yosemite 10.10.5. I will be using Homebrew to install everything I need. This is a great package manager available on OSX that’s similar to apt-get on Debian and yum on Red Hat. So let’s get started.
Make sure you are not using MAMP or something similar. It could affect the environment. Remove it before continuing. Ruby is used to install Homebrew. Ruby should already be installed by default on your Mac.
# install Homebrew ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" # run update and upgrade brew update brew upgrade # check installation brew doctor
If you haven’t done any development on your Mac, it may ask you to install the command line developer tools. I would not only install but get Xcode as well just in case you’ll be using Xcode for other things. So click on the Get Xcode button to install both Xcode and the developer tools.
This will open the App Store. Once installed, open XCode for the first time. It will ask you to agree to the terms and it will ask you to enter your password. If you don’t do this, it will ask you when you run your brew command until you do so. Afterwards, go back to terminal and press Return or run the process over. It will prompt you for your password. Hopefully you don’t have any errors when running
Homebrew does not have a default formula for PHP. A formula is what a repository is called in Homebrew. We need to add two.
brew tap homebrew/dupes brew tap homebrew/php
With this, we can install PHP along with other options like PHP for Apache or Nginx. You can view the options with the following command.
brew options php56
I want to install PHP with the Mysql driver so I will use the following command. I’m not going to need a web server at the moment. PHP56 has a built-in one I can use.
brew install --without-apache --without-fpm --with-mysql php56
For some reason it wasn’t installing PHP56 so I had to run the install as follow.
brew install php56
If you read the long description after you install it, it explains more steps to set it up. I will also note it below.
Next we will update our $PATH so that we can use
php command in terminal.
# bash echo 'export PATH="/usr/local/sbin:$PATH"' >> ~/.bash_profile # allow for PHP CLI to use version from Homebrew export PATH="$(brew --prefix homebrew/php/php56)/bin:$PATH" . ~/.bash_profile # very that php is running from /usrl/local/bin/php which php # check the version php -v
If you don’t have a ~/.bash_profile, create one or use whatever file you’re using as the initialization file. It could be .bash_login or .bashrc.
Let’s set up a launch agent so that things will start automatically. We will create a folder in your Library folder called LaunchAgents. Then create symbolic links.
# create LaunchAgent folder mkdir -p ~/Library/LaunchAgents # create symbolic link for php ln -sfv /usr/local/opt/php56/homebrew.mxcl.php56.plist ~/Library/LaunchAgents/ # autostart launchctl load ~/Library/LaunchAgents/homebrew.mxcl.php56.plist
This is optional but if you’re going to develop using Laravel, then you will need mcrypt and composer.
# install mcrypt brew install php56-mcrypt # check/view modules and make sure mcrypt is there php -m # install composer brew install composer # check composer is installed composer about
Here are the commands to install MySQL using Homebrew.
# install mysql brew install mysql # set up autostart ln -sfv /usr/local/opt/mysql/*.plist ~/Library/LaunchAgents/ # start the server launchctl load ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist # run secure install, just follow the prompts mysql_secure_installation
Install Node and NPM
It’s really easy to install node and npm via homebrew.
# install node and npm brew install node # check the version of node and npm, also checks to see if it's installed node -v npm -v
Install RVM for Ruby
But Ruby is already installed with OSX. Yes it is but sometimes Apple will release newer versions at a later time and you may not be able to use new features. So to make things as flexible as possible, we’ll use rvm to handle different versions of Ruby. You can also use rbenv but this article we’ll be install rvm.
# you can append ruby=[version#] as well if you know the version # ahead of time curl -L https://get.rvm.io | bash -s stable --auto-dotfiles --autolibs=enable
It may give you a warning about .profile not existing (unless it already does) but if you’ve been using .bash_profile, make sure you add the contents of .profile into .bash_profile. It may look like this.
export PATH="$PATH:$HOME/.rvm/bin" # Add RVM to PATH for scripting [[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session$ # don't forget to source it source ~/.bash_profile # install ruby using rvm install [version] rvm install 2.2 # select version and use it if it didn't do it automatically rvm use --default 2.2 # check version and which one - should be in your home directory inside the .rvm directory ruby -v which ruby # check which gem, should be inside .rvm using same version as selected above which gem # update gem and install bundler gem update gem install bundler # install jekyll if you will use it gem install jekyll
That’s pretty much what I do to get an development environment going on OSX. Of course I didn’t include all the tools I use for deployment – that’s another post in the future. Why go through all the trouble when there’s MAMP or packaged environments? Well, I tried MAMP and purchased a pro license a few years back. I just didn’t have the same control as I do with this setup. Maybe it has changed now but this works for me. I also played with Vagrant. I don’t really like Virtualbox much. Hopefully this helps some of you. Please check outhttp://blog.frd.mn/install-nginx-php-fpm-mysql-and-phpmyadmin-on-os-x-mavericks-using-homebrew/. I got some of the commands off this post.