1
1
1alexandr2015-05-31 06:22:06
symfony
1alexandr, 2015-05-31 06:22:06

How to set up symfony2 and nginx?

Hello! I can't properly set up a project on nginx + php-fpm.
Now my project is launched only under .../app_dev.php, I would like it to be launched without app_dev.php. When trying to run without, the app_dev.php file is downloaded. How can this be corrected? Here is the content of the file from site-available (taken from here ):

server {
    server_name allergo.loc www.allergo.loc;
    root /var/www/allergo.loc/web;

    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(/|$) {
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_split_path_info ^(.+\.php)(/.*)$;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param HTTPS off;
    }
    # PROD
    location ~ ^/app\.php(/|$) {
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_split_path_info ^(.+\.php)(/.*)$;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param HTTPS off;
        # Prevents URIs that include the front controller. This will 404:
        # http://allergo.loc/app.php/some-path
        # Remove the internal directive to allow URIs like this
        internal;
    }

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

And another question, I can’t clear the cache without sudo, after I cleared it, I have to chmod app/cache. How to fix it?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Denis, 2015-05-31
@1alexandr

server {
    server_name allergo.loc www.allergo.loc;
    root /var/www/allergo.loc/web;
    
    listen 80;
    location / {
        try_files $uri @rewriteapp;
    }
    location @rewriteapp {
        rewrite ^(.*)$ /app.php/$1 last;
    }
    location ~ ^/(app|app_dev|config)\.php(/|$) {
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_split_path_info ^(.+\.php)(/.*)$;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param HTTPS off;
    }
    
    charset utf-8;
    client_max_body_size 100m;

    gzip_min_length 1024;
    gzip_proxied expired no-cache no-store private auth;
    gzip_types text/plain application/xml;

    error_log /var/log/nginx/allergo_error.log;
    access_log /var/log/nginx/allergo_access.log;
}

Cache
If on LAN and does not look outside, then move the site to a hamster and run puff with a server from the user.
Less gem ... oya will be with the rights later.

K
kompi, 2015-05-31
@kompi

Concerning the rights and a cache.
Run php-fpm/nginx under www-data.
And a few commands to forget about debian-like permissions:
1) force group for /var/www
2) chmod -R g+rw /var/www once
3) umask 002 for www-data
4) umask 002 for the user
5) add the user to the www-data group
6) restart services and relogin the user

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question