📜 ⬆️ ⬇️

Best practices for hosting Drupal in a cloudy environment

image
The main purpose of this article is to talk about the features and best practices of placing Drupal in the cloud environment of the Microsoft Azure platform [about the benefits of the Azure platform for hosting websites on PHP, Java, Python, .NET and Node.js you can read in this article - note . trans.]. From this guide, you will learn:


How to migrate an existing site to Drupal to the cloud


Migrating your Drupal site to your Azure cloud is a daunting task. Just use the best practices listed below and you can move your site to Drupal in a cloud environment in just one hour.

Creating an Azure Web Site and MySQL database

To get started, create a new website in Azure with MySQL and with Git support (you can use step-by-step instructions ). Please note that the article describes how to use the FREE version of MySQL in the cloud. This database version is great for the development phase, but for industrial use you may need to purchase a cloud copy of the ClearDB database from the Azure Store. You can choose from a set of plans for acquiring a common database cluster. For more information, see the ClearDB article from the Azure Store . If a plan with a common database cluster does not suit you, then you can choose a dedicated MySQL cluster. Details can be found at the following link ClearDB mission critical database plans .
')
If you are going to use Git for your Drupal site, then go through the steps guide that describes how to configure the Git repository. Make sure that you have done the necessary steps described in the section on getting information about connecting to a remote MySQL server, as you will need this information later. You may well ignore the final part of the tutorial, which is dedicated to deploying your site to Drupal, however, if you are just learning about the Azure cloud (or Git), then this part of the guide may be useful to you.

After starting a new Azure website with a database in MySQL, you will have information about connecting to a remote database and (optionally) the Git repository. The next step is to copy your MySQL database to the Azure website.

Copy database to MySQL to Azure website

There are many ways to migrate a database to Azure. One proven way to migrate MySQL is to use the [MySqlDump] tool. The following command shows an example of copying from a local machine to the cloud Azure Web Sites:

mysqldump -u local_username --password = local_password drupal | mysql -h remote_host -u remote_username --password = remote_password remote_db_name

Of course, you need to provide your name and password for an existing Drupal database. In addition, you need to transfer the host name, username, password and database name to the MySQL database created in the first step. This information is available in the connection string you received earlier. The connection string has a format similar to the following:

Database = remote_db_name; Data Source = remote_host; User Id = remote_username; Password = remote_password

Depending on the size of your database, the copy process may take several minutes.

Now your database lives in the Azure Web Sites cloud. Before placing your Drupal code you need to change it so that it can connect to the new database.

Change database connection in settings.php

At this step, you will again need information about connecting to a new database. Open the <drupalsite> /sites/default/setting.php file in the editor and replace the 'database', 'username', 'password' and 'host' values ​​in the $ databases array with the values ​​set for your new database. You should end up with something like this:

$databases = array ('default'=>array ('default'=>array ('database'=>'remote_db_name','username'=>'remote_username', 'password'=>'remote_password','host'=>'remote_host','port'=>'', 'driver'=>'mysql','prefix'=>'',),),); 

Note: if you have a configuration parameter $ base_url in settings.php , then comment it out, since Drupal CMS will create URL addresses from the set $ base_url. You can use the $ base_url parameter again right after your cloud site has been configured to use a custom domain. Save the settings.php file .

Now you are ready to place your code.

Posting Drupal code using Git or FTP

The final step is to place your code in the Azure website’s cloud using Git or FTP.


How to set up an Azure Storage Module


Immediately after installing Drupal, you need to enable and configure the blob storage module, which uses Azure Storage cloud storage to save media files. Use the following instructions to configure this module. Log in to your site as an administrator and enable the Azure Storage module in the modules tab. If this module is not in the list of modules, install it from here .

image_thumb [15]

Click the Configuration tab, then select Azure Storage in the Media section .

image_thumb [13]

Click the Add button to add the storage account data that will be used by your Drupal sites. Specify all the details: the name of the storage account, the name of the existing container (the container must be public), the URL of the blob storage repository, the primary access key. Use the custom URL parameter if your repository is associated with a CDN and specify the CDN address here. If you are not using a CDN, leave this field blank.

