Sign inSign up

mouadbourbian/php-mysql-app

By mouadbourbian

Updated over 2 years ago
Archived

Docker image for PHP apps with MySQLi & Composer, serving `info.php` and `db.php` through port 80.

Image
Web servers
Databases & storage
0

88

mouadbourbian/php-mysql-app repository overview

PHP MySQL App Docker Image

This Docker image is designed for hosting PHP applications with Apache and MySQL support, optimized for easy deployment via Docker Compose. It's ideal for developers seeking a streamlined setup process for their PHP applications that require database connectivity.

Key Features

  • PHP 8.0 with Apache: Offers a robust platform for PHP applications, leveraging the latest PHP version and Apache for efficient web serving.
  • MySQL Integration: Equipped with the mysqli PHP extension for direct communication with MySQL databases.
  • Composer Ready: Pre-configured with Composer, facilitating dependency management for PHP projects.
  • Flexible Configuration: Supports environment variable-based configuration for database connections, enhancing security and flexibility.

Deployment with Docker Compose

This image is best utilized within a Docker Compose setup, allowing for simplified orchestration and configuration management. Below is an example docker-compose.yml snippet demonstrating how to deploy the PHP MySQL app alongside a MySQL database service:

version: '3.8'

services:
  db:
    image: mariadb:latest
    container_name: m347-kn04-mariadb
    ports:
      - "3306:3306"
    env_file:
      - .env
    environment:
      MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}
      MYSQL_DATABASE: ${MYSQL_DATABASE}
      MYSQL_USER: ${MYSQL_USER}
      MYSQL_PASSWORD: ${MYSQL_PASSWORD}
    networks:
      default:
        ipv4_address: 172.10.5.2

  web:
    image: mouadbourbian/php-mysql-app:kn04-web
    container_name: m347-kn04-php-mysql-app
    ports:
      - "80:80"
    depends_on:
      - db
    networks:
      default:
        ipv4_address: 172.10.5.3
    env_file:
      - .env
    environment:
      DB_SERVER: ${DB_SERVER}
      MYSQL_DATABASE: ${MYSQL_DATABASE}
      MYSQL_USER: ${MYSQL_USER}
      MYSQL_PASSWORD: ${MYSQL_PASSWORD}
      MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}

networks:
  default:
    driver: bridge
    ipam:
      config:
        - subnet: 172.10.0.0/16
          ip_range: 172.10.5.0/24
          gateway: 172.10.5.254
Template for environment variables

This is a template for the .env file. Please fill it out with your specific details. It's important to note that the user specified here does not have access rights to the database; only the root user has those privileges.

MYSQL_DATABASE= # your_database_name
DB_SERVER= # your_database_server_address
MYSQL_ROOT= # your_root_username
MYSQL_ROOT_PASSWORD= # your_root_password
MYSQL_USER= # your_non_access_user
MYSQL_PASSWORD= # your_non_access_user_password

Getting Started

To deploy the PHP MySQL app using Docker Compose, ensure Docker and Docker Compose are installed on your system. Clone this repository and navigate to the directory containing the Dockerfile and docker-compose.yml.

Run the following commands to start the services:

docker-compose up --build -d

Your PHP application will be accessible at http://localhost:80. Ensure the database service is correctly configured to match your application's requirements.

  • info.php : http://localhost:80/info.php
  • db.php : http://localhost:80/db.php

License

Licensed under the MIT License. See the LICENSE file for full details.

Tag summary

Content type

Image

Digest

sha256:2bda65f6f

Size

170.1 MB

Last updated

over 2 years ago

docker pull mouadbourbian/php-mysql-app:kn04-web