I'm new with Linux, PHP, Nginx & Symfony (yes, this will be a long road :) ) and I'm in trouble with creating a new Symfony project.
The problem
I browsed the web and others topics here, but I can't deal with the following message while accessing app_dev.php
:
An error occurred while loading the web debug toolbar (404: Not Found) Do you want to open the profiler?
And if I click OK
, I'm redirected on http://testsite.local/Symfony/web/app_dev.php/_profiler/f63f84
that results in a 404 error.
The config
I have a fresh install of Nginx with fpm that works fine with à standard PHP site.
app.php
and config.php
both work well (no problems spotted in config.php).
Here is the path of my Symfony project : /srv/www/testsite.local/public_html/Symfony/
And here my (basic) config of Nginx ( /etc/nginx/sites-available/testsite.local
):
server {
server_name testsite.local;
access_log /srv/www/testsite.local/logs/access.log;
error_log /srv/www/testsite.local/logs/error.log;
root /srv/www/testsite.local/public_html;
location / {
index index.html index.htm index.php;
}
location ~ \.php$ {
include /etc/nginx/fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
If anyone has an idea of how to solve this issue, let me know. Any help would be very appreciated :)
Thanks !
This nginx configuration should work for your dev environment
server {
server_name testsite.local;
root /srv/www/testsite.local/public_html;
location / {
# try to serve file directly, fallback to app.php
try_files $uri /app.php$is_args$args;
}
# DEV
# This rule should only be placed on your development environment
# In production, don't include this and don't deploy app_dev.php or config.php
location ~ ^/(app_dev|config)\.php(/|$) {
include /etc/nginx/fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
fastcgi_param DOCUMENT_ROOT $realpath_root;
}
error_log /srv/www/testsite.local/logs/error.log;
access_log /srv/www/testsite.local/logs/access.log;
}
If it's not check your fastcgi_params ( /etc/nginx/fastcgi_params
)
And don't forget to reload your nginx server
--
This configuration is a mix of the symfony documentation and the configuration you posted
@Miro & @VEBERArnaud : Thx guys, it works now.
Here is the solution, based on your suggestions :
server {
server_name testsite.local;
access_log /srv/www/testsite.local/logs/access.log;
error_log /srv/www/testsite.local/logs/error.log;
root /srv/www/testsite.local/public_html;
location / {
# try to serve file directly, fallback to app_dev.php
try_files $uri /Symfony/web/app_dev.php$is_args$args;
}
location ~ \.php$ {
include /etc/nginx/fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.