image_thumb [11]

Go back to the Configuration tab and select File System in the Media section. Select an item and save the setting by clicking Save Configuration.

image_thumb [9]

Now select Structure-> Content Type. Then click on manager fields of type Article. In the dialog box, check if you have an Image label that will display the Image Upload option when creating new materials. If you plan to support uploading files (of various formats), then also include the checkmark for File Upload.

image_thumb [7]

Now click on edit for the Image label and select the Azure Storage option for the Upload destination parameter. Do the same for all other tags you have for uploading files (with FILE field types).

image_thumb [6]

Repeat the steps to update the configuration for any type of content that supports uploading images or other files.

How to set up Memcached Cloud to support caching


Subscribe to the Memcached Cloud service, which offers memcached as a managed service. This service is currently available in the East US and West US regions of the Azure platform. If you want to manage your own memcached servers, then you have the easy option to configure them using your Linux-based Azure virtual machine. This article discusses the use of cloud Memcached.

Log in to the Redis labs portal and select New Memcached Subscription.

image_thumb [17]

Select the cloud platform / region for the service and the plan you will use. The free plan (25 MB) is great for development and testing purposes, but will not provide a sufficient level of performance required for a site in commercial operation. Click on Select and create your own memcached endpoint.

image_thumb [20]

Enter all required information. The module that I use for Drupal does not support the SASL (Simple Authentication and Security Layer), which can be added to your memcached server, in connection with which I deselected this option in the current step. Enter the resource name and click Activate . If you already have a module that supports the security level for memcached, you can enable it during the creation of the memcached endpoint.

image_thumb[24]

Now you can manage your memcached service from the Redis Labs portal .

image_thumb[25]

To get the server endpoint, click on the Resource Name you created. Remember the Endpoint value that you will need later to configure Drupal.

image_thumb[27]

Download and copy the memcached PECL extension from here . Please note that this extension is intended for PHP5.4 (32 bit). If your site uses a friend configuration, then select the appropriate library from here . Install the memcached module for Drupal. In the Azure website control panel, update your site configuration. In the application settings section (app settings) of the Configure tab, add the PHP_EXTENSIONS parameter with the value “bin \ php_memcache.dll”.

In the settings.php file in the $ conf variable add the memcached server. If you do not specify any of the servers, then memcache.inc will decide that an instance of your memcached server is running on the local machine on port 11211 (127.0.0.1:11211 or localhost: 11211), and since it is not there, your application does not will work.

The following array example shows the pattern:

 $conf['memcache_servers'] = array( 'pub-memcache-10939.us-east-1.1.azure.garantiadata.com: 10939' => 'default' ); 

For details, see the Memcache API for Drupal Handbook. You can use only one server for all Drupal operations with the above configuration, but if you prefer to split your dataset into multiple Memcached servers, you can easily create new Memcached server endpoints in the Azure Store. Below you will find a simple setup with two Memcached servers and in this example all data will be cached in Bucket 1, excluding “pages” (pages) that will be cached in Bucket 2.

  $conf['memcache_servers'] = array( 'server1_hostname:server1_port' => 'default', 'server2_hostname:server2_port' => 'pages' ); $conf['memcache_bins'] = array( 'cache_page' => 'pages', ); 

The most common approach for organizing caching is to mix the use of the content delivery network (CDN) and the Memcached service. Drupal uses a database to store the cache. If any content is changed, then by defining the change, Drupal will mark the cache as outdated to preserve the consistency of the content. Memcached replaces the internal Drupal caching system.

Best Practices for Drupal CMS in Azure


General recommendations for any site in the cloud:

  1. Plan for the future : you must track the performance and requirements of your site and user traffic patterns to plan up and down infrastructure scaling;
  2. Back up your site : back up your site [Azure Web Sites offers a built-in automatic backup and restore feature - approx. trans.]. Test backup and restore procedures.

Now let's focus on the Drupal CMS and learn some best practices for building and managing Drupal CMS in the Azure Web Sites cloud environment.

