In this episode, we go through the process of deploying our Laravel app from local development to a live production server. While the exact steps can vary depending on your hosting and DNS provider, the goal is to show you a real-world example using Laravel Forge to provision the server and Cloudflare to manage DNS and SSL—feel free to swap these with your preferred services, though!
We kick things off with a server and database already set up in Forge, and a domain configured and pointing its nameservers to Cloudflare. Key points here: if you're using Cloudflare, make sure the nameservers match and your domain is added.
Next up is actually creating the site on Forge, pointing it to the correct directory (public
for Laravel), and allowing wildcard subdomains since our app supports user subdomains. We hook up our GitHub repository, configure the deployment script (including running npm install
and npm run build
for our assets), and update our environment variables for production (disabling debug, setting the app URL, and updating database credentials).
Once deployed, we register a user account to test things out, but notice subdomains don't quite work yet—they need SSL! So, we use Let's Encrypt through Forge and set it up for the root and wildcard subdomains. This requires a specific Cloudflare API token with permissions to manage DNS and read the zone.
Finally, we handle the last hurdle: DNS setup for wildcard subdomains. We add an A record in Cloudflare using an asterisk to cover any subdomains, point it to our Forge server's IP, and after a bit of propagation, everything just works—subdomains included. Now the site is live with valid SSL certificates and ready for users.
Even if you're not using Forge or Cloudflare, the big ideas are the same: configure your server, environment, SSL, and DNS properly, and you'll have a multi-subdomain Laravel app up and running in production!