Learn how to prevent the net::ERR_CONNECTION_RESET error in the browser when accessing the default route of a new Symfony 6 project using XAMPP in Windows.

How to prevent Symfony 6 Projects from throwing net::ERR_CONNECTION_RESET in the browser using XAMPP with PHP 8

I've been using XAMPP for simple projects since I learned to develop software on the web with PHP. Symfony was as well my first choice of framework for PHP as I started working with it since the version 1.4 (a long time has passed considering that the latest version till the date is Symfony 6). A common problem with this practice is that when you work with special modules like Imagick, GD or other stuff that needs to be installed in the distribution of PHP, if it was installed locally in your environment but unfortunately it wasn't installed in the server (which instead of running Windows, runs Linux), your code will fail (causing the meme reaction "it works on my machine").

Excluding the mentioned problem, I'm still using XAMPP to run my Symfony projects locally in Windows and they work pretty well, except for the new Symfony 6 projects. You may probably be facing the same issue when trying to configure a VirtualHost and run a new empty Symfony 6 project and XAMPP with PHP 8.0.12.

That's all that you get in the browser when trying to connect, a vague browser error message of net::ERR_CONNECTION_RESET. At the beginning I thought that maybe my VirtualHost was misconfigured, but all the other PHP projects worked pretty well (including Symfony <= 5 projects), so I researched for a solution to this problem without success. In the end I was able to run the project using the Symfony built-in server:

symfony serve

This may be a possible solution for you in some cases (it was the solution for me until now), however if you are insistent in using xampp to make the project work, you have reached the correct place to learn how to do it.

Solution ... ?

Skinner Xampp Symfony

Unexpectedly a month ago, I found this issue#412 on the Monolog Bundle for Symfony opened by @JPustkuchen and everything pointed to the same issue I was facing. As any new Symfony 6 project works perfectly in production on Linux servers, it pointed out to a problem with XAMPP in Windows and something in the configuration. JPustkuchen determined the problem on the Monolog Bundle, if you comment out the MonologBundle from your project/config/bundles.php file:

<?php

return [
    // ... //
    // Symfony\Bundle\MonologBundle\MonologBundle::class => ['all' => true],
    // ... //
];

And comment the default configuration of monolog (project/config/dev/monolog.yaml):

#
#monolog:
#    handlers:
#        main:
#            type: stream
#            path: "%kernel.logs_dir%/%kernel.environment%.log"
#            level: debug
#            channels: ["!event"]
#        # uncomment to get logging in your browser
#        # you may have to allow bigger header sizes in your Web server configuration
#        #firephp:
#        #    type: firephp
#        #    level: info
#        #chromephp:
#        #    type: chromephp
#        #    level: info
#        console:
#            type: console
#            process_psr_3_messages: false
#            channels: ["!event", "!doctrine", "!console"]

Then clean the cache of your project and try to access the default route of a new Symfony project in the browser, the project will work and you will obtain a normal response in the browser! So we found the reason of the problem, but, this isn't a real solution isn't it? Monolog is a very useful tool that we shouldn't remove from our projects.

Real solution

Specifically, in this StackOverflow question, David Ferenczy mentions that:

It's a common problem when working with long regular expressions in PHP. This problem happens more often on Windows platform, because of smaller Apache's default stack size. There is 1 MB default stack size on Windows, unlike 8 MB on Unix/Linux platforms. It could be a reason, why some for example PHP scripts works properly on Linux, but cause crash of Apache on Windows. The best way to alter the Apache's stack size is using the ThreadStackSize directive in the Apache's configuration file. There is a description of the ThreadStackSize directive in Apache's documentation."

So in the end, it wasn't Symfony or Monolog's fault but a problem with Apache in Windows. To solve this problem, all I had to do was to specify the ThreadStackSize in the mpm_winnt_module of apache to 8MB and increase the ThreadsPerChild from 100 to 250. You can modify those parameters in the xampp/apache/conf/extra/httpd-mpm.conf file:

# xampp/apache/conf/extra/httpd-mpm.conf
# WinNT MPM
# ThreadsPerChild: constant number of worker threads in the server process
# MaxConnectionsPerChild: maximum number of connections a server process serves
<IfModule mpm_winnt_module>
    ThreadStackSize 8388608
    ThreadsPerChild        250
    MaxConnectionsPerChild   0
</IfModule>

Save the changes to the configuration file, restart apache and the project should be now accessible as always:

Symfony 6 Default Route Success Xampp PHP 8

Happy coding ❤️!


Interested in programming since he was 14 years old, Carlos is a self-taught programmer and founder and author of most of the articles at Our Code World.

Become a more social person

Sponsors