Security configuration

  1. Delete all temporary files before placing. While editing files, you may have temporary backup copies, for example, .bak files, files with names ending with “~”, settings.php.orig. These files can be viewed through the browser, unless you deny access to them through the setting in the web.config file using URL Rewrite rules. Such files can become a vulnerability of your site and open access to it for intruders. Delete all similar files. You can deny access to similar files by adding rules to the configuration file, denying access to any type of file. In addition, you can easily automate the task of deleting temporary files using the WebJobs background tasks feature offered by the Azure Web Sites service.
  2. Enable SSL for login. Drupal does not require the use of Secure sockets layer (SSL) when a user logs on. This makes it easier for attackers to gain administrative access to your site. Install and enable the Secure Pages module from drupal.org. This module ensures that each user is served via SSL.
  3. Disable unsafe download fields. Prevent unnecessary File and image fields that allow users to upload files to the site. An attacker could use these features to gain control on your website by downloading a file that could cause havoc on your system. Enter restrictions on the types of files that are allowed to download, remove the ability to download files such as .exe, .swf, .flv, .htm, .php, .vb, .vbs.
  4. Turn on the Security Kit module. The Security Kit module offers improvements to the security of your site, such as protection against attacks such as Clickjacking, Cross-Site Request Forgery (CSRF), Cross-Site Scripting (XSS) and others. It is recommended to use the default configuration for this module, however, if your site has any special requirements that the module may not meet, then you can configure the module’s own settings. For more information, see the module page .
  5. Do not use common user names for administrator accounts. The name of your administrator account should not be admin, administrator, or root , which are widespread and may represent a security vulnerability in your site. Use complex or unique usernames to avoid hacking.
  6. Hide the display of information about errors of the site from your users. These error messages can contain important sensitive information about your site or server and give it to visitors. To configure your website not to display error information to users, open the Logging and errors page at / admin / config / development / logging and select None from the Error messages to display and click Save configuration.
  7. Enable the Password Policy module. Your website's content editors may decide to use passwords that are easy to crack, which will open the doors of your website to intruders. In order to reduce the possibility of a vulnerability, enable the Password Policy module , which will include mandatory complex password policies.

Performance configuration

  1. The minimum cache lifetime is less than 5 minutes. To increase site responsiveness and performance, the minimum cache lifetime prevents the cache of pages and blocks from clearing after a change for a specified period of time. If you set the minimum cache lifetime to less than 5 minutes, the server will work more to deliver fresh content to site visitors. To set the minimum cache lifetime to 5 minutes or more on your site, open the Performance page at / admin / config / development / performance and select a new value for the Minimum cache lifetime parameter. Set this parameter as large as possible given the desire to have cached pages and the need for visitors to get fresh content as quickly as possible.
  2. The maximum page cache age is less than 5 minutes. When the maximum page cache age is set to less than 5 minutes, the server has to regenerate pages more frequently. This reduces the performance of the site. To set the parameter value to 5 minutes or more, open the Performance page at / admin / config / development / performance and select a new value for Page cache max age.
  3. Optimize CSS and JS scripts. With CSS / JS optimization turned off, your users will get a decrease in page speed and an increase in server load. To enable CSS optimization, open the Performance page at / admin / config / development / performance and set the Aggregate and compress CSS files option. To enable JavaScript optimization, open the Performance page at / admin / config / development / performance and set the Aggregate JavaScript files option.
  4. Turn on page compression. When page compression is turned off, site visitors face longer downloads of these pages. Squeeze the pages before storing them in the cache, so as to reduce network sharing with the backend. To enable page compression, open the Performance page at / admin / config / development / performance and make sure that the Cache pages for anonymous users option is set and set the Compress cached pages option.

