Thursday, October 2, 2025

How To Deploy Your Laravel App To A Server Using Docker

Maximilian Kürschner
deploy your laravel app to a server using docker

Learn how to deploy your Laravel app to a Server using docker and then make it available with a custom domain using a reverse proxy. This is the next step based on this guide where we learned how to set up a Server and install docker. So follow this guide if you want the same starting point!

The guide will first show you how to do these steps manually. In case you are not that interested in it jump to section 5 where I will show you a tool that does all of these steps automatically for you with basically one command!

Create a Dockerfile for your Laravel app

The first step to deploying your web app to your Server is to create a specific Dockerfile for it. To do so go to the root of your project and create a file Dockerfile. It is the template for your Docker image and contains the steps that are taken to build the image. Every image starts with a base image, then installs the dependencies and finally builds the app that will later be exposed.

FROM php:8.2-apache
RUN apt-get update && apt-get install -y git unzip libpq-dev
RUN docker-php-ext-install pdo pdo_mysql pdo_pgsql
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
RUN a2enmod rewrite
RUN sed -i 's/Listen 80/Listen 8080/' /etc/apache2/ports.conf
RUN sed -i 's/:80/:8080/' /etc/apache2/sites-available/000-default.conf
WORKDIR /var/www/html
COPY . .
RUN composer install --no-dev --optimize-autoloader
RUN chown -R www-data:www-data storage bootstrap/cache
ENV APACHE_DOCUMENT_ROOT=/var/www/html/public
RUN sed -ri -e 's!/var/www/html!${APACHE_DOCUMENT_ROOT}!g' /etc/apache2/sites-available/*.conf
RUN sed -ri -e 's!/var/www/!${APACHE_DOCUMENT_ROOT}!g' /etc/apache2/apache2.conf /etc/apache2/conf-available/*.conf
EXPOSE 8080
CMD ["apache2-foreground"]

In the next step we will use it to create the image.

Build a Laravel app Docker image and upload it to your server

Now that we have the Dockerfile we will run the following command to deploy our web app.

docker build -t laravelappimage:{version}

And then we check if the image can be run locally.

docker run -p 8080:8080 -it laravelappimage:{version}

We should then be able to access our Laravel app under http://localhost:8080.

If everything worked we will upload the image to our server using:

docker save laravelappimage:{version} | ssh user@your-vps-ip 'docker load'

A different way to this process is to upload the image to container registry e.g. githubs container registry and then pull it on the server. I will show it in this guide: urllaravel.

Next we will use the image available on our server to deploy our Laravel app.

Run your app using docker compose

To now deploy our image and make it available for our users we have to create new directory e.g. ~/laravelapp and inside it a new file docker-compose.yml. The docker compose file will define how our container actually runs. Here we will expose port 8080 (the same as in the Dockerfile). In addition we will create a Docker network that we will need for the reverse proxy.

services:
  laravelapp:
    container_name: laravelapp
    image: laravelappimage:{version}
    expose:
	    - '8080'
    networks:
	    - web
    restart: unless-stopped
networks:
  web:
    external: true

After we created the compose file we have to enter the directory and run:

docker compose up -d

With that our Laravel app is running. Next we need to make is accessible.

Make it available using a reverse proxy and a custom domain

Before we start make sure that your domain has an A record pointing to your server.

Next we will create another Docker compose file in another directory: ~/caddy/docker-compose.yml in addition we will create a Caddyfile in the same directory.

The caddyfile contains the configuration of the reverse proxy and basically just points the domain to our container.

laravelapp.com {
    reverse_proxy laravelapp:8080
}

The compose file will create the actual reverse proxy and supply it with configuration.

services:
  caddy:
    container_name: caddy
    image: caddy:latest
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - ./Caddyfile:/etc/caddy/Caddyfile
      - ./data:/data
      - ./config:/config
    networks:
      - web
    restart: unless-stopped

networks:
  web:
    driver: bridge
    external: true

Next we run the following command again:

docker compose up -d

After all our app should now be available under your domain! To update your app you have to follow the same steps from 2. again!

The easy way: quickdeploy

These were a lot of steps with a lot of situations where a small mistake will lead to your app not successfully being deployed. Quickdeploy will help you deploy all your web apps with only one command:

quickdeploy push --domain laravelapp.com

It streamlines the whole process that we just learned about and adds some additional goodies like rolling updates, so your app does not go offline between deployments. If it sounds interesting to you check out the landing page here.

Get Access

Start shipping faster today

Single License

QuickDeploy is yours forever! Updates, fixes, and improvements included.

What's included

  • One time payment
  • CLI tool for Mac, Linux & Windows
  • Free updates included
  • Simple, no vendor lock-in

Pay once, own it forever

Price will increase soon to 19€

10€EUR

Get Access to QuickDeploy
How To Deploy Your Laravel App To A Server Using Docker