DEV Community

Cover image for A Laravel project on your own dev server in 10 minutes
Kim Daniel Geisthardt
Kim Daniel Geisthardt

Posted on Originally published at envbay.com

A Laravel project on your own dev server in 10 minutes

Disclosure first: I run Envbay, a small hosted service for Envoryx. Everything below works on a self-hosted Envoryx too, I just happen to use mine.

Every time I start a Laravel thing for a client I need the same stuff before I can show anything. PHP in the right version. A database. Redis. Somewhere for mail to go that isn't a real inbox. And an https address the client can click without me explaining self-signed certificates.

Doing that by hand on a VPS costs me an afternoon, every time. For a while now I've been using Envoryx for it. It's an open-source tool that treats every environment as a "project" with its own containers and its own address. Here's the way I set up a Laravel project with it, mostly so I have it written down.

What you need

  • An Envoryx instance you can log in to. Self-hosted is fine, install notes are in the repo. If you don't want to run a box, see the end.
  • A browser.
  • For the IDE bit: VS Code with the "Remote - SSH" extension and an SSH key. No key? ssh-keygen -t ed25519 and you have one.

1. New project

Log in, click New project, pick the Laravel template, give it a name. I use shop here because that's what it usually is. The name ends up in the address later, so don't call it test3.

2. Pick the stack

The wizard asks what you want. I take:

  • the PHP version production runs (check first, I've gotten this wrong)
  • Caddy as web server
  • MariaDB
  • and under services Redis and Mailpit

Each of those is its own container inside the project. Nothing is shared with the other projects on the instance, so the next client can be on a different PHP version and nobody cares.

3. Create

Click Create project and wait. Envoryx pulls the PHP image, runs composer create-project and the migrations. On my hosted instance that was a bit over a minute, with composer being the slow part. On your own hardware it depends on your disk and whether the image is cached already.

4. Open it

The project page shows the address. Click it, you get the Laravel welcome page, https, real certificate. On Envbay it looks like https://shop.<you>.envbay.dev, self-hosted it's whatever base domain you gave Envoryx.

That's the part that used to take me the afternoon.

5. Check .env

The template writes the connection values for you. If you import your own repo instead of the template, this is where it usually breaks: your .env still points at 127.0.0.1. It needs to point at the service names inside the project:

DB_CONNECTION=mysql
DB_HOST=database
REDIS_HOST=redis
MAIL_HOST=mailpit
Enter fullscreen mode Exit fullscreen mode

Took me a while to figure that out the first time, so there you go.

6. Mail

Whatever your app sends lands in Mailpit, never with a real person. You open Mailpit from the project's services. Quick way to check from the project terminal:

php artisan tinker --execute="Mail::raw('hello', fn (\$m) => \$m->to('test@example.com')->subject('Mailpit test'));"
Enter fullscreen mode Exit fullscreen mode

Shows up in Mailpit a second later.

7. VS Code over SSH

Envoryx has an SSH gateway, so the IDE talks straight to the project.

  1. In the instance, Settings → SSH keys, paste your public key.
  2. Find the SSH host and port. On Envbay they're in the customer panel, self-hosted they're whatever you exposed for the gateway.
  3. In VS Code: Remote-SSH: Connect to Host…, enter it as an ssh command with the port. User is the project name:
ssh -p <port> shop@ssh.<you>.envbay.dev
Enter fullscreen mode Exit fullscreen mode
  1. Open /var/www/html. That's your Laravel project. Terminal, php artisan, composer, git, all inside the project's container.

The project has to be running or SSH won't connect. If you get Permission denied, either the key isn't under Settings → SSH keys or you typed the wrong user (it has to be the project name). ssh -v tells you which. PhpStorm works the same way through its SSH config.

Where this stops

To be fair about it, this is a dev and staging setup, not production:

  • It's one machine. No load balancing, no HA.
  • Resources are whatever the instance has. Big frontend builds want more than 2 GB.
  • Feature branches as separate environments exist in Envoryx, but each one eats memory like a project does.

If you'd rather not run the server

That's basically why Envbay exists. You get your own Envoryx instance, I keep it updated, addresses, certificates, SSH gateway and backups are already there. It's in beta, it's for dev and staging only, servers are in the EU. There's a free 7-day plan if you want to click through the above without installing anything: envbay.com.

If you self-host Envoryx and have a quicker route to a running Laravel project, tell me in the comments, I'll update this.

Top comments (0)