Configuring an Azure website

  1. Through the Azure website management portal, enable server logs and use Azure Storage to store them. You can use the same repository that you have configured for storing media content. For more information, see the Azure website diagnostics manual.
  2. Set up automatic scaling, which will automatically increase or decrease the number of instances of your site. For details, refer to the Auto-scale Configuration manual.
  3. Use the Basic or Standard modes of the Azure Web Site, which provide you with dedicated VM instances, high performance, support within the SLA. For more information, see Features by tiers .
  4. Configure the site to operate in at least two Medium or Large instances (instances correspond to specific VMs for your website). If you use one instance, then in case of problems with its VM, your site may become unavailable. When using two copies, you will be able to avoid failure due to the failure of one point.
  5. Perform load testing of your site using Visual Studio tools or others to make sure that the scaling configuration of the site really allows you to maintain the calculated traffic.
  6. Set up an automatic disinfection of your site, which restarts your VMs based on certain indicators of the site status. For more information, see the article How to Auto-heal your website .

Best practice code

  1. Avoid making changes to the core Drupal. Making these changes makes it harder to manage Drupal versions and update your website, as well as make it more difficult for your website to grow as it grows.
  2. Avoid using a large number of modules. Drupal offers you the flexibility of allowing you to add modules that extend the functionality of the CMS. But at the same time, too many modules can affect the performance of your site and slow it down.
  3. Use web.config to launch the Azure website. Azure Web Sites websites use IIS, which allows you to use a web.config file to manage unauthorized file access protection and manage Rewrite URLs. Use the example web.config specified here for your Drupal site. You need to disable Application Request Routing cookies that pin certain users to specific VM instances. Turning off this feature will allow your website to use the usual load balancing behavior that is provided by the Azure platform out of the box. For more information, see the Disable ARR Cookie article. To configure this, add the following section to your web.config file immediately after <system.webserver>:

 <httpProtocol> <customHeaders> <add name="Arr-Disable-Session-Affinity" value="True" /> </customHeaders> </httpProtocol> 

Scaling Drupal into several regions around the world


By placing copies of a website in different regions around the world, you reduce the risk of a single point of failure when you rely on only one copy of the site in one data center. The key thing to keep in mind when working with cloud solutions is the understanding that each component (website, database, cache, etc.) may fail, and therefore your decision should be able to fail. handle and be trouble free. This will reduce the operating costs that may be due to service failure.

For this scenario, you need to place your Drupal site in at least two regions, for example, in East US and West US. Consider the Active-Active (Master-Master) configuration for the Drupal website in Azure:

  1. Two Azure websites linked to their respective MySQL databases
  2. Both MySQL databases are synchronized using database replication
  3. Using the Azure Traffice Manager service, user traffic is balanced for the regions by one of the three methods Performance, Failover or Round Robin
  4. Memcached managed service configured with failover function
  5. Azure Storage uses geo-redundancy with Azure CDN

This architecture is very easy to create, but if your application has special requirements, then you can customize this configuration for yourself. You can make the following changes:


Website scaling

Scaling up Azure Web Sites requires two actions: changing your Web Hosting Plan mode to a higher level and configuring certain settings after moving to a new plan. Both actions are covered in this article. Higher levels, such as the Standard mode, offer high performance and flexibility in how your resources will be used. For details, refer to the documentation for the How to scale Azure website .

Database Scaling

Your application depends on two components — the Azure website and the database. Depending on how you created your database, you are offered several ways to scale your database for high availability and fault tolerance. For example, there are two scenarios:

  1. If you are using the CrearDB service, then you just need to configure ClearDB high availability routing (CDBR). The ClearDB service offers database replication between pairs of regions (for example, East US and West US), but you can create and use your own database replication tools using Azure Web Jobs.
  2. MySQL Cluster CGE , MySQL Microsoft Azure. , MySQL, .

Memcached

Memcached Cloud Redis Labs . memcached , memcached . Memcached Cloud Features .

Traffic Manager

Azure Traffic Manager , -. Traffic Manager , DNS -. - . Traffic Manager :


Azure Traffic Manager Azure.

image_thumb[31]

, ADD -, .

image_thumb[33]

Web Site -,

Add Website Endpoints

traffic manager. URL traffic manager , .

Conclusion


Drupal Azure Web Sites. , , Drupal Azure . Drupal Microsoft Azure.

Additional links


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


All Articles