📜 ⬆️ ⬇️

Environment for 1C-Bitrix based on Docker

Why do you need it?


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, at the same time update the whole environment necessary for work. The question immediately arose: “How to make different projects work on different versions of PHP?”

What came to mind:

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

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

Selection environment


Maria DB was chosen from the DBMS, since fast reading of data is important in all our projects, there is no need to simultaneously write data.
')
Decided to use a bunch of Apache2 + Nginx, where Nginx serves static files and Apache2 takes responsibility for the dynamics.

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

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 have their own container with b / d. Those. demo and prod databases are separated. Also demo and prod and include a PHP5 coteiner and a PHP7 container.

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

Example of site configuration for Nginx proxy:

server { listen 80; server_name example.ru www.example.ru; location / { proxy_pass http://demo_php7_web; } } 

Visually consider the structure of the system can be on the scheme:

image

System optimization


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

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

Special features



Using


Currently, this system, which runs more than 30 projects, works properly on our server.

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

Source: https://habr.com/ru/post/351286/


All Articles