Optimization of the web environment on the Jelastic platform for projects in PHP
In previous articles, we told you about the launch of the Jelastic.Cloud cloud platform on Infobox, as well as how we created a CMS directory to deploy them in one click on the Jelastic.Cloud platform and what high performance results we achieved by optimizing web environments. But, of course, not all existing CMS are in our catalog, so now we’ll talk about how to deploy your PHP project on Jelastic.Cloud yourself and optimize your environment for it. We will do this using the example of UMI.CMS.
Let's start by creating an environment. For most projects, a bunch of Apache + MySQL will suffice.

About how to upload project files to the created environment has been written more than once, so we will limit ourselvesreference to the instructions . But with databases, the question is not so obvious. When creating a MySQL node, the root user password comes in the mail. The most common mistake is to use this password to connect the site to the database server. To do this, it is better to create a separate user in PhpMyAdmin:

Another common mistake is to specify the local host in the Host field. The fact is that in Jelastic, the application server and the database server are separated, which means that user access will only be through the PhpMyAdmin interface and there will be no other place. You can specify “Any host” in this field, or you can check with technical support the internal address of your application server and allow access from it.
For ease of setup, you can also check the box “Create a database with a username in the name and grant full privileges to it” or “Grant full privileges to databases that match the template (username \ _%)”, otherwise you must also configure permissions created user.
The next difficulty that you may encounter when deploying a project on Jelastic is connecting the site to the database. To connect, you first need to look at the address of the database server:


And when connecting, it is this address and the data of the previously created user:


When the project is posted, you can think about optimizing the environment. Let's start with MySQL.
In the Jelastic control panel, select “Configuration” of the MySQL node and open the my.cnf file for editing:

We have 96 tables on our site. In order not to waste time opening them, let’s keep them all open in the cache by changing the value of the table_open_cache parameter to 100. When this parameter is set significantly larger than the number of tables, you increase the amount of RAM reserved for the cache, which leads to its increased consumption , which means high costs without any performance gain.
Now let’s cache requests by adding the variable query_cache_size with a value of 16M. This is an average value, which will be sufficient for most sites (with the exception of online stores), but another figure may be optimal for a specific project.
In addition to requests, it is desirable to cache streams. You can do this by adding a linethread_cache_size = 16 (8 is possible if high resource traffic is not expected).
Since InnoDB is used on the project in question, it is necessary to set the frequency of dumping logs to disk using the innodb_flush_log_at_trx_commit parameter . At the stage of debugging the project, you can use the value 1, but after the completion of the main work it is better to transfer the parameter to 2: this will ensure the maximum speed of the database server.
There are 2 more important parameters associated with InnoDB:
innodb_flush_method = O_DIRECT will avoid a situation where caching will be performed by both the operating system and the MySQL server;
innodb_buffer_pool_sizethe default is 512 MB, which is unnecessary for small databases. With the static content of the database, this parameter should be set slightly larger than the database size. If information is constantly added to the database, then the parameter can be 1.5-2 times larger than the database size and periodically reviewed.
Having made all these changes, save the my.cnf file and restart the MySQL server.
Now let's move on to optimizing the application server. To do this, open php.ini in the same way on the Apache node.
One of the reasons why the site does not work well on shared hosting is often the PHP accelerator, or rather, its absence. There are 4 accelerators preinstalled in Jelastic, you just have to turn on the needed one by uncommenting the necessary line in php.ini. Practice shows that the inclusion of apc gives the best result, so we will talk about its use later. At the same time, nothing prevents you from using another accelerator or even installing your own by downloading the SO file in the modules folder and also connecting it to php.ini.
For optimal APC operation, add the following lines to php.ini:
realpath_cache_size = 4M - the amount of memory allocated for caching the real path;
apc.ttl = 1800- sets the cache time to 30 minutes (the optimal value may be different depending on the frequency of updating content on the site);
apc.max_file_size = 4M - files larger than the specified value will not be cached to avoid an increase in RAM consumption;
apc.shm_size = 128M - maximum cache block size (the number of blocks can be increased using apc.shm_segments );
Save php.ini and move on to setting up the web server itself. The settings file is located in the conf directory and is called httpd.conf.
Most of this file does not affect performance, we will only be interested in the section:
StartServers 1
MinSpareServers 1
MaxSpareServers 2
ServerLimit 256
MaxClients 256
MaxRequestsPerChild 100
It should be replaced with:
StartServers 5
MinSpareServers 5
MaxSpareServers 10
ServerLimit 256
MaxClients 256
MaxRequestsPerChild 10000
In order not to overload the article, we will not describe the value of each of the variables, we only note that this configuration increases the speed of work, but at the same time leads to increased memory consumption.
After making the changes, you need to save httpd.conf and restart Apache:

The result of not too long work was the “excellent result” of the UMI.CMS performance index.

We hope that this article will help your projects to work faster! Well, the web applications from our CMS catalog for 1-click installations on Jelastic already fly.
You can see for yourselftaking part in beta testing of the platform until October 15.