I’ve made the deliberate choice to shift away from using containers on my Apple M1 machine for local development, and instead, I’ve embraced Laravel Valet. The decision was driven by several key factors that have greatly improved my development workflow. Firstly, the Apple M1 architecture posed compatibility challenges with some containerization solutions, which led to performance issues and occasional system instability. Secondly, Laravel Valet’s simplicity and ease of setup have streamlined my local development environment, allowing me to focus more on coding and less on managing containers and configurations. Additionally, Valet’s native support for PHP, Nginx, and MySQL has proven to be incredibly efficient, resulting in faster load times and overall improved productivity. This transition has been a game-changer for my development process, enabling me to work more efficiently and effectively on my M1-powered Mac.
How to Install Valet?
Installing Laravel Valet on your macOS system is relatively straightforward, but it does require some prerequisites. Here are the steps to install Laravel Valet:
Prerequisites:
- macOS with Homebrew installed (https://brew.sh/)
- PHP installed (you can use Homebrew for this)
- Composer installed (https://getcomposer.org/)
- MySQL or another database system installed (optional, depending on your project requirements)
Installation Steps:
- Install Homebrew: If you haven’t already, install Homebrew by opening Terminal and running this command:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
- Install PHP: Laravel Valet requires PHP. You can install it using Homebrew:
brew install php
- Install Composer: If you haven’t already installed Composer, you can do so by running this command:
brew install composer
- Install Valet: Use Composer to install Laravel Valet globally:
composer global require laravel/valet
- Add Composer Global Bin Directory to Your Path: Laravel Valet’s executable files are located in Composer’s global bin directory. To make them accessible from anywhere in your terminal, add this directory to your PATH. Add the following line to your shell profile file (usually
~/.zshrc
or~/.bashrc
):export PATH="$PATH:$HOME/.composer/vendor/bin"
- Install Valet: Run this command to install Valet and start its services:
valet install
- Park a Domain: Choose a domain to use for your development projects. For example, let’s use
.test
. To park a domain, run:valet domain test
- Install MySQL with Homebrew:
brew install mysql
- Start MySQL Server:
brew services start mysql
This command will start the MySQL server and ensure that it launches automatically at system startup.
- Secure MySQL Installation:
After installation, you should run the MySQL security script to improve the default security settings:mysql_secure_installation
Follow the prompts to set a root password, remove anonymous users, disallow remote root login, and remove the test database.
- Access MySQL Console: You can access the MySQL console with the following command:
mysql -u root -p
Enter the root password you set during the secure installation process. - Create Databases for Your Drupal Projects: In MySQL, create separate databases for each of your Drupal projects. You can do this from the MySQL console or use a tool like Sequel Pro if you prefer a graphical interface.
Mysql query to create Database by namedrupal10
.create schema drupal10
;
I’m using this for local development, so I use theroot
user while configuring the Drupal instead of creating the specific database user and assigning the permissions to the database. - Create a New Directory for Your Drupal Projects: Create a directory where you’ll store all your Drupal projects. For example, you can create a “drupal-projects” folder in your home directory:
mkdir ~/drupal-projects
- Navigate to the Drupal Projects Directory: Move to the directory where you want to create your Drupal projects:
cd ~/drupal-projects
- Park the Drupal Project to Valet: Add current directory
to Valet so all the applications within this directory will be accessible.valet park
Now, any application you create within your “parked” directory will automatically be served using theĀhttp://<directory-name>.test
- Create a New Drupal Project: Use Composer to create a new Drupal project. Replace
project-name
with your desired project name:composer create-project drupal/recommended-project project-name
- Link the Drupal Project to Valet: Navigate to your new Drupal project’s directory:
cd ~/drupal-projects/project-name
- Access Your Projects: You can now access your Drupal projects in your web browser using the domain you parked earlier. For example, if you parked
.test
, you can access a project athttp://project-name.test
.
- Connect with Database: Now you will the get install page where you can connect your Drupal with the database, using hostname: localhost, username: root, password: <configured in Step 10>, database_name: drupal10/<or whichever you created>.