Mac Dev Environment

Published:
May 23rd 2021


Reading Time:
8 minutes

blog Mike Jones Writer

Introduction

Last month i went through the start to finish process of setting up Valet Linux on Ubuntu 20.04. Unfortunately the system i went through the tutorial with has died.... so i'm back to my iMac, i've bought some extra RAM (32gb) so at least its not falling over itself all the time.

Here's what we are going to do in this tutorial:

  • Install & Configure iTerm2 with OhMyZsh
  • Install Homebrew
  • install PHP
  • install Composer
  • install Valet
  • Configure Valet
  • install Laravel
  • install MySQL Workbench

It seems more than it is! So let's get cracking!

Installing iTerm2 & OhMyZsh

This first step is optional, i just prefer it to the Mac standard terminal. So head across to iTerm2's website and download it. Once downloaded, just run through the standard install process. (Open the Zip and copy the iTerm application to your Applications directory on your Mac).

When you first open iTerm2 you will be told you need to install some extra bits to use it, click ok to kick off the download, it should take about three minutes. once up you will be faced with:

Not very exciting to look at is it...

Now we need to pull down the OhMyZsh install file which can be done with the following command:

sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"

this takes a couple of seconds to download and you will be face with the following screen.

We're getting somewhere!

Now, you can leave it at this and continue to installing Homebrew and the rest of the dev environment or like me, you can install the Powerlevel10k theme.

First we need to install some recommended fonts which can be found here: MesloLGS Fonts.

Install these fonts and config iTerm2 to use them by going to iTerm2 preferences:

Also select the Use Ligatures.

Once the fonts are installed copy the following command and run it:

git clone --depth=1 https://github.com/romkatv/powerlevel10k.git ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes/powerlevel10k

This will download powerlevel10k to your machine ready for config, this should only take about 10 seconds.

Once downloaded we need to tell ZSH to use the Powerlevel10k package by editing its config. Type: nano ~/.zshrc which will bring the config up. When the config appears find the line ZSH_THEME="robbyrussell" and replace it with ZSH_THEME="powerlevel10k/powerlevel10k" Once you have pasted the new theme press Ctrl + X and hit enter, this will save the config.

When its saved you'll be returned to the command window again.... and it will look like nothing has changed, were nearly done with the terminal don't worry. To setup the theme you can either Close and Re-open iTerm and the install wizard will start for you or just type p10k configure and it will open the wizard for you.

Now this bit is all up to you, have a look at the config options and setup as you like. Mine looks like this:

Nice right? and thats it. The terminal is setup with OhMyZsh and Powerlevel10k . Double check that iTerm is your default terminal and you're good to go.

Install Homebrew

What is Homebrew? is a god send and is essentially a package manager for MacOS and Linux. Installing it couldn't be any easier.... Simply copy and paste the following command into your terminal and press enter:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

This will take a good few mins to download as there is a lot that comes down with it. And thats it....... Yep... thats it... Homebrew is now installed ready for your brew commands.

Installing PHP

First off lets update our brew install with the following command brew update. at this points its probably not necessary to do so as its a fresh install, Just get into the habit of doing so going forward.

Once any updates are done (if any) you can install PHP by typing the following:

brew install php

and thats it, again this may take a few minutes but once its done that its you have php installed on your machine.

Installing Composer and setting it up

I have no idea why but on my windows machine i used to learn dev work on i always struggled to get composer working properly. On Linux and macOS it just seemed easier...

The following commands needs to be run in terminal, I tend to run them one at a time just incase, but as far as i'm aware you can run them all at the same time.

Note: hash_file command is subject to change, so it might be worth checking for the latest command for this here.

php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('sha384', 'composer-setup.php') === '756890a4488ce9024fc62c56153228907f1545c228516cbf63f885e036d37e9a59d27d63f46af1d4d07ee0f76181c7d3') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php
php -r "unlink('composer-setup.php');"

Now we need to make composer globally accessible and to do that we need to move the Composer.phar file to a folder that is accessible to the system PATH. The following command will do this for you.

Simply type:

mv composer.phar /usr/local/bin/composer

Now you can use composer <Your Command> Instead of php composer.phar <your command>.

And finally we need to add it to the global path in ZSH. Type: nano ~/.zshrc and copy the below lines to the bottom of the file and save it.

PATH=$HOME/.config/composer/vendor/bin:~/.composer/vendor/bin:$PATH
export PATH

Ctrl + X to exit and Save modified buffer? y and hit enter.

Now apply them changes by typing: source ~/.zshrc

And thats composer completely setup to work with zsh and is globally accessible.

Install Laravel Valet

Valet is awesome, early in my Laravel journey i used homestead which is also very powerful but can be cumbersome. Average memory usage could be a gig or two whereas Valet..... 7mb..... Yep 7MB, you can park your domains so you can use ANY folder on your system you want for ease of use. I believe Valet was originally designed just for macOS but has since been ported to both Windows and Linux.

to start with copy the following command into your terminal:

composer global require laravel/valet

Once this has completed type:

valet install

This bit takes a little bit longer as it will check for installed prerequisites and download them through brew if not (and also install them). you should now have the following terminal window:

Now you can leave the domain prefix as .test if you like, its really not important. but i tend to change it to .vm with the following command:

valet domain vm

That will set it all up so you can type a url like www.test.vm and it will work :D

one final step for us to do is set the PHP version valet uses. again with Valet this is dead easy, Simply type:

valet use php@8.0

As we installed PHP with the standard Homebrew setup earlier though it should already be PHP 8.0. The beauty with Valet is you can switch between PHP versions using the above command.

Next were going to create a directory to store our websites and park the directory. We'll do this in the Home root of MacOS in your terminal type: cd ~/

When you are there you need to make the folder by typing the following command:

mkdir web_data

web_data is what i call my folder, you can change this to what ever you want and it will do the same. when you have run the command CD into the directory: cd web_data and then park the folder as your web folder like so:

valet park

This will now serve any site directory as a website in there. For example, if you have a folder called awesomewebsite in your web_data folder you can simply type awesomewebsite.vm in a browser and it will serve the site.

Install Laraval Framework

Now for the star of the show! Laravel... To pull down and install laravel simply type:

composer global require laravel/installer

this will bring down the installer so its globally accessible to you when ever you ant to make a new project by typing something like: laravel new website-name

And thats it for laravel.....

Also at this point install NPM with this command:

brew install node

Install MySQL on your Mac

This another install that Brew can help with and its accomplished in a single command

brew install mysql

After the install is complete start the service by typing

brew services start mysql

Once this is complete you will need setup MySQL for use... this can be done in a few different ways, i prefer the mysql_secure_installation method as it asks you questions on how you want to setup your MySQL environment.

sudo mysql_secure_installation

During this installation the only question you really need to answer is the one on password security you can set it at "0" as its a local environment, however if you're using this method to install MySQL on a server like i did you'll want to choose a higher security.

And thats it. Your DBs are accessible on 127.0.0.1 under root and what ever password you set when going through the secure install.

To manage your DBs there is a lot of choices so il let you choose this bit yourself. Personally i use MySQL workbench as its something i've used for a while and i'm familiar with.

Nice to have's!

Terminal Aliases - be lazy why type: cd ~/web_data when you can type wd and get the same result this is done through the ~/.zshrc file type nano ~/.zshrc to edit the config, and find the # Example Aliases and set them up as you like.

Dbeaver - If you plan one writing RAW SQL to interact with your DB's this free and easy to setup solution is for you!.