Deploy a PHP Web App with Laravel and Docker

hoangit

David Nguyen

Posted on June 14, 2023

Deploy a PHP Web App with Laravel and Docker

Laravel is one of the most popular web frameworks for PHP and for good reason. It comes bundled with most common web app needs, including authentication, authorization, localization, and support for multiple database backends including PostgreSQL.

In this guide, were going to deploy a simple Laravel 10x web app using Renders native PostgreSQL and Docker support.

Lets get started!

  1. Create a new PostgreSQL database on Render and copy the internal DB URL to use below.

  2. Fork hoangsvit/laravel-10x-docker and create a new Web Service on Render, giving Render permission to access your forked repo.

Select Docker for the runtime, and add the following environment variables under the Advanced section:

KEY VALUE
DATABASE_URL The internal database URL for the database you created above.
DB_CONNECTION pgsql
APP_KEY Copy the output of php artisan key:generate --show

Thats it! Your Laravel web app will be live on your Render URL as soon as the build finishes. You can test it out by registering and logging in.

Modifying an Existing Laravel App for Render

The commit history of our sample repo is useful in understanding the modifications needed for an existing Laravel app.

If you havent already, make sure to run php artisan make:auth to generate authentication scaffolding for your app.

  1. Force HTTPS on all assets served by Laravel to avoid mixed content warnings in the browser. Render already manages and terminates TLS certificates for you, but Laravels asset helper needs to be configured to serve everything over TLS. You can do this by following the changes in Force HTTPS for Laravel.

  2. Configure your repo to deploy Laravel using Docker and NGINX. Were building on the nginx-php-fpm Docker image as shown here, and adding php-fpm configuration for NGINX to tie everything together.

  3. Finally, add a deploy script that will be run when your PHP app starts up.

You should now be able to deploy your existing Laravel app on Render.

💖 💪 🙅 🚩
hoangit
David Nguyen

Posted on June 14, 2023

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related