Using Caddy to deploy Laravel apps with zero downtime

Caddy 2 is a popular web server written in Go. It is known for its simplicity and ease of use. It is also very easy to configure and deploy. In this tutorial, we will see how Eddy Server Management can help you deploy Laravel apps with zero downtime.

Setting up the server

Once you've created an account, you can provision a server at your preferred cloud provider. While you can use any cloud provider, Eddy has integrations with DigitalOcean and HetznerCloud. Simply log in to your cloud provider, create a new API token, and add it to Eddy. Now you can provision a new server with a click of a button without having to log in to your cloud provider.

Eddy will provision Ubuntu 22.04 with Caddy 2. It also installs other software like PHP, MySQL, Redis, and Node. Of course, it makes also sure that the server is secure and up-to-date, and that you can connect to it via SSH.

Server Provisioning Eddy

Deploying a Laravel app

Once the server is provisioned, you can deploy your Laravel app. Eddy supports deploying apps from GitHub or any other Git repository. When you connect your GitHub account, you can select the repository and branch you want to deploy. You can select a PHP version per site. By default, it will select Laravel as the site type, but you can also select Generic, Static or WordPress. The Laravel site type makes sure the storage directory is shared between releases, and that the .env file is symlinked. It also comes with a default script to compile assets, cache configuration, route and view files, and run database migrations.

Site Deployment with Eddy

How it works

When you choose to use Eddy's zero-downtime deployment, it will create a directory structure on the server like this:


Every time you deploy a new release, it will create a new directory in the releases directory. It will then run the deployment script in the new release directory for things like installing dependencies and compiling assets. If the deployment is successful, it will update the current symlink to point to the new release directory. Eddy uses Caddy's php_fastcgi directive to proxy requests to the PHP-FPM process. With the resolve_root_symlink option, Caddy will resolve to the current symlink. This way, you can deploy new releases without having to restart Caddy.