In my previous post, I wrote about how to use Virtual Host in MacOS. Today, I will try to make your life easier who uses laravel and want to implement a virtual host. In this tutorial, I would love to show you a practical introduction to Laravel Valet. Let's deep driving into it.
Imagine that, you have a Laravel project on MacOS, now you want to use a virtual host for the local development for accessing
anything.test, instead of http://127.0.0.1. In that case, laravel brings valet for you our of the box.
I assume you have a fresh machine. You can skip any step if you feel that you have already.
You can follow official docs or use as follow-
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
brew install php
You can install database as you wish.
brew install [email protected]
Check more in the official docs.
brew install mariadb
Now run the following command-
sudo mysql -u root mysql> USE mysql; mysql> SELECT User, Host, plugin FROM mysql.user;
You may see something like this-
+------------------+-----------------------+ | User | plugin | +------------------+-----------------------+ | root | auth_socket | | mysql.sys | mysql_native_password | | debian-sys-maint | mysql_native_password | +------------------+-----------------------+
As you can see in the query, the root user is using the auth_socket plugin.
Run this command and reset the password:
ALTER USER 'root'@'localhost' IDENTIFIED BY 'root';
Now your mySQL login password is: root.
Download composer from this link: https://getcomposer.org/installer
Then, Rename it composer.phar
Try with this command-
Then move it to the composer directory by the following command-
mv composer.phar /usr/local/bin/composer
Run this command to install valet globally-
composer global require laravel/valet
Now run this command to install valet-
To park your whole coding directory or any specific directory, you just go to the directory and run the following command. For example, in my case, I put all of my coding projects into
/Users/username/desktop/code, so I will go to the
code folder then run the following command-
Once you parked successfully, all of your project inside the folder will be accessible via
.test domain. For example, I have the following projects inside the
code - project1 - project2 - project2
Now, I just go to the browser and run http://project1.test where I should able to see the content of the
It's cool, right?
I really love this feature. I like it.
You can even use
https in your local project. To make it secure, you just need to run
valet secure your-project-folder. For example, in my case, I will go to
code and want to make secure
project1, so I will run the following command.
valet secure project1
Even if you want, you can unsecure also. To unsecure your project, you can try as following-
valet unsecure project1
By default, Valet serves your projects using the
.test TLD. If you'd like to use another domain, you can do so using the
valet tld tld-name command.
For example, if you'd like to use
.app instead of
valet tld app and Valet will start serving your projects at
By default laravel valet use
folder name as the default domain name. To change the default domain, just go to the parked folder and run
valet link your-desire-domain. For example, in my case, instead of
project1 I want to use
learning.test. So I will cd to
/code folder and run the following command-
valet link learning
Now, I can go to http://learning.test which will be opening the
valet forget Run this command from a "parked" directory to remove it from the parked directory list.
valet log View a list of logs which are written by Valet's services.
valet paths View all of your "parked" paths.
valet restart Restart the Valet daemon.
valet start Start the Valet daemon.
valet stop Stop the Valet daemon.
valet trust Add sudoers files for Brew and Valet to allow Valet commands to be run without prompting for passwords.
valet uninstall Uninstall Valet: Shows instructions for manual uninstall; or pass the
--force parameter to aggressively delete all of Valet.
valet links See the list of the linked project
valet unlink SITENAME If you want to unlink any site from the valet, you can try this.
Hope this post helps you.
Thanks for reading.
Hello. I’m Thouhedul Islam. Some people also know me as Suchi.
At night I love to solve problems for the community. I love to be active at Laracasts.