Environment for 1C-Bitrix based on Docker

Why is this needed?


For a long time, all the projects of our company worked on PHP5, and now there was a desire to speed them up by switching to PHP7, while updating the entire environment necessary for work. The question immediately arose: "How to get different projects to work on different versions of PHP?"

What came to mind:

  1. Contain 2 different servers
  2. Use virtual machine
  3. Apply Docker

Option 1 is obviously not economically viable. Option 2, we found it difficult to configure and too resource intensive. Many probably will not agree with this, however, we decided to use Docker technology, due to its lightness and ease of application transfer. The main selection criterion was that Docker solves the “works on my machine” problem .

Environment selection


Maria DB was chosen from the DBMS, since in all our projects it is important to quickly read data, there is no need to write data simultaneously.

We decided to use the Apache2 + Nginx bunch, where Nginx serves static files and Apache2 takes responsibility for the dynamics.

In the future, it is easy to add, if necessary, such things as Redis, Memcached, etc. to the system.

Environment structure


All our projects have copies on the battle server, used to test changes before release. Therefore, we conditionally divided the environment into 2 parts: demo and prod.
Each of the parts has its own container with b / d. Those. demo and prod databases are separate. Demo and prod also include a container with PHP5 and a container with PHP7.

At the head of everything is Nginx proxy, directing requests to the container specified in the configuration file. This makes it easy to switch PHP versions by simply redirecting the request to the required container, since project files are available in each of them. The only difference is in what environment they are executed.

Example site configuration for Nginx proxy:

server {
	listen 80;
	server_name example.ru www.example.ru;

	location / {
		proxy_pass http://demo_php7_web;
	}
}

You can clearly see the structure of the system in the diagram:

image

System optimization


Most of our projects work on the 1C-Bitrix platform, so we configured Apache2 and Nginx taking into account the requirements of the bitrix_server_test script provided by 1C-Bitrix.

All necessary PHP extensions are installed in containers with web servers, as well as curl, rsyslog, htop, xvfb, libfontconfig, wkhtmltopdf, jpegoptim, optipng . In addition, server-side file compression is configured.

Features


  • On the crown is checking the configuration files of Apache2 and Nginx for changes, with a frequency of 1 minute. There is no need to go into the container to do reload after changing the settings.
  • The containers on the web server have a developer
  • user who runs Apache2, Cron, and Nginx
  • SSL is supported, a description of the configuration is given in the examples of configuration files

Using


Currently, this system, in which more than 30 projects are launched, works properly on our server.

The project is available on GitHub . It also contains a more detailed description of the file structure of the project and describes how to get started.