Symfony 3.4.9执行console debuger:router遇连接拒绝及路由问题求助
Hey there, let's work through these issues you're hitting with Symfony 3.4 — I've dealt with similar connection and routing headaches before, so here's what to check step by step:
1. Fix the Typo in Your Debug Command
First off, the error might stem from a simple typo! You ran sudo console debuger:router, but the correct Symfony console command for listing registered routes is:
sudo php bin/console debug:router
Give that a try first — if you still get the connection refused error, we'll dig into deeper checks.
2. Ensure Your Local Server is Running
Symfony can't respond to requests if the server isn't up and running:
- If you're using Symfony's built-in server, start it with:
php bin/console server:run - If you're using Apache or Nginx instead, verify the service is active (run
sudo systemctl status apache2orsudo systemctl status nginx) and that your virtual host is correctly pointing to your project'swebdirectory (the public root for Symfony 3.4).
3. Verify Your Routing Configuration
Since you're getting a "page not found" error when accessing your controller route, let's confirm your routes are properly registered:
- If using YAML routing (in
app/config/routing.yml), make sure you've imported your controller routes correctly. For example:app: resource: "@AppBundle/Controller/" type: annotation - If using annotations in your controller, double-check that annotation routing is enabled in
app/config/config.ymland that your controller class has valid@Routeannotations (watch for typos in paths or controller references). - Run the corrected
debug:routercommand — if your expected route doesn't show up in the list, that's a clear sign your routing config has an issue.
4. Fix File Permissions (Ubuntu 16.04 Specific)
Ubuntu's strict file permissions often cause unexpected Symfony errors. Make sure the var directory (where Symfony stores cache and logs) has the right access:
sudo chmod -R 775 var sudo chown -R $USER:www-data var
This lets Symfony write to necessary files, which can resolve connection or access-related issues.
5. Check for Unnecessary Service Connections
If the connection refused error persists, it might be that Symfony is trying to connect to a service (like a database) that isn't running or configured properly. Check your app/config/parameters.yml for database credentials, and confirm your database server (MySQL/MariaDB) is active with sudo systemctl status mysql.
Since you're following a routing tutorial, you might not even need a database yet — if that's the case, check if any enabled bundles in your config are requiring a database connection that isn't set up.
内容的提问来源于stack exchange,提问作者Mark Dibeh

