services:
  web:
    image: php:8.2-apache
    container_name: excellent_blog_web
    ports:
      - "0.0.0.0:8480:80"
    volumes:
      - ./src:/var/www/html
      - ./config/php.ini:/usr/local/etc/php/php.ini
      - ./config/apache.conf:/etc/apache2/sites-available/000-default.conf
    depends_on:
      - db
    environment:
      - MYSQL_HOST=db
      - MYSQL_PORT=3306
      - MYSQL_DATABASE=excellent_blog
      - MYSQL_USER=blog_user
      - MYSQL_PASSWORD=blog_pass
      - GPT_API_KEY=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
    command: >
      bash -c "
      docker-php-ext-install mysqli pdo pdo_mysql &&
      a2enmod rewrite &&
      apache2-foreground
      "

  db:
    image: mysql:8.0
    container_name: excellent_blog_db
    ports:
      - "0.0.0.0:3346:3306"
    environment:
      - MYSQL_ROOT_PASSWORD=root_password
      - MYSQL_DATABASE=excellent_blog
      - MYSQL_USER=blog_user
      - MYSQL_PASSWORD=blog_pass
    volumes:
      - mysql_data:/var/lib/mysql
      - ./config/init.sql:/docker-entrypoint-initdb.d/init.sql
    command: --default-authentication-plugin=mysql_native_password

  phpmyadmin:
    image: phpmyadmin/phpmyadmin:latest
    container_name: excellent_blog_phpmyadmin
    ports:
      - "0.0.0.0:8481:80"
    environment:
      - PMA_HOST=db
      - PMA_PORT=3306
      - PMA_USER=root
      - PMA_PASSWORD=root_password
    depends_on:
      - db

volumes:
  mysql_data: