### Initial Server Setup with Docker Compose Source: https://context7.com/bitrix-docker/server/llms.txt Clones the Bitrix Docker repository, configures the main environment file (.env), initializes Let's Encrypt storage, and starts all common services using Docker Compose. Requires Git, Docker, and Docker Compose. ```bash # Clone repository to server mkdir -p /srv/bitrix-server/ && cd /srv/bitrix-server/ git clone git@gitlab.com:bitrix-docker/server.git . # Create environment configuration from template cp .env.local.example .env # Edit configuration (key variables shown below) nano .env ``` ```ini # .env - Main server configuration COMPOSE_PROJECT_NAME=bitrix-common COMPOSE_FILE=docker-compose/docker-compose.yml:docker-compose/traefik.yml:docker-compose/grafana.yml:docker-compose/errors.yml:docker-compose/mysql.yml:docker-compose/mysql-adminer.yml:docker-compose/mailpit.yml:docker-compose/sphinx.yml # Main domain for system services (traefik.MAIN_HOST, adminer.MAIN_HOST, etc.) MAIN_HOST=bitrix.local # Database configuration MYSQL_IMAGE=mariadb:10.11 MYSQL_ROOT_PASSWORD=your_secure_password_here # SSL - use letsEncrypt for production, empty for local dev TRAEFIK_CERT_RESOLVER= TRAEFIK_CERTIFICATESRESOLVERS_LETSENCRYPT_ACME_EMAIL=admin@example.com # Basic auth for Traefik dashboard (generate with: echo $(htpasswd -nB admin) | sed -e s/\$/\$\$/g) TRAEFIK_BASIC_AUTH_USERS=admin:$$apr1$$vH.i1FEf$$V0VSouTyT6NuN2OE2KiI21 ``` ```bash # Initialize Let's Encrypt certificate storage echo "{}" > data/traefik/letsencrypt/acme.json && chmod 600 data/traefik/letsencrypt/acme.json # Start all common services docker compose up -d # Verify services are running docker compose ps # Expected output: traefik, db, grafana, loki, promtail, sphinx, mailpit, adminer containers running ``` -------------------------------- ### Creating a New Bitrix Site with Docker Compose Source: https://context7.com/bitrix-docker/server/llms.txt Guides through creating a new Bitrix site by copying a distribution template, configuring its specific environment file (.env), setting execute permissions, and starting the site's containers. Includes instructions for updating the hosts file and completing the Bitrix installation. ```bash # Create new site from template (replace test.example.com with your domain) cp -r bitrix-distr/ sites/test.example.com cd sites/test.example.com # Configure site environment cp .env.local.example .env nano .env ``` ```ini # sites/test.example.com/.env - Site configuration COMPOSE_PROJECT_NAME=test-example-com COMPOSE_COMMON_PROJECT_NAME=bitrix-common COMPOSE_FILE=docker-compose.yml # Database (created automatically on first run) DBHost=db DBName=testexamplecom DBLogin=root DBPassword=your_secure_password_here # Domain settings PROJECT_HOST=test.example.local PROJECT_DOMAIN=test.example.com # PHP version: 7.3, 7.4, 8.0, 8.1, 8.2, 8.3, 8.4 PHP_VERSION=8.4 # Environment: dev or prod PHP_ENV=dev # Timezone SERVER_TIMEZONE=Europe/Moscow PHP_TIMEZONE=Europe/Moscow # SSL resolver (letsEncrypt for production) PROJECT_CERT_RESOLVER= # Middlewares for redirects PROJECT_SSL_MIDDLEWARES=redirect-to-non-www@file,trim-index@file PROJECT_MIDDLEWARES=redirect-to-non-www-http@file,trim-index@file ``` ```bash # Set execute permission for entrypoint script chmod +x docker-entrypoint.sh # Start site containers docker compose up -d # Add local domain to hosts file (for local development) echo "127.0.0.1 test.example.local www.test.example.local" | sudo tee -a /etc/hosts # Access site in browser and complete Bitrix installation wizard # Database settings during installation: # Server: db # User: root # Password: (from MYSQL_ROOT_PASSWORD in main .env) # Database: testexamplecom ``` -------------------------------- ### MSMTP Configuration for Email Sending Source: https://context7.com/bitrix-docker/server/llms.txt This is an example MSMTP configuration file (`msmtprc`) that sets up an account for sending emails, specifically configured for Gmail. It includes authentication, TLS settings, and specifies the default account. ```conf # config/msmtp/msmtprc - MSMTP configuration defaults auth on tls on tls_trust_file /etc/ssl/certs/ca-certificates.crt logfile /var/log/msmtp.log account gmail host smtp.gmail.com port 587 from your-email@gmail.com user your-email@gmail.com password your-app-password account default : gmail ``` -------------------------------- ### Configure Multi-Site with Shared Core via Docker Compose Source: https://context7.com/bitrix-docker/server/llms.txt This configuration demonstrates how to set up multiple Bitrix sites sharing a single core installation using Docker Compose. It involves defining shared volumes in the `docker-compose.yml` file and creating symbolic links within the PHP container. ```yaml # sites/secondary-site.com/docker-compose.yml # Add volume mounts to share core from main site (main.ru) services: nginx: # ... other settings ... volumes: - ./config/nginx/default.conf:/etc/nginx/conf.d/default.conf:ro - &www-volume ./:/var/www:cached - &bitrix-volume ./../main.ru/www/bitrix:/var/main.ru/bitrix:cached - &upload-volume ./../main.ru/www/upload:/var/main.ru/upload:cached - &images-volume ./../main.ru/www/images:/var/main.ru/images:cached php-fpm: # ... other settings ... volumes: - *www-volume - *bitrix-volume - *upload-volume - *images-volume ``` -------------------------------- ### Configure Custom SSL Certificates with Traefik Source: https://context7.com/bitrix-docker/server/llms.txt This guide explains how to configure custom SSL certificates for a Bitrix Docker server using Traefik. It involves disabling Let's Encrypt, copying certificate files, and creating a `certificates.yml` configuration file. ```bash # For custom certificates, disable Let's Encrypt resolver # Set PROJECT_CERT_RESOLVER= (empty) in .env # Copy certificates to data folder cp your-cert.crt data/traefik/certs/ cp your-cert.key data/traefik/certs/ # Create certificates configuration cp config/traefik/dynamic/certificates.yml.example config/traefik/dynamic/certificates.yml ``` -------------------------------- ### Update Site .env and Restart Docker Compose Source: https://context7.com/bitrix-docker/server/llms.txt Updates the .env file with new database credentials and restarts the Docker Compose services to apply the changes. This is a common first step after initial setup or when credentials need to be changed. ```bash # Update site .env with new credentials DBLogin=siteuser DBPassword=secure_password_here # Restart site to apply new credentials docker compose up -d ``` -------------------------------- ### Enable Let's Encrypt SSL with Traefik Source: https://context7.com/bitrix-docker/server/llms.txt This configuration enables automatic SSL certificate generation using Let's Encrypt with Traefik. It involves setting environment variables in the `.env` files for both main services and individual projects, and configuring redirect middlewares. ```ini # .env - Enable Let's Encrypt for main services TRAEFIK_CERT_RESOLVER=letsEncrypt TRAEFIK_CERTIFICATESRESOLVERS_LETSENCRYPT_ACME_EMAIL=admin@example.com # Redirect middlewares for HTTPS TRAEFIK_SSL_MIDDLEWARES=redirect-to-non-www@file,trim-index@file TRAEFIK_MIDDLEWARES=redirect-to-https@file,redirect-to-non-www-http@file,trim-index@file ``` ```ini # sites/example.com/.env - Enable Let's Encrypt for site PROJECT_CERT_RESOLVER=letsEncrypt PROJECT_SSL_MIDDLEWARES=redirect-to-non-www@file,trim-index@file PROJECT_MIDDLEWARES=redirect-to-https@file,redirect-to-non-www-http@file,trim-index@file ``` -------------------------------- ### Create Symlinks for Multi-Site Core Sharing Source: https://context7.com/bitrix-docker/server/llms.txt This snippet details the process of creating symbolic links inside a PHP container to share the Bitrix core from a main site to a secondary site. It also includes optional steps for creating host symlinks for IDE access. ```bash # Create symlinks inside the PHP container cd sites/secondary-site.com docker compose exec php-fpm sh # Inside container - create symlinks to main site ln -s /var/main.ru/bitrix/ /var/www/www/bitrix ln -s /var/main.ru/upload/ /var/www/www/upload ln -s /var/main.ru/images/ /var/www/www/images exit # Create symlinks on host for IDE access (optional) sudo ln -s /srv/bitrix-server/sites/main.ru/www /var/main.ru ``` -------------------------------- ### Switch Mail Service from Mailpit to MSMTP Source: https://context7.com/bitrix-docker/server/llms.txt This snippet shows the steps to switch the mail handling service from Mailpit (default for development) to MSMTP (for production). It involves disabling the Mailpit configuration and enabling the MSMTP configuration files for PHP-FPM. ```bash # Mailpit is enabled by default for development # Access web interface at: http://mailer.bitrix.local # Switch from Mailpit to MSMTP for production: # 1. Disable Mailpit mv sites/example.com/config/php-fpm/dev/mailer.ini sites/example.com/config/php-fpm/dev/mailer.ini.disabled # 2. Enable MSMTP mv sites/example.com/config/php-fpm/prod/msmtp.ini.disabled sites/example.com/config/php-fpm/prod/msmtp.ini ``` -------------------------------- ### View Docker Container Logs Source: https://context7.com/bitrix-docker/server/llms.txt This snippet shows how to view logs for specific Docker containers, such as Traefik, PHP-FPM, and Nginx. The `-f` flag allows for real-time log streaming, which is useful for troubleshooting. ```bash # View logs for troubleshooting docker compose logs -f traefik docker compose logs -f php-fpm docker compose logs -f nginx ``` -------------------------------- ### Generate Self-Signed Certificate for Local Testing Source: https://context7.com/bitrix-docker/server/llms.txt This bash command generates a self-signed SSL certificate for local testing purposes. It creates a private key and a certificate valid for 365 days, saving them to the specified data directory. ```bash # Generate self-signed certificate for local testing sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 \ -keyout data/traefik/certs/local.key \ -out data/traefik/certs/local.crt ``` -------------------------------- ### Set MSMTP Account and PHP Environment Source: https://context7.com/bitrix-docker/server/llms.txt This `.env` file configuration specifies the active MSMTP account to be used and sets the PHP environment to production. This is necessary when using MSMTP for sending emails in a production environment. ```ini # sites/example.com/.env - Set MSMTP account MSMTP_ACCOUNT=gmail PHP_ENV=prod ``` -------------------------------- ### Configure Sphinx for Full-Text Search Source: https://context7.com/bitrix-docker/server/llms.txt Enables full-text search with morphology support by configuring Sphinx for your site. This involves copying and editing a Sphinx configuration file, creating a synonyms file, restarting the Sphinx container, and configuring Bitrix admin settings. ```bash # Copy Sphinx config template (replace example-com with domain using dashes) cp config/sphinx/example.conf config/sphinx/sites/example-com.conf # Edit the configuration nano config/sphinx/sites/example-com.conf ``` ```conf # config/sphinx/sites/example-com.conf # Replace 'examplecom' with your site identifier (no special chars) # Replace 'example-com' with your domain using dashes index examplecom { type = rt path = /var/lib/sphinx/index/examplecom/ morphology = stem_enru min_word_len = 2 min_infix_len = 2 wordforms = /var/lib/sphinx/synonyms/example-com.txt charset_table = 0..9, A..Z->a..z, _, a..z, \ U+410..U+42F->U+430..U+44F, U+430..U+44F, U+401->U+0435, U+451->U+0435 rt_field = title rt_field = body rt_attr_uint = item_id rt_attr_uint = site_id rt_attr_uint = module_id rt_attr_uint = param1 rt_attr_uint = param2 rt_attr_timestamp = date_change rt_attr_timestamp = date_from rt_attr_timestamp = date_to } ``` ```bash # Create synonyms file for your site cp data/sphinx/synonyms/example.txt data/sphinx/synonyms/example-com.txt nano data/sphinx/synonyms/example-com.txt ``` ```text # data/sphinx/synonyms/example-com.txt # Format: word => replacement # or: word1, word2, word3 (synonyms) notebook, laptop phone, smartphone, mobile ``` ```bash # Restart sphinx container to load new config docker compose restart sphinx # Configure Sphinx in Bitrix admin panel at /bitrix/admin/settings.php?mid=search # Settings: # Use morphology: Yes # Full-text search: Sphinx # Connection string (MySQL protocol): sphinx:9306 # Index identifier: examplecom # Run full reindex at /bitrix/admin/search_reindex.php ``` -------------------------------- ### Configure Xdebug for PHP Debugging Source: https://context7.com/bitrix-docker/server/llms.txt Enables PHP debugging for local development by configuring Xdebug. This involves uncommenting `extra_hosts` in the `docker-compose.yml` for Linux systems and ensuring the Xdebug configuration file is correctly set up with the client host and port. ```yaml # sites/example.com/docker-compose.yml # Uncomment extra_hosts for Linux systems (not needed on macOS/Windows) services: php-fpm: # ... other settings ... extra_hosts: - "host.docker.internal:host-gateway" ``` ```ini ; sites/example.com/config/php-fpm/dev/xdebug.ini ; Default Xdebug configuration (already included) [xdebug] xdebug.mode=debug xdebug.client_host=host.docker.internal xdebug.client_port=9003 xdebug.start_with_request=yes xdebug.idekey=PHPSTORM ``` -------------------------------- ### MySQL User Management for Bitrix Sites Source: https://context7.com/bitrix-docker/server/llms.txt Demonstrates how to create dedicated MySQL users and grant them specific privileges for individual Bitrix sites, enhancing security by avoiding the use of root credentials. This can be executed via the Bitrix admin SQL panel or a MySQL client connected to the database container. ```sql -- Execute in Bitrix admin panel at /bitrix/admin/sql.php -- or connect via MySQL client to db container -- Create new user for site CREATE USER 'siteuser' IDENTIFIED BY 'secure_password_here'; -- Grant permissions only to site's database GRANT ALL PRIVILEGES ON testexamplecom.* TO 'siteuser'; FLUSH PRIVILEGES; -- Verify user was created SELECT User, Host FROM mysql.user WHERE User = 'siteuser'; ``` -------------------------------- ### Perform Zero-Downtime Docker Updates Source: https://context7.com/bitrix-docker/server/llms.txt These bash commands outline the process for updating the Dockerized Bitrix server. They include pulling the latest code, updating Docker images, and recreating containers with minimal downtime. Commands are provided for updating common services from the project root and individual sites from their respective directories. ```bash # Update common services (run from project root) git pull \ && docker compose pull \ && docker compose up --force-recreate --remove-orphans --build -d \ && docker image prune -f # Update individual site (run from site folder) cd sites/example.com docker compose pull \ && docker compose up --force-recreate --remove-orphans --build -d ``` -------------------------------- ### Enable/Disable Xdebug in PHP-FPM Source: https://context7.com/bitrix-docker/server/llms.txt This snippet shows how to enable or disable the Xdebug extension for PHP-FPM by renaming configuration files. It requires access to the server's file system and the ability to restart the PHP container. ```bash # Enable Xdebug (rename .disabled to .ini) mv sites/example.com/config/php-fpm/dev/xdebug.ini.disabled sites/example.com/config/php-fpm/dev/xdebug.ini # Disable Xdebug (rename .ini to .disabled) mv sites/example.com/config/php-fpm/dev/xdebug.ini sites/example.com/config/php-fpm/dev/xdebug.ini.disabled # Restart PHP container to apply changes cd sites/example.com && docker compose restart php-fpm ``` -------------------------------- ### Access MySQL Console Source: https://context7.com/bitrix-docker/server/llms.txt This command allows direct access to the MySQL database console running within the Docker container. It requires the root username and password for authentication. ```bash # Access MySQL console docker compose exec db mysql -u root -p ``` -------------------------------- ### Access PHP Container Shell Source: https://context7.com/bitrix-docker/server/llms.txt This command provides access to the PHP-FPM container's shell. This is useful for debugging issues within the containerized PHP environment, such as checking file permissions or running commands. ```bash # Access PHP container shell for debugging docker compose exec php-fpm sh ``` -------------------------------- ### Traefik Custom SSL Certificate Configuration Source: https://context7.com/bitrix-docker/server/llms.txt This YAML file defines the configuration for custom SSL certificates used by Traefik. It specifies the paths to the certificate and key files within the container's volume mounts. ```yaml # config/traefik/dynamic/certificates.yml tls: certificates: - certFile: /certs/your-cert.crt keyFile: /certs/your-cert.key ``` -------------------------------- ### Configure Bitrix Agents to Run via Cron Source: https://context7.com/bitrix-docker/server/llms.txt Configures Bitrix agents to run via cron in an isolated container instead of on page hits. This involves setting specific options in the Bitrix PHP console, modifying `dbconn.php`, and enabling the cron container in the Docker Compose file. ```php // Execute in Bitrix PHP console to configure agent settings COption::SetOptionString("main", "agents_use_crontab", "N"); COption::SetOptionString("main", "check_agents", "N"); COption::SetOptionString("main", "mail_event_bulk", "20"); // Verify settings echo COption::GetOptionString("main", "agents_use_crontab", "N") . "\n"; echo COption::GetOptionString("main", "check_agents", "Y") . "\n"; echo COption::GetOptionString("main", "mail_event_bulk", "5") . "\n"; ``` ```php // sites/example.com/www/bitrix/php_interface/dbconn.php // Replace existing BX_CRONTAB constants with conditional check if(!(defined("CHK_EVENT") && CHK_EVENT===true)) define("BX_CRONTAB_SUPPORT", true); ``` ```ini # sites/example.com/.env - Enable cron container COMPOSE_FILE=docker-compose.yml:cron.yml ``` ```bash # Restart site with cron enabled cd sites/example.com docker compose up -d # Verify cron container is running docker compose ps # Should show: example-com-cron container running alongside php-fpm and nginx ``` -------------------------------- ### Configure Memcached for Distributed Caching Source: https://context7.com/bitrix-docker/server/llms.txt Enables distributed caching by configuring Memcached support. This involves updating the Docker Compose file to include the Memcached service and setting Memcached-specific constants in the Bitrix PHP configuration files. ```ini # Add memcached to main .env COMPOSE_FILE COMPOSE_FILE=docker-compose/docker-compose.yml:docker-compose/traefik.yml:docker-compose/mysql.yml:docker-compose/memcached.yml # Memcached settings MEMCACHED_CONN_LIMIT=1024 MEMCACHED_MEMORY_LIMIT=1024 MEMCACHED_THREADS=8 ``` ```php // sites/example.com/www/bitrix/php_interface/dbconn.php // Add these constants for Memcached support define("BX_CACHE_TYPE", "memcache"); define("BX_CACHE_SID", $_SERVER["DOCUMENT_ROOT"]."#01"); define("BX_MEMCACHE_HOST", "memcached"); define("BX_MEMCACHE_PORT", "11211"); ``` ```php // sites/example.com/www/bitrix/.settings_extra.php // Alternative D7 configuration method return array( 'cache' => array( 'value' => array( 'type' => 'memcache', 'memcache' => array( 'host' => 'memcached', 'port' => '11211', ), 'sid' => $_SERVER["DOCUMENT_ROOT"]."#01" ), ), ); ``` -------------------------------- ### Disable Cron for Secondary Bitrix Sites Source: https://context7.com/bitrix-docker/server/llms.txt This configuration snippet from a `.env` file shows how to disable cron jobs for secondary Bitrix sites, ensuring they only run on the main site. This is achieved by specifying the correct `COMPOSE_FILE` environment variable. ```ini # sites/secondary-site.com/.env # Disable cron for secondary sites (run only on main site) COMPOSE_FILE=docker-compose.yml # NOT: COMPOSE_FILE=docker-compose.yml:cron.yml ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.