Skip to main content
All CollectionsManageCustomize your dating serviceSystem
PHP development environment based on Docker
PHP development environment based on Docker

This guide is tailored for the Dating Pro-based product.

Yanar avatar
Written by Yanar
Updated this week

Requirements

  • Git

  • Docker engine version 19.x or higher


Features and Capabilities

  1. Multiple PHP Versions:

    • PHP 8.0 and PHP 7.4 with a set of commonly used extensions.

  2. Flexibility:

    • Enables using different PHP versions for various web projects.

  3. Pre-configured Tools:

    • Includes a ready-to-use process supervisor.

    • Pre-configured Nginx web server.

  4. Databases:

    • MySQL 5.7

    • MySQL 8

    • PostgreSQL (latest)

    • MongoDB 4.2

    • Redis (latest)

  5. Configuration Flexibility:

    • Environment parameters are set through the .env file.

    • Services can be modified via docker-compose.yml.

  6. Docker Images:

    • Uses official images for all Docker containers.

    • Structured Dockerfile for creating PHP images.

  7. Data Management:

    • Most container directories storing user data and configuration parameters are mounted locally.

  8. Service Isolation:

    • Adheres to the principle that each container should only run one service.


Project Structure

.env-example .gitignore .ssh README.md docker-compose.yml mongo mysql-5.7 mysql-8 nginx php-ini php-workers php-workspace postgres projects redis
  • .env-example: Example file with basic environment settings.

  • .gitignore: Specifies files and directories to be ignored by Git.

  • .ssh: Stores SSH keys.

  • docker-compose.yml: Defines multi-container application rules.

  • Databases:

    • mongo: MongoDB database settings, dumps, and configurations.

    • mysql-5.7 and mysql-8: MySQL database settings, dumps, and logs.

    • postgres: PostgreSQL database settings and dumps.

  • nginx: Stores Nginx configuration and logs.

  • php-ini: Contains PHP configuration files for different versions.

  • php-workers: Stores Supervisor configuration files.

  • projects: Directory for storing web projects accessible to PHP containers.

  • redis: Redis key-value store configuration and data.


Getting Started

  1. Clone the repository:

    git clone git@bitbucket.org:datingpro/pg_docker.git
  2. Update Environment Settings:

    • Copy the .env-example file:

      cp .env-example .env
    • Modify the .env file to suit your requirements.

  3. Clone Web Projects:

    • Clone your web projects into the projects directory.

    • Example:

      • dev.loc: Uses PHP 8.0.

      • prod.loc: Uses PHP 7.4.

  4. Update Nginx Configuration:

    • Modify virtual host settings in ./nginx/conf.d/.

  5. Set Up Hosts File:

    • Map domain names to the local machine’s IP:

      • On Mac/Linux: /etc/hosts

      • On Windows: C:\Windows\System32\drivers\etc\hosts

      127.0.0.1 dev.loc 127.0.0.1 prod.loc
  6. Optional: Add Routing Within Containers:

    • To enable containers to communicate with each other, add extra_hosts in docker-compose.yml:

      extra_hosts: - 'dev.loc:IP_HOST_MACHINE' - 'prod.loc:IP_HOST_MACHINE'
  7. Start the Containers:

    docker-compose build && docker-compose up -d
  8. Install Dependencies:

    • Use Composer or npm to install dependencies for web applications.

    • Example:

      docker exec -it php-8.0 bash composer install
  9. Check Running Containers:

    docker ps

Database Management

MySQL:

  1. Load a dump file:

    docker exec -i mysql mysql --user=root --password=secret --force < databases-dump.sql
  2. Use Percona XtraBackup for hot backups if required.

PostgreSQL:

  1. Restore a database:

    docker exec -i postgres psql --username user_name database_name < /path/to/dump/pgsql-backup.sql

MongoDB:

  1. Restore a dump:

    docker exec -it mongo sh mongorestore -d database_name /dump/databases/database_name

FAQ

How to stop and remove containers?

docker-compose down

How to get detailed information about a container?

docker inspect container_name

How to list all containers?

docker ps -a

How to delete all containers?

docker rm -v $(docker ps -aq)

How to check installed PHP extensions?

docker exec -it php-8.0 php -m

For detailed information and updates, refer to the original documentation or reach out to the support team.

Did this answer your question?