Setup PHP Laravel Environment with Docker: Apache, Ubuntu, and MongoDB

Introduction

This guide provides a detailed setup for a PHP Laravel environment using Docker, Apache, Ubuntu, and MongoDB. The Docker Compose configuration defines services for the application and MongoDB, allowing for seamless development and testing.

Docker Compose Configuration

services:
  app:
    build:
      context: .
      dockerfile: Dockerfile
    container_name: petra_devs
    ports:
      - "80:80"
      - "443:443"
    extra_hosts:
      - "petradevs.org:127.0.0.1"
    environment:
      - VIRTUAL_HOST=petradevs.org
    restart: unless-stopped
    tty: true
    volumes:
      - ./:/var/www/html/petradevs
      - ./storage/logs:/var/www/html/petradevs/storage/logs
    links:
      - mongodb
    networks:
      - laravel_network

  mongodb:
    image: mongodb/mongodb-community-server:latest
    container_name: mongodb
    restart: unless-stopped
    tty: true
    volumes:
      - mongodb_data:/data/db
    ports:
      - '27017:27017'

volumes:
  mongodb_data:
    driver: local

networks:
  laravel_network:
    driver: bridge

Explanation

The Docker Compose file defines two services: app and mongodb.

Dockerfile Reference

For detailed instructions on setting up the Dockerfile for a PHP development environment with Apache and Ubuntu, refer to the internal link:

Dockerfile Setup: PHP Development Environment with Apache and Ubuntu

Accessing MongoDB Locally

To access the local MongoDB instance from within the Docker container, use the following environment variable:

DB_MONGO_DSN=mongodb://host.docker.internal:27017

This configuration allows the application to connect to the MongoDB instance running on the host machine.

Additional Resources

For more information on using MongoDB with PHP and Laravel, refer to the official MongoDB documentation:

MongoDB PHP Laravel Documentation

Conclusion

This guide covers the setup of a PHP development environment using Docker, including configuration for Apache, Ubuntu, and MongoDB. By following these steps, you can create a robust and isolated development environment.

Published By: Krishanu Jadiya
Updated at: 2024-07-20 00:31:27

Card Image

How to Set Up a Local SSL Certificate on Apache: Step-by-Step Guide

Learn how to set up a local SSL certificate on Apache with this comprehensive step-by-step guide. Secure your local development environment with HTTPS.

Card Image

Latest Features of Coding Technology

Explore the latest features and advancements in coding technology, including new programming languages, frameworks, DevOps tools, AI integration, and more.

Card Image

Understanding Laravel Mix Webpack Configuration: Step-by-Step Guide

Step-by-step explanation of a Laravel Mix Webpack configuration file, including asset management for JavaScript, CSS, and Vue.js support.

Card Image

How Emojis Can Enhance Your Git Commits | Gitmoji Guide

Discover how to enhance your Git commits with emojis. Learn about the best practices for creating informative and visually distinctive commit messages.