14

Ok, so I just installed latest version Symfony 4. Run the browser after installation and a nice welcome greeting shows. All good!

Then I created a new controller using make:controller. I named this controller Client and is using Annotations, same with the other Default Controller. I configured the routing as follows:

/**
 * @Route("/client", name="client")
 */
public function index()
{
    // replace this line with your own code!
    return $this->render('@Maker/demoPage.html.twig', [ 'path' => str_replace($this->getParameter('kernel.project_dir').'/', '', __FILE__) ]);
}

I refreshed the browser and all good, no errors.

Then I manually typed the path into the browser to check if it's really working:

localhost:8000/client

Problem. The url returned standard apache 404

Not Found
The requested URL /client was not found on this server.

Apache/2.4.18 (Ubuntu) Server at new.staff-fdr.dev Port 80

The debug route sees this though:

-------------------------- -------- -------- ------ ------------------
  Name                       Method   Scheme   Host   Path   

 -------------------------- -------- -------- ------ -----------------
  client                     ANY      ANY      ANY    /client  
  index                      ANY      ANY      ANY    /       
  _twig_error_test           ANY      ANY      ANY    /_error/{code}.
Riza
  • 647
  • 2
  • 10
  • 16

3 Answers3

34

Missing .htaccess file.

composer config extra.symfony.allow-contrib true

composer req symfony/apache-pack
malcolm
  • 5,250
  • 24
  • 41
5

I also had this issue and here are a couple of other ideas if this isn't working for you. One is to configure your web server as documented here. The optimized apache with mod_php worked for me:

https://symfony.com/doc/master/setup/web_server_configuration.html

Second, I didn't have mod rewrite enabled on my web server. This was ultimately the fix that got me up and going. Run:

sudo a2enmod rewrite

Then

sudo service apache2 restart

That should get you going.

Johnny Wales
  • 349
  • 4
  • 13
  • Had the same problem on 2 different projects and had no clue about the cause. This was the solution, thank you very much! – MNN Nov 01 '19 at 00:31
0

In my case, I simply had forgotten to change my vhost configuration from the web to public folder when migrating to symfony flex.

<VirtualHost *:80>
    ServerAdmin webmaster@localhost.com
    DocumentRoot "C:/xampp/htdocs/myproject/web/"
    ServerName dev.myproject.com
    ServerAlias dev.myproject.com
    <Directory "C:/xampp/htdocs/myproject/web/">
        Options Indexes FollowSymLinks Includes ExecCGI
        AllowOverride All
        Require all granted
        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>

TO

<VirtualHost *:80>
    ServerAdmin webmaster@localhost.com
    DocumentRoot "C:/xampp/htdocs/myproject/public/"
    ServerName dev.myproject.com
    ServerAlias dev.myproject.com
    <Directory "C:/xampp/htdocs/myproject/public/">
        Options Indexes FollowSymLinks Includes ExecCGI
        AllowOverride All
        Require all granted
        Order allow,deny
        Allow from all
     </Directory>
</VirtualHost>
Tortus
  • 92
  • 7