# Running Symfony 4 on Windows

If you have been following the posts about Symfony 4, then you will know that there is a new package called 'flex' which can auto-configure extensions after installing them.

The issue is that it uses the 'make' command which is not available on Windows (Unless you have installed one of the various programs that make it available).I couldn't find any information about the plans to make this work with Windows, but I was recently told on GitHub that the 'make' commands were optional and didn't need to be used. So I thought I would have another go. I'm sure it will all work when the first stable release comes out, but for me, some changes need to be made to get the demo working.

I'm assuming that people finding this have been trying to follow this demo post where we walk through installing some extensions.

So, I start by creating a composer project:

composer create-project "symfony/skeleton:^3.3" symfony4

This creates the folder symfony4 and installs the basic needed packages.

In the terminal, you will probably get an error like this:

Executing script make cache-warmup [KO]
[KO]
Script make cache-warmup returned with error code 1
!!  'make' is not recognized as an internal or external command,
!!  operable program or batch file.
!!
!!

This one isn't really an issue and everything will install ok, it just can't warm up the cache after the install.

If you check the composer.json file in the root of the project folder, in the scripts section you will see the line:

"make cache-warmup": "script",

If you then check the Makefile in the root of the folder, you will see that the cache-warmup command calls the usual Symfony bin/console command. So this would fail even if 'make' was possible since we don't have the console installed at this point anyway.

cache-warmup: cache-clear
@test -f bin/console && bin/console cache:warmup || echo "cannot warmup the cache (needs symfony/console)"

So, back to the tutorial, we install the console (cli) and a webserver (Make sure you cd into the project folder before running commands).

composer req cli:next

or

composer req webserver

This is where the issues started for me. You may see an error like this:

Executing script make cache-warmup [KO]
[KO]
Script make cache-warmup returned with error code 1
!!  'make' is not recognized as an internal or external command,
!!  operable program or batch file.
!!
!!

Installation failed, reverting ./composer.json to its original content.

Same error again about the cache warmup, but a more serious message that composer is reverting the config file back to the previous version as the installation failed. So our config file is no longer representative of the packages we are trying to install.

Open up the composer file again and change the 'make' line to use the normal php console command (Change the path to php if needed).

"php bin/console cache:warmup": "script",

If you now try running the same install command again, they should succeed and the packages should be added to the require section of the config file.

The next issue I ran into was when trying to start the built-in server.

php bin/console server:run

The run command assumes the web root is a folder called 'web', but the web root is now a folder called 'public' so the server won't start.

I briefly changed the public folder to 'web' and that got it running but I'm not sure what would happen when the asset installer runs after installing new packages since installing the admin package automatically adds easyadmin's assets to the public folder. In the composer config file, it uses '%PUBLIC_DIR%' but I can't find where this is defined.

I have always had issues with the built-in webserver and ZendServer anyway so I'm keeping the folder named public and accessing via my usual localhost instead.

Following on with the tutorial, you install the admin bundle, create the Product entity, install and migrate the database and configure the admin bundle.

At this point you should be able to see the easyadmin interface at /admin but I get a 404 error (Not a Symfony one).

To get around that, I created a .htaccess file in the public folder to route all requests to the index.php file:

RewriteEngine On
#
# If the requested path and file is not /index.php and the request
# has not already been internally rewritten to the index.php script
RewriteCond %{REQUEST_URI} !^/index\.php
# and the requested path and file doesn't directly match a physical file
RewriteCond %{REQUEST_FILENAME} !-f
# and the requested path and file doesn't directly match a physical folder
RewriteCond %{REQUEST_FILENAME} !-d
# internally rewrite the request to the index.php script
RewriteRule .* index.php [L]

Now when I test the admin route, I still get a 404, but this time I see the normal Symfony debug page.

If you debug the router in the console window you should see that the admin route is registered.

php bin/console debug:router

Shows:

 ------------------ -------- -------- ------ ---------------------------
Name               Method   Scheme   Host   Path
------------------ -------- -------- ------ ---------------------------
_twig_error_test   ANY      ANY      ANY    /_errors/{code}.{_format}
------------------ -------- -------- ------ ---------------------------

So this is really just a cache issue. Clear the cache with:

php bin/console cache:clear --no-warmup

You must use the --no-warmup flag or you will get another error and the cache will not be cleared.

 // Clearing the cache for the dev environment with debug true

[WARNING] Calling cache:clear without the --no-warmup option is deprecated since version 3.3.
Cache warmup should be done with the cache:warmup command instead.

Fatal error: Class App\Kerne_ may not inherit from final class (App\Kernel) in \path\to\symfony4\var\cache\de_\kernel.tmp on line 49

I'm not sure why we always need a flag but, now the cache is cleared, the admin route should now work and you can see the easyadmin interface and manage products.

Phew :)