laravel / homestead

MIT License
3.87k stars 1.44k forks source link

Symfony 4.x route annotations not working on homestead #1179

Closed brooksvb closed 5 years ago

brooksvb commented 5 years ago

Versions

Host operating system

Windows 10

Homestead.yaml

ip: 192.168.10.10
memory: 2048
cpus: 1
provider: virtualbox
authorize: ~/.ssh/id_rsa.pub
keys:
    - ~/.ssh/id_rsa
folders:
    -
        map: ./
        to: /home/vagrant/code
sites:
    -
        map: homestead.test
        to: /home/vagrant/code/public
        type: "symfony4"
        php: "7.3"
databases:
    - homestead
name: brooks-codes
hostname: brooks-codes

Vagrant destroy & up output

Gist

Expected behavior

After instantiating the homestead box, if I use composer require annotations and add a route annotation to my Symfony project, it should properly enable and use the route annotations.

Actual behavior

Installing annotations and adding an annotation-defined route does not get used by the Symfony application. It does not show up in bin/console router:debug output either. The default page is shown every time instead. Defining the routes with routes.yml does work, however.

I haven't tested it extensively, but there seemed to be a similar issue with installing other Symfony packages, for example, the web debug toolbar not appearing after installing it.

Steps to reproduce

  1. Start with fresh Symfony project
  2. Install homestead via Composer on host machine
  3. vagrant up
  4. vagrant ssh
  5. Run composer require annotations in the project directory
  6. Add a default controller with a route defined by annotation
  7. Attempt to visit that route in browser OR run bin/console debug:router in the project directory

References

svpernova09 commented 5 years ago

Try changing

    map: ./

To

    map: /path/to/symfony-project

Then run

    vagrant destroy && vagrant up

--

brooksvb commented 5 years ago

I made this change and it didn't change behavior at all.

I'm using Homestead on a per-project-basis, which is why it was a relative path rather than absolute.

svpernova09 commented 5 years ago

Add the following to Homestead.yaml and run vagrant destroy && vagrant up (And save the output to another gist for us to see)

version: 7.2.1
svpernova09 commented 5 years ago

This is now the second issue we've seen where really odd things are happening in the alpha base box. #1178 is the other

brooksvb commented 5 years ago

This fixed the issue. vagrant destroy && vagrant up output gist

svpernova09 commented 5 years ago

I tried to replicate this without issue. My concern is there is an undiscovered bug in the alphas causing this and #1178, however using Homestead 8.5.5 and box 8.0.0-alpha2 I'm unable to replicate it. I'm surprised 8.0.0-alpha2 works with 8.x, I certainly wouldn't recommend it.

You were using Homestead 8.4 with the 8.0.0-alpha1 box. Following your steps, I created a new app, added homestead, added annotations, added a default controller and added another method. The routes work fine and show up in bin/console debug:router as you'd expect.

DefaultController:

<?php

namespace App\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Routing\Annotation\Route;

class DefaultController extends AbstractController
{
    /**
     * @Route("/", name="root")
     */
    public function index()
    {
        return $this->render('default/index.html.twig', [
            'controller_name' => 'DefaultController',
        ]);
    }

    /**
     * @Route("/about", name="about")
     */
    public function about()
    {
        return $this->render('default/about.html.twig', [
            'controller_name' => 'DefaultController',
        ]);
    }
}

vagrant@homestead-test:~/code$ bin/console debug:router
 -------------------------- -------- -------- ------ -----------------------------------
  Name                       Method   Scheme   Host   Path
 -------------------------- -------- -------- ------ -----------------------------------
  _twig_error_test           ANY      ANY      ANY    /_error/{code}.{_format}
  _wdt                       ANY      ANY      ANY    /_wdt/{token}
  _profiler_home             ANY      ANY      ANY    /_profiler/
  _profiler_search           ANY      ANY      ANY    /_profiler/search
  _profiler_search_bar       ANY      ANY      ANY    /_profiler/search_bar
  _profiler_phpinfo          ANY      ANY      ANY    /_profiler/phpinfo
  _profiler_search_results   ANY      ANY      ANY    /_profiler/{token}/search/results
  _profiler_open_file        ANY      ANY      ANY    /_profiler/open
  _profiler                  ANY      ANY      ANY    /_profiler/{token}
  _profiler_router           ANY      ANY      ANY    /_profiler/{token}/router
  _profiler_exception        ANY      ANY      ANY    /_profiler/{token}/exception
  _profiler_exception_css    ANY      ANY      ANY    /_profiler/{token}/exception.css
  root                       ANY      ANY      ANY    <href=>/
  about                      ANY      ANY      ANY    <href=>/about
 -------------------------- -------- -------- ------ -----------------------------------
ghost commented 4 years ago

I have the exact same issue with Homestead 9.0.1 and Virtual Box 5.2.

svpernova09 commented 4 years ago

I have the exact same issue with Homestead 9.0.1 and Virtual Box 5.2.

Virtualbox 5.2 is ancient. You should be using at least Virtualbox 6.0.0

ghost commented 4 years ago

It seems to be a problem with my Firewall, if I turn it off, everything works. Thanks for your help and sorry to bother you.

svpernova09 commented 4 years ago

@creacheck no worries! glad you got it sorted out.