0

I'm having trouble configuring Symfony2 with nginx

I installed symfony2 like this

php composer.phar create-project symfony/framework-standard-edition /var/www/symf

everything went smoothly, when i'm on the config page no erros enter image description here

but when i click Configure online or Buypass config i'm landing on nginx 404 NOT FOUND

here is the config file

upstream phpfcgi {
server 127.0.0.1:9000;
}

server {
listen 80;

server_name localhost;
root /var/www/symf/web;

error_log /var/log/nginx/symfony2.error.log;
access_log /var/log/nginx/symfony2.access.log;

# strip app.php/ prefix if it is present
rewrite ^/app\.php/?(.*)$ /$1 permanent;

location / {
    index app.php;
    try_files $uri @rewriteapp;
}

location @rewriteapp {
    rewrite ^(.*)$ /app.php/$1 last;
}

# pass the PHP scripts to FastCGI server from upstream phpfcgi
location ~ ^/(app|app_dev|config)\.php(/|$) {
    fastcgi_pass phpfcgi;
    fastcgi_split_path_info ^(.+\.php)(/.*)$;
    include fastcgi_params;
    fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_param  HTTPS off;
}
}

Note : i noticed when clicking buypass i'm landing on a link like ....symf/web/app_dev.php/ removing last / allow me to reach the page but got and error enter image description here clicking ok -> 404 no found

i'm i missing something ?

parameters.yml

    database_driver: pdo_mysql
database_host: 127.0.0.1
database_port: null
database_name: symfony
database_user: root
database_password: *****
mailer_transport: smtp
mailer_host: 127.0.0.1
mailer_user: null
mailer_password: null
locale: fr
secret: ******
debug_toolbar: true
debug_redirects: false
use_assetic_controller: true

3 Answers 3

1

Remove that part

# strip app.php/ prefix if it is present
rewrite ^/app\.php/?(.*)$ /$1 permanent;

You are already rewritting here after the try file which is how it should be done

location @rewriteapp {
    rewrite ^(.*)$ /app.php/$1 last;
}

And ofc make sure you reload your nginx service

Sign up to request clarification or add additional context in comments.

7 Comments

thank you but still cannot reach the page, 404 not found
You are installing on your local computer right not on a server ? Else you should try removing the locahost reference from the server_name directive and replacing it with 'your-domain.com' or '' for default. If that doesn't work we need more info on your php setup (ie: php5-fpm).
on a server yes, not locally, tried putting server_name to default, same, what exactly do you need ? php-fpm.conf file ?
@MuiMui not locally?? it wont work. if look at config folder there are routing.yml and routing_dev.yml which are responsible for local and production instances of your project.. Also, in prod version you can simply set you configuration in parameters.yml file
@xurshid29 my parameters.yml file was configured during the installation i edited first post to show you the config.
|
1

It's difficult to suggest somthing without knowing about your server configuration, but here is my working config, which works very fine (for nginx-php-fpm), may be it helps you:

server {
    listen   80;
    server_name my_site.dev *.my_site.dev;
    root /var/www/my_site.dev/public_html/web;

    error_log /var/log/nginx/my_site_error.log;
    access_log /var/log/nginx/my_site_access.log;

    rewrite ^/app\.php/?(.*)$ /$1 permanent;

    try_files $uri @rewriteapp;

    location @rewriteapp {
        rewrite ^(.*)$ /app.php/$1 last;
    }

    # Deny all . files
    location ~ /\. {
        deny all;
    }

    location ~ ^/(app|app_dev)\.php(/|$) {
        fastcgi_split_path_info ^(.+\.php)(/.*)$;
        include fastcgi_params;
        fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_index app.php;
        send_timeout 1800;
        fastcgi_read_timeout 1800;
        fastcgi_pass unix:/var/run/php5-fpm.sock;
    }

    # Statics
    location /(bundles|media) {
        access_log off;
        expires 30d;

        # Font files
        #if ($filename ~* ^.*?\.(eot)|(ttf)|(woff)$){
        #       add_header Access-Control-Allow-Origin *;
        #}

        try_files $uri @rewriteapp;
    }
}

Comments

0

Looks like the issue was with nginx, switching to apache2 and worked instantly

EDIT : if anyone has a clue of what is going on with nginx, is the conf file wrong ? i would like to know

1 Comment

This may sound stupid but did you happen to try restarting nginx after you made changes to the config file?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.