0

Created a virtualhost for symfony application in local system

Here is the nginx config file

server {
    listen 80;
    server_name local.symfony;
    root /home/guest/symfony_demo/web;

    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;

       try_files $uri @rewriteapp;
    }

    error_log /var/log/nginx/project_error.log;
    access_log /var/log/nginx/project_access.log;

}

On load of app in browser its throwing an error 502 Bad Gateway Error:No input file specified.

Error caught from error.log file:

FastCGI sent in stderr: "Unable to open primary script: /home/guest/symfony_demo/web/app.php (No such file or directory)" while reading response header from upstream, client: 127.0.0.1, server: local.symfony, request: "GET / HTTP/1.1", upstream: "fastcgi://unix:/var/run/php5-fpm.sock:", host: "local.symfony"

Can anyone help me to configure symfony app to app_dev config file.

Any thoughts??

3 Answers 3

3
 fastcgi_param  SCRIPT_FILENAME  $realpath_root$fastcgi_script_name;

This line is the problem. If you remove it, your error disappears. You may then have Opcache problems due to Symfony using symlinks to the current project.

With $realpath_root$fastcgi_script_name, the web server looks at the "real" path for the PHP script based on the root definition in your server block. Nginx must have read permissions to the path for this to work. Your code is in /home/guest/, if nginx is running as "www-data" give it permissions to your directories, or run nginx as the "guest" user (ignoring the security implications of this).

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

Comments

0

Why don't you start with configuration from official documentation (http://symfony.com/doc/current/cookbook/configuration/web_server_configuration.html#nginx) and when that works, you can try to add your custom configuration (caching of sttaic files ...) ?

This should work:

server {
    listen 80;
    server_name local.symfony;
    root /home/guest/symfony_demo/web;

    location / {
        try_files $uri /app_dev.php$is_args$args;
    }

    location ~ ^/(app_dev|config)\.php(/|$) {
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        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 /var/log/nginx/project_error.log;
    access_log /var/log/nginx/project_access.log;
}

1 Comment

I have tried this configuration. But, I still see the same error.
0

This error happens when nginx is not able to find the php-fpm.sock file.

Can you make sure that the php-fpm.sock file is in the path as mentioned. I had to update fastcgi_pass like below

fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;

as my php-fpm.sock was there

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.