Laravel Docker Apache Configuration using Docker-compose Example - TechvBlogs

Laravel Docker Apache Configuration using Docker-compose Example

Explore seamless Laravel integration with Apache using Docker Compose. Follow our step-by-step example for efficient Dockerized setups. Elevate your development environment effortlessly.

Smit Pipaliya - Author - TechvBlogs
Smit Pipaliya

2 months ago

TechvBlogs - Google News

This comprehensive tutorial illustrates the seamless configuration of Laravel with Docker and Apache. Step-by-step, we'll guide you through creating a docker-compose setup and optimizing the 000-default.conf file for Laravel. If you're seeking a clear example and solution for installing Laravel with Docker and Apache, this user-friendly guide is tailored to simplify the process of configuring Laravel with Docker Compose and Apache.

In this tutorial, we'll walk you through the straightforward process of setting up Docker Compose for your Laravel application. We'll create a default.conf configuration file for Apache, ensuring proper path configuration and permissions. Follow these simple steps to streamline the setup:

Let's embark on a step-by-step journey to set up a Laravel 10 project using Docker Compose. Follow these sequential steps for a smooth and efficient setup process.

Step 1: Install Laravel 10

While this step is optional, if you haven't yet created the Laravel app, feel free to proceed by executing the following command:

composer create-project laravel/laravel example-app

Step 2: Create a Dockerfile

Create a file named 'Dockerfile' at the root of your Laravel project and add the following content:


FROM php:8.2-apache
WORKDIR /var/www/html
RUN apt-get update && apt-get install -y \
    libzip-dev \
    unzip \
    && docker-php-ext-install zip pdo_mysql
COPY . /var/www/html/
RUN chown -R www-data:www-data /var/www/html/storage /var/www/html/bootstrap/cache
RUN chmod -R 775 /var/www/html/storage /var/www/html/bootstrap/cache

Step 3: Create a VirtualHost Configuration

Generate a file named 'default.conf' in the '.docker/apache' directory (create the directory if necessary) and include the following content:


<VirtualHost *:80>
    DocumentRoot /var/www/html/public
    <Directory /var/www/html>
        AllowOverride All
        Require all granted
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

Step 4: Create a docker-compose.yml File

Generate a 'docker-compose.yml' file at the root of your Laravel project, and include the following content:


version: '3'
      context: .
      dockerfile: Dockerfile
    image: my-laravel-app
      - "8080:80"
      - .:/var/www/html
      - ./.docker/apache/default.conf:/etc/apache2/sites-enabled/000-default.conf

Step 5: Build and Run Docker Containers

Execute the following commands to build and run your Docker containers:

docker-compose up -d --build

To verify if your port '8080' is operational, use the following command:

docker-compose ps

Afterwards, open your web browser and navigate to the following URL to confirm whether it is functioning:


Thank you! If you need any more assistance or have further questions, feel free to ask.

Comments (0)


Note: All Input Fields are required.