Ngobrolin IT
Posted on March 18, 2024
Hello, dev.. đź‘‹
If you often develop Laravel applications, you will know Valet. Well, valet is a tool that helps to create local development, but valet only works on Mac OS. So in this tutorial, we will try to use Valet but on Linux.
The Linux I’m currently using is Ubuntu 22.04 LTS, so if your Linux OS is the same or your Linux is another Ubuntu-based Linux, you can follow this tutorial.
The Valet that we will use is Valet Linux which is maintained by cpriego.
Add PPA to Ubuntu
Before starting the installation, we add the PPA repository to our Ubuntu. We will use the PHP and Nginx packages from Ondřej Surý. He is a Debian Developer and voluntarily develops Apache, PHP, and Nginx packages following official updates.
sudo add-apt-repository ppa:ondrej/php
sudo add-apt-repository ppa:ondrej/nginx
Then update the source list with the following command
sudo apt update
Install Nginx
Valet uses nginx, so we install nginx first.
sudo apt install nginx
Once installed, open localhost and it will display the Nginx homepage.
Install PHP
Because we are using Nginx, we will install php-fpm using the following command. By default, it will install the latest version of PHP. We will also install the curl PHP Extension.
sudo apt install php-fpm php-curl php-mysql
You also install a certain version of PHP, for example, version 8.0, adding the version behind PHP.
sudo apt install php8.0-fpm php8.0-curl php8.0-mysql
Then if you have several versions of PHP installed, and want to change them, use the following command
sudo update-alternatives --config php
Next, to check the PHP version, you can use the following command
php -v
Install Composer
To install Composer, you can follow the documentation on the composer website at https://getcomposer.org/download/
Install Valet Requirements
According to valet requirements for Linux Ubuntu, you must install the following tools.
sudo apt-get install network-manager libnss3-tools jq xsel dnsmasq inotify-tools
Install Valet
Run the following command to add the valet Linux repository to composer
composer global require cpriego/valet-linux
Then run the following command to install valet
valet install
If the valet install command is not executed, then you need to run the following command in the terminal
echo "export PATH=$PATH:$HOME/.config/composer/vendor/bin" >> ~/.bashrc
Or the following command if you use zsh in your terminal
echo "export PATH=$PATH:$HOME/.config/composer/vendor/bin" >> ~/.zshrc
Valet Command
There are several valet commands that you can use, such as:
valet park
valet forget
valet link
valet unlink
valet park used to add directories to the valet path so that each folder can be accessed using foldername.test
valet forget reverse valet park to remove the directory from the valet path
valet link to make folders individually accessible with foldername.test
valet unlink reverse valet link to remove the link from valet
Troubleshoot
To find out if valet is running well with the command
valet status
If it says Nginx is stopped… then you need to activate Nginx first
sudo systemctl start nginx
Good luck 🍻
Posted on March 18, 2024
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.