Set up a blazing fast Magento 2 development environment in less than 10 minutes
Running multiple Magento 2 development environments is hard. You have to check out the code, install Magento and end up with a very slow environment. Have you tried a VM? Too slow! Have your tried the Docker environment? Better, but still painfully slow! So you end up with a local setup and configuring vHosts and all this stuff for every project you are working on. What is the easiest way to set up a blazing fast development environment?
Valet is a minimalistic development environment which runs locally on your Mac. It supports multiple project types like generic PHP, Laravel, Magento 2, Craft CMS, Symfony or just Wordpress.
- Install Laravel Valet via the Official Documentation
- Go to your root project where you store your projects and add it to Valet by typing
valet parkinto your terminal. Valet is now watching all projects in this directory. If you only want to link a single project, go to the root of the project and type
valet link project-name
Now you can access your PHP projects with
project-name.test like magic. (Updated: Former *.dev domains do not work in Google Chrome anymore)
Optional: I’ve created a Valet extension for creating databases with a simple command. I’m using it every time I setup a new project.
Put this file into your
~/.valet/Extensions directory and restart Valet with
valet restart. You can create a new local database with
valet db DB-NAME now.
Install Magento 2 via composer and add the
--use-rewrites=1 flag during the setup! If you don’t do it, Magento adds the
server.php of Valet in your URL and all links are broken.
bin/magento setup:install --admin-firstname=FIRSTNAME --admin-lastname=LASTNAME --firstname.lastname@example.org --admin-user=admin --admin-password='PASSWORD' --base-url='http://YOUR-FOLDER-NAME.dev' --db-name='DB-NAME' --backend-frontname=admin --use-rewrites=1
Bonus: Share your local development environment with a client
Share your local environment with a simple
valet share command. Valet creates a local tunnel via ngrok and gives you http and https URLs for a direct access. Whether you are behind a corporate firewall or not.
Make sure to update your Base URLs in Magento and, as always, clear your cache with
No virtualization anymore! For most shops, this setup is quite reliable for development. Sure, it might not work for an enterprise version with different caching layers and a lot of services, but for most PHP and Magento projects, it works fine — and it’s fast.