0

I have a project on symfony2.8, i use Parrot OS (Debian based), i have already installed PHP7.1 and MariaDB, but when i try to access to website project, i got :

403 Forbidden

There is some logs :

/var/log/nginx/error.log

2018/08/18 19:57:29 [error] 2520#2520: *15 directory index of "/var/www/html/xxxxxx/" is forbidden, client: ::1, server: _, request: "GET /airnjobs/ HTTP/1.1", host: "localhost"

/var/log/nginx/access.log

::1 - - [18/Aug/2018:19:57:29 +0200] "GET /xxxxx/ HTTP/1.1" 403 199 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36"

Can you help me please :/ i'm stuck !

UPDATE 1 :

Still no access, i chown directory and files and chmod with no results.

Casual
  • 11
  • 3
  • The docs have instructions on setting up directory permissions. Sadly, even when you get past this, Symfony 2.x will not run on php 7.x. Couple of php bc changes. Need to roll back to php 5.6. – Cerad Aug 18 '18 at 18:28
  • Please post your relevant Nginx config for that site. How familiar are you with configuring Nginx? – lxg Aug 18 '18 at 20:39
  • Also, @Cerad is right, you cannot run SF 2.8 with PHP 7.x. However, instead of going back to PHP 5.6, you might consider upgrading your SF to 3.4, as 2.8 will soon reach EOL anyway. – lxg Aug 18 '18 at 20:40
  • Just a side note: Symfony 2 IS compatible with PHP 7. I'd still advise to update to Symfony 3.4 as soon as possible though as Symfony 2.8 will not receive bug fixes anymore from December this year (see http://symfony.com/roadmap/2.8). To help you get your application up and running in the meantime, as @lxg said we will indeed need to know how you configured your virtual host in Nginx. – xabbuh Aug 18 '18 at 21:29
  • I understand better now what is problem, I will try to apply what you have advised me and maybe even try to upgrade the version of symfony! Thank you all for replying me ! – Casual Aug 19 '18 at 17:05

1 Answers1

0

This looks like an nginx configuration issue, not a permission problem.

If /xxxxx is the project directory, the web root of the project should be /xxxxx/web.
You log shows that you are trying to list the content of you project directory, when you should only ever be accessing /xxxxx/web/app_dev.php, /xxxxx/web/app.php or /xxxxx/web/config.php,
so this 403 error is the expected behaviour.

When trying to access the dev environment, your URL should be something like
http://localhost/xxxxx/web/app_dev.php,
or http://xxxxx.local/app_dev.php if you have a web host configured correctly.

The symfony doc has an example of nginx configuration for 2.8:
https://symfony.com/doc/2.8/setup/web_server_configuration.html#nginx

I changed it a bit to fit your case:

server {
    server_name xxxxx.local;
    root /var/www/html/xxxxx/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/php/php7.1-fpm.sock;
        fastcgi_split_path_info ^(.+\.php)(/.*)$;
        include fastcgi_params;
        # When you are using symlinks to link the document root to the
        # current version of your application, you should pass the real
        # application path instead of the path to the symlink to PHP
        # FPM.
        # Otherwise, PHP's OPcache may not properly detect changes to
        # your PHP files (see https://github.com/zendtech/ZendOptimizerPlus/issues/126
        # for more information).
        fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
        fastcgi_param DOCUMENT_ROOT $realpath_root;
    }
    # PROD
    location ~ ^/app\.php(/|$) {
        fastcgi_pass unix:/var/run/php/php7.1-fpm.sock;
        fastcgi_split_path_info ^(.+\.php)(/.*)$;
        include fastcgi_params;
        # When you are using symlinks to link the document root to the
        # current version of your application, you should pass the real
        # application path instead of the path to the symlink to PHP
        # FPM.
        # Otherwise, PHP's OPcache may not properly detect changes to
        # your PHP files (see https://github.com/zendtech/ZendOptimizerPlus/issues/126
        # for more information).
        fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
        fastcgi_param DOCUMENT_ROOT $realpath_root;
        # Prevents URIs that include the front controller. This will 404:
        # http://domain.tld/app.php/some-path
        # Remove the internal directive to allow URIs like this
        internal;
    }

    # return 404 for all other php files not matching the front controller
    # this prevents access to other php files you don't want to be accessible.
    location ~ \.php$ {
        return 404;
    }

    error_log /var/log/nginx/xxxxx_error.log;
    access_log /var/log/nginx/xxxxx_access.log;
}

This goes into your nginx configuration file, for example:
/etc/nginx/conf.d/xxxxx.conf

Then you need to add the hostname xxxxx.local to your /etc/hosts file:

127.0.0.1        xxxxx.local
vctls
  • 736
  • 7
  • 25