DEV Community

Ngobrolin IT
Ngobrolin IT

Posted on • Edited on

Install Laravel Valet on Linux Ubuntu

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
Enter fullscreen mode Exit fullscreen mode

Then update the source list with the following command

sudo apt update
Enter fullscreen mode Exit fullscreen mode

Install Nginx

Valet uses nginx, so we install nginx first.

sudo apt install nginx
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

Then if you have several versions of PHP installed, and want to change them, use the following command

sudo update-alternatives --config php
Enter fullscreen mode Exit fullscreen mode

Next, to check the PHP version, you can use the following command

php -v
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

Install Valet

Run the following command to add the valet Linux repository to composer

composer global require cpriego/valet-linux
Enter fullscreen mode Exit fullscreen mode

Then run the following command to install valet

valet install
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

Or the following command if you use zsh in your terminal

echo "export PATH=$PATH:$HOME/.config/composer/vendor/bin" >> ~/.zshrc
Enter fullscreen mode Exit fullscreen mode

Valet Linux Ubuntu

Valet Command

There are several valet commands that you can use, such as:

valet park
valet forget
valet link
valet unlink
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

If it says Nginx is stopped… then you need to activate Nginx first

sudo systemctl start nginx
Enter fullscreen mode Exit fullscreen mode

Good luck 🍻

Top comments (0)