DEV Community

Callum
Callum

Posted on

Setting up PHP 8.2 + Laravel 11 dev environment on Multipass

Setting up the dev box using Multipass on your machine

  1. Install Multipass from https://multipass.run
  2. On Initial run of multipass it will setup the primary box, just let it and close it once it is done
  3. run multipass launch -c 2 -d 10G -m 2G -name PHP8.2Laravel -v to setup ubuntu VM for dev
    1. This will create a VM called PHP8.2Laravelwith 2GB’s of RAM and 2 CPU Cores as well as 10GB space
  4. Next we need to open the box with multipass shell PHP8.2Laravel in your terminal
  5. Lets do a Quick update and upgrade on the Ubuntu OS in the box : sudo apt update && sudo apt upgrade -y
  6. add your SSH keys to ~/.ssh/authorized_keys
  7. close the shell in windows PowerShell terminal run multipass list

    1. you should see something like this:

    PHP8.2Laravel Running 172.29.84.17 Ubuntu 22.04 LTS

  8. Copy the IP address (yours should be different to mine)

Getting VS Code to connect to PHP8.2Laravel VM

  1. Open VS Code, install the extension “Remote - SSH”
  2. Once installed press Ctrl + Shift + P and type add ssh
  3. this should show you an option to Add new SSH host
  4. In the prompt you will add the following: ssh ubuntu@[your IP address from above ]
  5. Once the setup is complete, click connect in the bottom right hand corner
    1. follow the prompts to say that you are sshing into a Linux machine etc…
  6. 🥳 You should now be in the PHP8.2Laravel VM with VS Code

Installing PHP(8.2) and composer

Please use the VS Code terminal from this step onwards.

We need to add a PPA to install the latest version of PHP as of this post if is 8.3

Install the tools needed to install a PPA:
sudo apt install software-properties-common ca-certificates lsb-release

Add the PPA (this is the Debian maintainers PPA so we can trust it)
LC_ALL=C.UTF-8 sudo add-apt-repository ppa:ondrej/php

Now let us install PHP, common libs, apache2 as well as composer the PHP package manager sudo apt-get install -y php8.2 php8.2-cli php8.2-common php8.2-mysql php8.2-sqlite3 php8.2-zip php8.2-gd php8.2-mbstring php8.2-curl php8.2-xml php8.2-bcmath composer

After all of this we can run composer-V and we should see the PHP version as well as the Composer version, the PHP version should be 8.2.xx

If you open a browser and type the boxes IP address you should see an apache2 welcome screen 🥂

Setting up a Laravel(11) project

This is the easy part simply run composer create-project laravel/laravel [your-app-name]

Once that is done in the VS Code terminal type code ./[your-app-name] and a new window should open with your project in it 👍

VS Code Magic

  1. Install PHP Extension Pack from VS Code extensions this will allow you to have intellisense over your codebase (it will take a few minutes after to index the project)
  2. To run your project type php artisan serve into the VS Code terminal and you should see : INFO Server running on [[http://127.0.0.1:8000](http://127.0.0.1:8000/)].
    1. If you Ctrl Click on the Localhost IP address VS code will port forward :8000 to your local machine form the Ubuntu VM and open it in a web browser for you

Happy hacking! 🥂

Top comments (0)