What happened to my Web Server?


Updating to Symfony 3.4

The GitHut series was originally created in order to help you get started with Symfony 3.

With the recent release of Symfony 4, some of the commands and processes described in this tutorial have changed.

Symfony has a strong backward compatibility promise, and we can take advantage of this when upgrading the tutorial to use Symfony 4 concepts and techniques.

A key step in migrating existing Symfony applications from Symfony 3 to Symfony 4 is to first upgrade to Symfony 3.4.

The reason for this is that Symfony 3.4 provides most of the same features as Symfony 4, and so if our project code works with Symfony 3.4, it is likely to continue working with Symfony 4.

However, the Symfony project follows semantic versioning which means a major release (such as Symfony 2>3, or Symfony 3>4) can and will break things. With Symfony 2 to Symfony 3, the changes were fairly small for the end user. With Symfony 3 to Symfony 4, however, the changes are much larger.

We will cover the changes from Symfony 3.4 > Symfony 4 in the next tutorial.

Upgrading From Symfony 3.x to Symfony 3.4

Making the change from Symfony 3.2 to Symfony 3.4 is seemingly a matter of updating the appropriate line in composer.json:

     "require": {
         "php": ">=5.5.9",
-        "symfony/symfony": "3.2.*",
+        "symfony/symfony": "3.4.*",

After which you will need to run composer update to bring in the latest changes.

There is a little more to it than this. If all you do is update symfony/symfony then problems may arise, but we will cover what these are, and how to fix them in the forthcoming videos.

The Web Server

The original videos in this tutorial were created using Symfony 3.2 specifically.

In Symfony 3.2 the web server came included.

In Symfony 3.3, the web server was extracted out to a separate bundle.

What this means is that in the original tutorial we could simply run:

php bin/console server:start              

 [OK] Server listening on http://127.0.0.1:8000                                                                         

And we would have a web server up-and-running, which we could connect to and start playing around with our code.

With Symfony 3.3 onwards (and we are on Symfony 3.4), we must now composer require this extra dependency:

composer require symfony/web-server-bundle --dev

Using version ^3.4 for symfony/web-server-bundle
./composer.json has been updated
# ... etc

Note the use of the --dev option flag. This puts the new dependency under the require-dev section of your projects composer.json file. This is because the web server is required only for development purposes, and is not required as part of a production build.

With the Web Server Bundle added to our projects dependencies we aren't quite done just yet.

We must enable the bundle, but only when in the dev / development environment.

We can easily achieve this by adding the following conditional to AppKernel:

<?php

// app/AppKernel.php

use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\Config\Loader\LoaderInterface;

class AppKernel extends Kernel
{
    public function registerBundles()
    {
        $bundles = [
            // ... existing bundles
        ];

        // ...

        if ('dev' === $this->getEnvironment()) {
            $bundles[] = new Symfony\Bundle\WebServerBundle\WebServerBundle();
        }

        return $bundles;
    }

With this change in place we can start a web server (php bin/console server:start) and continue with the tutorial.

Code For This Video

Get the code for this video.

Episodes

# Title Duration
1 What happened to my Web Server? 04:09
2 Fixing Generic Symfony Deprecations 07:11
3 Fixing Deprecations In Our Own Code 08:52
4 Fixing Third Party Bundle Deprecations (Indirectly) 05:38
5 [Part 1/2] Migrating to Symfony 4.0 with Flex 06:44
6 [Part 2/2] Migrating to Symfony 4.0 with Flex 10:44