Reputation: 157
I'm trying to create a simple routing rule in Symfony4 using Apache as webserver, but it is not working properly.
I can see the main / rule, but not anyone.
I've installed my project following these commands:
composer create-project symfony/skeleton s4-02-routing
composer require symfony/apache-pack
It's my routes.yaml file...
app_lucky_number:
path: /lucky/number
controller: App\Controller\LuckyController::number
And this it's the controller...
<?php
// src/Controller/LuckyController.php
namespace App\Controller;
use Symfony\Component\HttpFoundation\Response;
class LuckyController {
public function number() {
$number = random_int(0, 100);
return new Response(
'<html><body>Lucky number: ' . $number . '</body></html>'
);
}
}
The .htaccess file exists, and this is the virtualhost configuration:
<VirtualHost *:80>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
#ServerName www.example.com
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
<Directory /var/www/html>
AllowOverride All
# Order Allow,Deny
Require all granted
Allow from All
</Directory>
# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf
</VirtualHost>
The main URL http://192.168.2.12/s4-02-routing/public/ is working properly since I can see:
Welcome to Symfony 4.3.2 Your application is now ready. You can start working on it at: /var/www/html/s4-02-routing/
But, the URL http://192.168.2.12/s4-02-routing/public/lucky/number is not working, because I see a symfony error:
Sorry, the page you are looking for could not be found. (2/2) NotFoundHttpException No route found for "GET /lucky/number"
But, the rule is well created:
vagrant@06f2a172f274:/var/www/html/s4-02-routing$ php bin/console debug:router
------------------ -------- -------- ------ ---------------
Name Method Scheme Host Path
------------------ -------- -------- ------ ---------------
index ANY ANY ANY /
app_lucky_number ANY ANY ANY /lucky/number
What is wrong? Thanks your any help.
Upvotes: 1
Views: 92
Reputation: 157
I found how to solve the issue: cleaning the cache...
php bin/console cache:clear
Upvotes: 1