A blog probably of interest only to nerds by John Morton.


A Checklist When Transitioning from MAMP to Valet

I have used MAMP for local development for a long time. Several people I know through the Craft CMS Slack group have professed the benefits of Laravel Valet so I decided to give it a spin as an alternative to MAMP.

When it comes to Craft CMS there is a built-in driver that allows Valet to serve a Craft site without any additional configuration. You just place your Craft site in the appropriate directory, set up your database connection, and it just works.

There is a reason for this post though. I did encounter an issue with transitioning a site from MAMP to Valet.

I have typically used a directory I’ve named "public" as my public-facing directory on Craft sites. In Craft 2, naming that directory "public" was the default. In the upgrade to Craft 3 the default public facing directory is no longer "public"; it has been changed to "web" instead. Out of familiarity I have kept my Craft 3 sites using "public" as my public-facing directory. The issue is that Laravel Valet expectes "web" and not "public" and will throw an error if you don’t follow the default naming convension.

You could simply write a custom Valet driver to specify your choice of names but I didn’t want to do this. (If you’re interested in doing this, check out this Craft3ValetDriver.php Gist by Chris Mousdale.)

If the Craft 3 default is changing to "web" I wanted to change that as well in my working environment.

The problem this presented though was that it’s more than simply changing the name of one directory. That is only the first step. This post is really about what else you need to do to make this change cascade throughout the rest of your workflow.

Things to consider about changing. #

In addition to changing the name of your public-facing directory for Valet, there are some other places you need to check as well.

  1. Have you referenced anything in your .gitignore file that is referencing "public" that you need to change to "web"?
  2. In my case I had 2 external servers, a staging server and a production server. Both of these servers had to be reconfigured to serve public-facing files from the new "web" directory instead of "public". If you push your new local code to your servers, they need to look in the correct "web" directory too.
  3. If you use any scripts (like these) to automate the backup of assets on your Craft site they are most likely using your public-facing directory name. You need to update these as well.

With those things changed, I was all set. This site’s local dev environment is now using Laravel Valet.