Categories
Code OSX PHP

Setting up OSX Big Sur with Valet, PHP & MySQL for Web Development

In this post I’ll post all of the steps to set up your Mac for PHP web development.
We will be setting up OSX Big Sur with Valet, PHP & MySQL.

I’ll be using the follow tools:

  • OSX Big Sur 11.2.3
  • iTerm (or osx terminal)
  • Homebrew
  • Composer 2
  • Laravel Valet
  • PHP 8 and PHP 7.4
  • MySQL 8, Sequal Ace and DBngin

Install Homebrew

Load the website https://brew.sh and copy the install bash script and run it in iTerm.

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

This will take a few minutes to run. Once complete, in my video you see me install a Oh-my-ZSH and a theme – this is optional.

Install Composer

Now homebrew is installed, we install composer 2 and then set up your PATH, making composer available globally on your Mac.

Visit https://getcomposer.org and the download page.

Copy the following lines into iTerm, making sure each line executes before running the next.

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');"

Once those 4 commands have run, run the following two commands:

mv composer.phar /usr/local/bin/composer
export PATH="$PATH:$HOME/.composer/vendor/bin"

Install Laravel Valet

Okay – we’re making good progress, now we want to install Laravel Valet. I used to use Homestead which is a complete Ubuntu operating system with many more features, this takes up more resources on your Mac, and no longer works on BigSur or Apple Silicon (M1) Macs.

Load the Laravel Valet site: https://laravel.com/docs/8.x/valet

Follow their instructions, we’re going to make sure homebrew is up-to-date, install PHP, Valet and for our development, set valet to use PHP 7.4 not PHP 8.03 which is the current PHP version.

brew update
brew install php
composer global require laravel/valet
valet install

These each take some time to run, grab a drink or cigar – you’ll need to wait.
Once done, we’re going to switch to PHP 7.4

valet use [email protected]4

Setting up an example site

Now we have a working PHP and NGINX install using Valet, we’re going to set up a simple PHP site.

Valet sets up a local DNS server dnamasq – this bind and domain with the .test tld.
This is great because it means we don’t need to worry about hacking our host file (/etc/hosts) we just link a site, and it works.

I’m going to make a ‘code’ directory in my home directory on my Mac, then make a test sites folder and ad a simple index.php with a phpinfo() command to output this on my browser.

cd ~/
mkdir code
cd ~/code
mkdir testsite
cd ~/code/testsite
nano index.php
<?php // index.php

    die(phpinfo()); 

?>

Okay – our test code is ready, in the ~/code/testsite directory now we need to connect Laravel Valet to this site, it’s simple with the following command:

valet link testsite

Now open your browser, and load the site:

http://testsite.test/

You should see your phpinfo() page.

Leave a Reply

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