Install Laravel Valet+ on Ubuntu
- Published on
- Reading time
- 3 min read
Set up the local Laravel environment we use: Nginx, PHP 8.2, MySQL, Composer and Valet+ on Ubuntu, plus phpMyAdmin on a secure .test domain.
To get our projects running, we recommend using the same environment we use ourselves: Ubuntu Linux with Laravel Valet+. This guide takes you from a fresh machine to a working local setup with Nginx, PHP 8.2, MySQL, Composer, Valet+ and phpMyAdmin served on a secure .test domain.
Note: this guide was written in October 2023 for PHP 8.2 and the genesisweb/valet-linux-plus package. Newer Ubuntu and PHP releases may need different package versions.
Pick your Linux: BackBox (recommended)
I like to use BackBox Linux because it comes with a lot of tools and supports our environment.
- Download the ISO image from the BackBox link.
- Write it to a USB stick using Rufus.
- Boot your computer from the USB stick and install it.
Install the dependency packages
Open your terminal and start by adding the Nginx and PHP repositories and updating the system:
sudo add-apt-repository -y ppa:nginx/stable
sudo apt install software-properties-common
sudo add-apt-repository ppa:ondrej/php
sudo apt-get update
sudo apt-get upgrade
When it finishes, reboot your computer, then install the packages Valet+ depends on:
sudo apt-get install network-manager libnss3-tools jq xsel
Install PHP and its extensions
Install PHP-FPM first:
sudo apt install php8.2-fpm
Then the CLI and the extensions a Laravel app needs:
sudo apt install php8.2-cli php8.2-common php8.2-curl php8.2-mbstring php8.2-opcache php8.2-readline php8.2-xml php8.2-zip php8.2-mysql php8.2-gd
Install MySQL Server
- Install the server:
sudo apt-get -y install mysql-server
- Run the secure installation script:
sudo mysql_secure_installation
When it asks for the password validation level, choose 0, then use any password, something like 12345678.
- When the installation is finished, open the MySQL console:
sudo mysql
- In the MySQL console, set the root password so apps can log in with it, then reload the privileges and exit:
mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '12345678';
mysql> FLUSH PRIVILEGES;
mysql> exit;
Install Composer
sudo apt install curl
curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/local/bin --filename=composer
Install Valet+
- Install the Valet+ package globally with Composer:
composer global require genesisweb/valet-linux-plus
- Now you need to add Composer's global
bindirectory to yourPATHso thevaletcommand is found:
PATH="$PATH:$HOME/.composer/vendor/bin"
Or, depending on where Composer keeps its global packages, use this one:
PATH="$PATH:$HOME/.config/composer/vendor/bin"
- Now it's easy to install Valet:
valet install
It will ask you for a password. Enter 12345678, the MySQL password you set earlier.
Install phpMyAdmin
With Valet installed, let's set up phpMyAdmin and serve it on a .test domain.
- Create a folder for your sites in your home directory
~:
cd ~
mkdir Sites
cd Sites
- From inside
Sites, park the directory so it becomes the home of your projects:
valet park
Every project in this directory is now served automatically on a .test domain.
-
Download phpMyAdmin from phpmyadmin.net, unzip it inside the
Sitesdirectory and rename the folder toPHPMyAdmin. -
Go inside the folder, copy the sample config and open it:
cp config.sample.inc.php config.inc.php
nano config.inc.php
Note: the original post copied the file to config.sample.php, which phpMyAdmin does not read. phpMyAdmin loads config.inc.php, so that name is used here.
- Change the
blowfish_secretline to:
$cfg['blowfish_secret'] = 'YK07LhNSe50vrj,HwBfb.l3gpbv;u8b7';
- Press
CTRL + X, answerYto save, then use Valet to link phpMyAdmin, secure it with SSL, and open it:
valet link
valet secure
valet open
phpMyAdmin is now running. Log in with root as the user and the MySQL password you created.
Wrapping up
You now have the environment we use for our projects: Nginx and PHP 8.2 managed by Valet+, MySQL with a root password your apps can use, Composer, and phpMyAdmin on a secure .test domain. Put any new project in ~/Sites and Valet serves it straight away.