Configuring Apache for 1C-Bitrix

Our company is engaged in the development, support and maintenance of Bitrix and Bitrix24 solutions of any complexity. From simple one-page sites to complex online stores, CRM systems with 1C and telephony integration. The experience of developers is confirmed by certificates from the vendor.
Our competencies:
Development stages
Latest works
  • image_website-b2b-advance_0.png
    B2B ADVANCE company website development
    1177
  • image_bitrix-bitrix-24-1c_fixper_448_0.png
    Website development for FIXPER company
    811
  • image_bitrix-bitrix-24-1c_development_of_an_online_appointment_booking_widget_for_a_medical_center_594_0.webp
    Development based on Bitrix, Bitrix24, 1C for the company Development of an Online Appointment Booking Widget for a Medical Center
    564
  • image_bitrix-bitrix-24-1c_mirsanbel_458_0.webp
    Development based on 1C Enterprise for MIRSANBEL
    747
  • image_crm_dolbimby_434_0.webp
    Website development on CRM Bitrix24 for DOLBIMBY
    655
  • image_crm_technotorgcomplex_453_0.webp
    Development based on Bitrix24 for the company TECHNOTORGKOMPLEKS
    976

Apache Configuration for 1C-Bitrix

Apache remains a common choice for Bitrix — especially in the official Bitrix Environment, where it runs alongside Nginx (Apache handles PHP, Nginx sits in front as a reverse proxy). Configuring Apache without understanding Bitrix-specific behavior leads to issues with .htaccess, the mod_rewrite module, and performance.

Apache as a Backend Behind Nginx

In Bitrix Environment, the standard setup is: Nginx listens on 80/443 and proxies PHP requests to Apache (port 8080):

# nginx: forward PHP to Apache
location ~ \.php$ {
    proxy_pass http://127.0.0.1:8080;
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}

Apache accepts the request and processes it via mod_php or mod_proxy_fcgi (PHP-FPM). In this setup, Apache does not serve static files — Nginx delivers them directly.

VirtualHost Configuration

<VirtualHost *:8080>
    ServerName example.com
    DocumentRoot /var/www/bitrix

    <Directory /var/www/bitrix>
        Options -Indexes +FollowSymLinks
        AllowOverride All
        Require all granted
    </Directory>

    # Accelerate PHP via FPM
    <FilesMatch "\.php$">
        SetHandler "proxy:unix:/run/php/php8.1-fpm-bitrix.sock|fcgi://localhost"
    </FilesMatch>

    ErrorLog ${APACHE_LOG_DIR}/bitrix_error.log
    CustomLog ${APACHE_LOG_DIR}/bitrix_access.log combined
</VirtualHost>

AllowOverride All — required for Bitrix .htaccess to work. Without it, SEF URLs (urlrewrite) will not function.

Bitrix .htaccess and mod_rewrite

Bitrix generates .htaccess automatically when SEF URLs are enabled. The core rules:

Options -Indexes
AddDefaultCharset UTF-8

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /

    # Bitrix composite (HTML cache)
    RewriteCond %{DOCUMENT_ROOT}/bitrix/html_pages/%{HTTP_HOST}/%{REQUEST_URI}/__index.html -f
    RewriteRule ^ /bitrix/html_pages/%{HTTP_HOST}/%{REQUEST_URI}/__index.html [L]

    # Redirect to urlrewrite.php
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ /bitrix/urlrewrite.php [L]
</IfModule>

mod_rewrite must be enabled: a2enmod rewrite && systemctl reload apache2.

Blocking Service Directories

# In /var/www/bitrix/bitrix/.htaccess
<IfModule mod_authz_core.c>
    Require all denied
</IfModule>

# Prevent PHP execution in the upload directory
<Directory /var/www/bitrix/upload>
    <FilesMatch "\.php$">
        Require all denied
    </FilesMatch>
</Directory>

Apache Performance for Bitrix

MPM event + PHP-FPM — the recommended combination for production:

# /etc/apache2/mods-enabled/mpm_event.conf
<IfModule mpm_event_module>
    StartServers          2
    MinSpareThreads      25
    MaxSpareThreads      75
    ThreadLimit          64
    ThreadsPerChild      25
    MaxRequestWorkers   150
    MaxConnectionsPerChild 1000
</IfModule>

MaxConnectionsPerChild 1000 — Apache restarts child processes after 1,000 requests. This is the equivalent of pm.max_requests in PHP-FPM and guards against memory leaks in mod_php.

Case Study: .htaccess and AllowOverride Conflict

A site migration: SEF URLs worked on the old hosting but on the new server all URLs except the homepage returned 404. mod_rewrite was enabled and .htaccess was in place. Cause: AllowOverride None in the default Apache 2.4 Ubuntu config. A single line AllowOverride All in the VirtualHost fixed the problem. Rule of thumb: after any migration, always verify AllowOverride in the Apache configuration.

Estimated time to configure Apache for Bitrix: 0.5–1 day.