If we have Drupal installed in a Linux development environment, it runs wonderfully even in a virtual machine with 1 GB of RAM and 1 CPU core. When we switch to Windows things change drastically, even with 16 GB of RAM and 6 CPU cores everything seems to go slow, with waiting times on average of 5 seconds, at least for a development environment, which is the only thing that it is acceptable to run it on Windows. This problem is nothing new, it has been dragging on since the adoption of IPv6 by Windows 7. I will not go into details about what the cause is and will concentrate on providing the solution.
Current configuration
- Drupal 9
- MariaDB 1.5
- PHP 7.4
- Nginx 1.14
- PHP opcache
- Laragon 5
If we used a virtual machine with Linux within Windows, we would not have the problem, but for ease we chose to use Laragon, but in this specific case it would be the same result with XAMPP, WampServer or WPN-XM.
Solution
Modifications on Windows
First, we must modify our hosts file in the path C:\Windows\system32\drivers\etv\hosts
, and verify that a line is found with the following:
127.0.0.1 localhost
There may be multiple lines with 127.0.0.1
, there is no problem.
Modifications in Drupal
Then in our Drupal site configuration file, which is normally [root]/web/sites/default/settings.php
or [root]/web/sites/default/settings.local.php
, we modify the "host" field of our database, and we put the value "127.0.0.1", this step is especially important, on Linux it is recommended to use "localhost", but not in Windows.
As an extra and highly recommended, I realized that the BigPipe module of the Drupal core does not work very well in Windows and that by deactivating it we gain a few extra seconds, at least in a native development environment in Windows, the thing would be hugely different on a Linux virtual machine.
Modifications in MySQL or MariaDB
Finally, we modify the MySQL or MariaDB configuration file, normally named my.ini, under the [mysqld]
section we add or modify the following values:
[mysqld]
#...
#...
skip-name-resolve
bind-address=*
To have a little more security, I recommend blocking port 3306 or the one we are using for MySQL, to prevent from connecting remotely. The skip-name-resolve
directive disables DNS resolution every time a client connects, and bind-address
allows connections from any IP address. Do not forget that we must restart MySQL or MariaDB with our package manager or in Windows services.
Conclusions
Although this problem is not new and at the same time it is not serious, one of the things that has become important in recent years is the performance of web applications, because we could say that waiting a few seconds is nothing while we develop, but 5 seconds is already torture, and although in this case Drupal uses an internal cache, the problem still exists only in a hidden way or at least only for users in the administration area. I took the trouble to write this post because after having quite a few intermittent problems with Vagrant, I decided to use something more practical and less error-prone like a native, non-virtualized application. I clarify that I have nothing against virtualization, on the contrary, the ideal is to have a production and development environment as similar as possible, even at the operating system level.