DEV Community

Ibrar Hussain
Ibrar Hussain

Posted on

Mac M1 setup for Local Development with Laravel Valet

Last week, I have received my new Macbook Pro M1. I am really amazed by its performance and battery timing. The one thing you instantly notice is that it does not heat up like the Intel-based Macbook Pro.

I won't go into the details about how I struggled to set up my local development environment with different options like Homestead, Laradoc, Sail etc.

Using a new M1 Mac the best and easy solution is to use Laravel Valet.

Following are the steps:

Setup ARM Compatibility

  • Install Rosetta with the following command:
/usr/sbin/softwareupdate --install-rosetta --agree-to-license
Enter fullscreen mode Exit fullscreen mode
  • Add the following function to your .zshrc in order to make an alias for arm while running commands with x86 flags. Shoutout to Matt Stauffer
arm() {
  arch -x86_64 $@
}
Enter fullscreen mode Exit fullscreen mode

Homebrew

  • Run the following command to install homebrew
arm /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
Enter fullscreen mode Exit fullscreen mode
  • You can confirm the installation with brew --version and you should get a result like the following: Alt Text

PHP

  • Run the following command to install PHP latest version
arm brew install php
Enter fullscreen mode Exit fullscreen mode
  • If you want to install a specific version of PHP the run the following command
arm brew install php@7.3
Enter fullscreen mode Exit fullscreen mode
  • You can confirm the installation with php -v and you should get a response like the following Alt Text

MySQL

  • For the latest version of MySQL run the following command
arm brew install mysql
arm brew services start mysql
Enter fullscreen mode Exit fullscreen mode
  • For a specific version
arm brew install mysql@5.7
arm brew services start mysql@5.7
Enter fullscreen mode Exit fullscreen mode
  • Setup default root password with the following command
mysql_secure_installation
Enter fullscreen mode Exit fullscreen mode
  • It will prompt you steps like the following image Alt Text

Composer

  • Install composer via the following commands and then move the PHAR file to the bin folder
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');"
mv composer.phar /usr/local/bin/composer
Enter fullscreen mode Exit fullscreen mode
  • Add the following line to your .zshrc file
export PATH=${PATH}:~/.composer/vendor/bin
Enter fullscreen mode Exit fullscreen mode

Valet

  • To install Valet run the following command
composer global require laravel/valet
valet install
Enter fullscreen mode Exit fullscreen mode
  • You can confirm the Valet installation by running valet -V and you should get a response like the following Alt Text
  • After successful installation, now you can either park an entire folder or link a single application folder. For more details go to Valet

Start Valet

  • You can start Valet with the following command
valet start
Enter fullscreen mode Exit fullscreen mode
  • You should get a response like the following Alt Text
  • Now, you can visit any of your Laravel application that you have already linked

Some of the useful commands list

arm brew services list
Enter fullscreen mode Exit fullscreen mode
arm brew services start mysql
Enter fullscreen mode Exit fullscreen mode
arm brew services stop mysql
Enter fullscreen mode Exit fullscreen mode
arm brew services restart mysql
Enter fullscreen mode Exit fullscreen mode
valet start
Enter fullscreen mode Exit fullscreen mode
valet stop
Enter fullscreen mode Exit fullscreen mode
valet restart
Enter fullscreen mode Exit fullscreen mode
valet install php@7.3
Enter fullscreen mode Exit fullscreen mode
valet use php@7.3
Enter fullscreen mode Exit fullscreen mode
References

Top comments (5)

Collapse
 
hcmf profile image
HCMF

Thanks so much for posting this!

Collapse
 
luisgmoreno profile image
Luigui Moreno

How is the performance and compatibility for Laravel development? do you use Phpstorm, do you have the 8gb ram or the 16gb ram version?

Collapse
 
ibrarturi profile image
Ibrar Hussain

So far I am satisfied with it and found no issues with Laravel development. I have 16GB RAM and use PhpStorm on daily basics.

Collapse
 
jarrodwhitley profile image
Jarrod Whitley

Btw, I get the error "Installer corrupt" when attempting line 2 of the Composer section.

Collapse
 
dkd903 profile image
Debjit Saha

MOre about valet can be found at laravel.com/docs/8.x/valet