Laravel Docker Apache Configuration using Docker-compose Example
Hi Guys,
This tutorial will provide an example of laravel docker apache configuration. In this article, we will implement a laravel docker 000-default.conf file. If you have a question about install laravel docker with apache example then I will give a simple example with a solution. This example will help you laravel docker compose apache configuration.
In this example, we will simply setup docker-compose for laravel application. we will create apache default.conf configuration file and setup path and permission. You can see the simple steps:
Now, we will start step by step setup laravel 10 project with docker compose.
Step 1: Install Laravel 10
This step is not required; however, if you have not created the laravel app, then you may go ahead and execute the below command:
composer create-project laravel/laravel example-app
Step 2: Create a Dockerfile
Create a file named "Dockerfile" in the root of your Laravel project with the following content:
Dockerfile
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
EXPOSE 80
Step 3: Create a VirtualHost Configuration
Create a file named "default.conf" in the ".docker/apache" directory (you may need to create the .docker/apache directory) with the following content:
.docker/apache/default.conf
<VirtualHost *:80>
DocumentRoot /var/www/html/public
<Directory /var/www/html>
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Step 4: Create a docker-compose.yml File
Create a file named "docker-compose.yml" in the root of your Laravel project with the following content:
docker-compose.yml
version: '3'
services:
web:
build:
context: .
dockerfile: Dockerfile
image: my-laravel-app
ports:
- "8080:80"
volumes:
- .:/var/www/html
- ./.docker/apache/default.conf:/etc/apache2/sites-enabled/000-default.conf
Step 5: Build and Run Docker Containers
Run the following commands to build and run your Docker containers:
docker-compose up -d --build
You can check your port "8080" is running or not by using follow command:
docker-compose ps
Then you can check following url on browser and check it will works:
http://localhost:8080
Output:
I hope it can help you...
Hardik Savani
I'm a full-stack developer, entrepreneur and owner of ItSolutionstuff.com. I live in India and I love to write tutorials and tips that can help to other artisan. I am a big fan of PHP, Laravel, Angular, Vue, Node, Javascript, JQuery, Codeigniter and Bootstrap from the early stage. I believe in Hardworking and Consistency.
We are Recommending you
- Laravel Convert Array to Query String Example
- How to Get Last Executed Query in Laravel 10?
- Laravel Mail Send with PDF Attachment Example
- How to Call Controller Function in Blade Laravel?
- How to Get Online Users in Laravel?
- How to Create and Use Stored Procedure in Laravel?
- Laravel CRUD with Image Upload Tutorial
- Laravel Carbon Subtract Minutes Example
- Laravel Carbon addMinutes() | Laravel Carbon Add Minutes Example
- How to Increase Session Lifetime in Laravel?
- Laravel Export to PDF using Maatwebsite Example