How to host a Laravel website on Netlify?
Stefan Bogdanescu
Founder & Senior Architect · 2026-06-29
# How to Host a Laravel Website on Netlify: Bridging Traditional Deployment with Modern JAMstack
Migrating a traditional, full-stack framework like Laravel from a dedicated deployment tool like Laravel Forge to a modern static hosting platform like Netlify presents a unique set of challenges. While Netlify excels at deploying static sites and serverless functions, running a dynamic PHP application requires bridging the gap between Netlify's build environment and the requirements of a typical Laravel setup (Composer dependencies, PHP execution).
This post will explore the feasibility of hosting a full Laravel application on Netlify, address why direct execution of commands like `composer install` is problematic, and outline the most practical architectural solutions for deploying your Laravel application.
## The Challenge: Build Environment Mismatch
The deployment script you provided from Laravel Forge relies on executing shell commands directly within a dedicated server environment where PHP-FPM and system services are already configured. Netlify's primary focus is compiling frontend assets (JavaScript, CSS) and deploying static files, often using Node.js environments for the build process.
Inserting raw Composer or `php artisan migrate` commands directly into Netlifyâs standard "Build Command" input usually fails because:
1. **Environment:** Netlify's build environment is ephemeral and doesn't natively run a full LAMP/LEMP stack required by Laravel.
2. **Execution Context:** Standard build commands are designed for compiling code, not managing application state or running persistent server processes like migrations.
Therefore, attempting to force the traditional Forge workflow directly into Netlifyâs simple build steps is generally not the recommended path for complex PHP applications.
## Recommended Architecture: Decoupling Frontend and Backend
For most modern Laravel deployments aiming for speed and scalability on platforms like Netlify, the best practice is to decouple the frontend assets (which Netlify handles perfectly) from the backend API and application logic (which should reside on a robust server).
### Strategy 1: Static Frontend on Netlify + Dynamic Backend Separately
This is the most robust and maintainable approach. You leverage Netlify's strengths for hosting your public-facing files while keeping the dynamic Laravel application running where it belongs.
1. **Backend Hosting:** Deploy your core Laravel application (API, business logic) to a dedicated environment like a VPS, DigitalOcean droplet, or a managed service like Render or Fly.io. This allows you to run PHP-FPM and manage database migrations as intended.
2. **Frontend Hosting:** Compile your Laravel Blade views into static assets (if necessary) or, more commonly, deploy any pure frontend components (like Vue/React setups if using Laravel as an API backend) directly to Netlify.
If you are building a full Single Page Application (SPA) with Laravel, the build process for the assets would look like this:
```bash
# In your project root before deploying to Netlify
npm install
npm run build # Compiles Vue/React into static files
```
You can then configure Netlify to deploy these compiled static files. This separation ensures you maintain the integrity of your Laravel application structure, which aligns with best practices suggested by the Laravel community on maintaining clean code and architecture.
### Strategy 2: Advanced Deployment using Docker and Netlify Functions (For Serverless PHP)
If you are determined to use Netlify for almost everything, you must containerize your entire environment. This involves creating a custom Docker image that includes PHP, Composer, and the necessary web server setup.
1. **Create a Dockerfile:** Define an image that contains PHP and all dependencies.
2. **Build Locally:** Run `composer install` and any necessary migrations *inside* the container during your local development/testing phase.
3. **Netlify Build Command:** Use the Netlify build command to execute the containerized deployment process. This often involves using a multi-stage build or custom scripts within the CI pipeline to manage the Docker image creation, which is significantly more complex than simply running shell commands.
For this advanced route, you would rely heavily on Netlifyâs ability to run custom build steps, perhaps utilizing services that bridge container builds (like AWS ECS or self-managed Docker runners) rather than Netlify's simple environment constraints for heavy PHP application deployment.
## Conclusion
While the desire to host everything on one platform is understandable, hosting a dynamic PHP framework like Laravel directly and entirely on Netlify is architecturally challenging. For achieving stability, performance, and maintainabilityâespecially when following patterns recommended by the Laravel ecosystemâ**decoupling the static frontend from the dynamic backend remains the superior strategy.** Use Netlify for what it does best: lightning-fast static asset delivery, and use a dedicated server to manage the core Laravel application logic and database interactions.