Skip to content

This repo contains a simple Docker setup with minimal configuration and only few files you can drop into many PHP-based projects.

Notifications You must be signed in to change notification settings

Kovah/Docker-Stack

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Docker Stack

PHP 8 MariaDB nginx Redis Laravel ready!

This repo contains a simple Docker setup you can drop into many PHP-based projects without the configuration and tweaking hassle. Find out more about the idea behind this in my blog post.

Basics

The stack consists of four files from those two are configuration files and one is the .env file you can find in many projects.

Directory structure

/
├─ docker
│  ├─ php.ini
│  └─ nginx.conf
├─ // Your other app files
├─ .env
└─ docker-compose.yml

My default setup consists of PHP, MariaDB as a MySQL-compatible database server, nginx and Redis. All services are defined in the docker-compose.yml file.

Part of the docker-compose

# --- PHP
php:
  container_name: "project-php"
  image: bitnami/php-fpm:8.1
  volumes:
    - .:/app:delegated
    - ./docker/php.ini:/opt/bitnami/php/etc/conf.d/php.ini:ro

# --- nginx
nginx:
  container_name: "project-nginx"
  image: bitnami/nginx:1.21
  ports:
    - "127.0.0.1:80:8080"
  depends_on:
    - php
  volumes:
    - .:/app:delegated
    - ./docker/nginx.conf:/opt/bitnami/nginx/conf/server_blocks/site.conf:ro

This is the definition of the PHP and nginx containers. As you can see it runs with PHP 8. The only things it does is to make the project available in the /app directory (the base directory for all Bitnami containers) and apply your custom php.ini.

Current Service Versions

Service Version
PHP 8.1
MariaDB 10.7
nginx 1.21
Redis 6.2

Setup & Configuration

In most cases you only have to change the .env file because it contains variable details about the stack and passwords. The main stack works for all plain PHP projects, but you can easily make it work with Laravel or any CMS by changing the nginx.conf file because each system may has different requirements on the web server configuration.

Installation and usage

  • Copy the main files (everything except /public, /.github and README.md) to your project
  • Make a copy of the .env.example file and name it .env, or copy the needed values to your existing .env file. Laravel users do not have to copy anything.
  • Make sure the current configuration matches your project setup. CMS like Wordpress or Drupal need additional configuration.
  • Replace dockerstack with your own project name in the APP_NAME variable in the .env file.
  • Run docker-compose up -d.

Docker will then download all images and start them up. By default, port 80 on your host machine is bound to nginx, so you should be able to access your app by opening http://localhost in your browser.

The database is accessible from your local machine only via port 3306.


Docker Stack is a project by Kovah | Contributors