laravelnginx-unit

Nginx Unit configuration cannot be applied for PHP/Laravel app. Permission issue, even with 777


I'm following this how-to: https://unit.nginx.org/howto/laravel/, with small modifications (basically changed the folder name).

Whenever I try to send the configuration JSON with CURL, I get this error message:

2023/06/15 20:01:27 [info] 5192#5192 "laravel" prototype started
2023/06/15 20:01:27 [info] 5193#5193 "laravel" application started
2023/06/15 20:01:27 [alert] 5193#5193 root realpath(/home/victor/workspace/estatutario/public/) failed (13: Permission denied)
2023/06/15 20:01:27 [notice] 5192#5192 app process 5193 exited with code 1
2023/06/15 20:01:27 [warn] 913#913 failed to start application "laravel"
2023/06/15 20:01:27 [alert] 913#913 failed to apply new conf
2023/06/15 20:01:27 [notice] 897#897 process 5192 exited with code 0

config.json

{
    "listeners": {
        "*:8003": {
            "pass": "routes"
        }
    },

    "routes": [
        {
            "match": {
                "uri": "!/index.php"
            },
            "action": {
                "share": "/home/victor/workspace/estatutario/public$uri",
                "fallback": {
                    "pass": "applications/laravel"
                }
            }
        }
    ],

    "applications": {
        "laravel": {
            "type": "php",
            "root": "/home/victor/workspace/estatutario/public/",
            "script": "index.php"
        }
    }
}

Permissions (to troubleshoot, I gave all permissions to everybody):

victor@webapps-dev:~/workspace/estatutario$ ls -la
total 384
drwxrwxrwx 13 unit   unit     4096 Jun 15 01:04 .
drwxrwxr-x 16 victor victor   4096 Jun 15 19:53 ..
drwxrwxrwx  7 unit   unit     4096 Jun 15 01:00 app
-rwxrwxrwx  1 unit   unit     1686 Jun 15 01:00 artisan
drwxrwxrwx  3 unit   unit     4096 Jun 15 01:00 bootstrap
(...)

PWD:

victor@webapps-dev:~/workspace/estatutario$ pwd
/home/victor/workspace/estatutario

User running Unit:

victor@webapps-dev:~$ ps -ef | grep unit
root         897       1  0 19:15 ?        00:00:00 unit: main v1.30.0 [/usr/sbin/unitd]
unit         912     897  0 19:15 ?        00:00:00 unit: controller
unit         913     897  0 19:15 ?        00:00:00 unit: router
victor      5559    1507  0 20:10 pts/0    00:00:00 grep --color=auto unit

I've double-checked the folder name and even gave 777 permissions. (Even though the user seems correct - unit).

Any thoughts why I'm still getting this error message?


Solution

  • Ok, after some research on a similar issue (Nginx: stat() failed (13: permission denied)) I found that Unit acts the same way as Nginx.

    So the problem / solution described on the previous question also applied. Even though I chowned the my project's root folder to unit:unit, the parent folder was still mine (victor:victor).

    /home/victor/workspace/myproject <--- unit:unit
    /home/victor/workspace/ <--- victor:victor
    /home/victor/ <--- victor:victor
    

    Nginx seems to need to have "x" permission from the root all the way to the folder you want to serve. I could either give unit those permissions or serve it from another directory.

    So I decided to serve from outside my home. /apps/myproject (unit:unit)