How to host a Laravel website on Netlify?

mesqueeb picture mesqueeb · Jun 2, 2018 · Viewed 8.7k times · Source

I'm trying to host my Laravel website on Netlify.

I was originally using Laravel Forge to deploy and host my website. The deploy script that was used on Laravel forge was:

cd /home/forge/lucaban.com
git pull origin master
composer install --no-interaction --prefer-dist --optimize-autoloader
echo "" | sudo -S service php7.1-fpm reload

if [ -f artisan ]
then
    php artisan migrate --force
fi

Is there any way I can host the website on Netlify and run these composer commands? Because I think I can only insert NodeJS commands into the build command input.

I have not yet succeeded getting my website live...

Answer

fool picture fool · Jun 2, 2018

You cannot host a laravel site on Netlify. Check out https://jamstack.org for more about the philosophy behind Netlify's hosting service.

While you can use php in the build environment (composer install should work, though you may want to set PHP_VERSION to 7.2 since the default is 5.6), the build process is intended to create static output files - html, css, js, images, etc - which Netlify can then serve from its CDN without running any more code on the server side. While the comparison is not quite perfect, imagine that the output from your build (limited to 15 minutes and no incoming network connections) is a bunch of files, which are stored on S3 and served as-is. So if you end up with file.php - Netlify would show, not run, the code in the file.

You cannot host a laravel, wordpress, drupal, magento, etc site on Netlify, though it is Netlify and the JAMstack movement's assertion that you don't need a legacy website that runs code at every visit to run much of the web and that there is great value in reducing the dynamic portions of a website to small services, such as form-handling or lambda functions. Here's a case study on a customer who migrated their site from wordpress to Netlify and includes authentication, comments, and e-commerce: https://www.netlify.com/blog/2017/03/16/smashing-magazine-just-got-10x-faster/