Permissions issue with Docker, nginx and Grav - php

I'm trying to set up a simple Grav site workflow using git, Docker and two containers: one for nginx and one for PHP. The idea is to git clone into my Digital Ocean droplet and run docker-compose up -d --build to build and serve the website.
I'm getting permission issues whenever I try to access the sites, and even Grav's documentation about troubleshooting permission issues does not help.
Here's my docker-compose.yml:
version: '3'
services:
web:
build:
context: .
dockerfile: ./docker/nginx/Dockerfile
ports:
- "80:80"
volumes:
- ./src:/var/www/html
links:
- php
php:
build:
context: .
dockerfile: ./docker/php/Dockerfile
volumes:
- ./src:/var/www/html
And here's nginx's Dockerfile:
FROM nginx:stable-alpine
WORKDIR /var/www/html
COPY ./src .
COPY ./docker/nginx/default.conf /etc/nginx/conf.d/default.conf
If that's any use, here's the nginx configuration I'm using:
server {
listen 80;
index index.php index.html;
server_name www.gravtest.test gravtest.test;
error_log /var/log/nginx/gravtest.test.error.log;
access_log /var/log/nginx/gravtest.test.access.log;
root /var/www/html;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass php:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
}
The PHP Dockerfile is simple, it just spawns php:7.3-fpm and installs a few dependencies like opcache, gd, etc...
Whenever I try to access the site via localhost, I get this error:
Fatal error: Uncaught RuntimeException: Creating directory failed for /var/www/html/cache/compiled/files/40779d000b68629af00dd987148afc06.yaml.php in /var/www/html/vendor/rockettheme/toolbox/File/src/File.php:325 Stack trace:....
Files are copied from the host to the container with the nginx:nginx owner, so I should be good, but looks like I'm not. I've tried setting folders/files chmod using Grav's documentation but no dice.
Am I missing something?

Answering my own question:
It turns out the images php-fpm and nginx do not use the same user, so the permission problem came from that. I simply had to add a new user to both Dockerfile, and run that container from that user.
So for PHP, my Dockerfile is now:
FROM php:7.3-fpm
# Install a few dependencies here...
COPY ./src /var/www/html
RUN addgroup --gid 1000 mygroup
RUN adduser --system --no-create-home --disabled-password --disabled-login --uid 1000 --ingroup mygroup myuser
RUN chown -R myuser:mygroup /var/www
USER myuser
And for nginx:
FROM nginx:stable-alpine
RUN addgroup --gid 1000 mygroup
RUN adduser --system --no-create-home --disabled-password --disabled-login --uid 1000 --ingroup mygroup myuser
WORKDIR /var/www/html
RUN chown -R myuser:mygroup .
USER myuser
And now everything works fine! :)

Related

How can change Nginx default log file location in docker setting

I'm very new to docker and trying build docker compose with multiple service/app, also set the log file place separately.
If I run docker compose up will cause the open() file error like
FPM-nginx | 2022/10/06 01:40:54 [emerg] 1#1: open() "/var/www/FPM/log/nginx/error.log" failed (2: No such file or directory)
FPM-nginx | nginx: [emerg] open() "/var/www/FPM/log/nginx/error.log" failed (2: No such file or directory)
According relative answer, I've try adding the new command in Dockerfile but still causing the error.
The answers tried
Nginx access log file path
The answers tried 2
Nginx log location
Currently Dockerfile docker-compose.yml nginx.conf like below
Dockerfile
FROM php:8.0.2-fpm
RUN mkdir -p /var/www/FPM/log/nginx/ \ <<<<<<<<< This is new add
touch /var/www/FPM/log/nginx/error.log \ <<<<<<<<< This is new add
touch /var/www/FPM/log/nginx/access.log \ <<<<<<<<< This is new add
apt-get update && apt-get install -y \
git \
curl \
zip \
unzip
WORKDIR /var/www/FPM
nginx.conf
server {
listen 80;
index index.php;
root /var/www/FPM/public;
error_log /var/www/FPM/log/nginx/error.log;
access_log /var/www/FPM/log/nginx/access.log;
error_page 404 /index.php;
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass app:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
location / {
try_files $uri $uri/ /index.php?$query_string;
gzip_static on;
}
}
docker-compose.yml
version: "3.8"
services:
app:
build:
context: ./
dockerfile: Dockerfile
container_name: FPM-app
restart: always
working_dir: /var/www/FPM
volumes:
- ../src:/var/www/FPM
nginx:
image: nginx:1.23.1-alpine
container_name: FPM-nginx
restart: always
ports:
- 8000:80
volumes:
- ../src:/var/www/FPM
- ./nginx:/etc/nginx/conf.d
I've also tried place
error_log /var/www/FPM/log/nginx/error.log;
access_log /var/www/FPM/log/nginx/access.log;
under location / but still cause the error
location / {
error_log /var/www/FPM/log/nginx/error.log;
access_log /var/www/FPM/log/nginx/access.log;
}
You've multiple issues with you docker and docker-compose files.
According to your docker-compose.yml, when you would be doing docker-compose up you'll have two containers running one brought up from the docker image built at the time and the other brought up from public nginx:1.23.1-alpine image. The first image built will have the /var/www/FPM/log/nginx/ folder along with the error.log and access.log files but docker-compose up will overwrite the content because of this line:
volumes:
- ../src:/var/www/FPM
That being said, you don't even need that folder and those files in the first (app) container in the first place. You need them in the nginx container. So you can remove these lines from the Dockerfile:
mkdir -p /var/www/FPM/log/nginx/ \
touch /var/www/FPM/log/nginx/error.log \
touch /var/www/FPM/log/nginx/access.log \
Instead, create error.log and access.log inside your src directory or if you would choose at src/log/nginx/ location for brevity. And mount these files in your docker compose file.
version: "3.8"
services:
app:
build:
context: ./
dockerfile: Dockerfile
container_name: FPM-app
restart: always
working_dir: /var/www/FPM
volumes:
- ../src:/var/www/FPM
nginx:
image: nginx:1.23.1-alpine
container_name: FPM-nginx
restart: always
ports:
- 8000:80
volumes:
- ../src:/var/www/FPM
- ../src/nginx/logs/error.log:/var/www/FPM/log/nginx/error.log;
- ../src/nginx/logs/access.log:/var/www/FPM/log/nginx/access.log;
- ./nginx:/etc/nginx/conf.d

Docker compose nginx get site running from another container

I have two containers running, one is running PHP and a laravel site which is all working fine. The second container is an nginx container, currently returning 404 error but I would like to render the site via the PHP container.
- app
- bootstrap
- config
- database
- nginx
- default.conf
- DockerFile
- php
- public
- resources
- routes
- storage
- vendor
- docker-compose.yml
- docker-production.yml
- DockerFile
DockerFile
FROM php:7.4
RUN apt-get update -y && apt-get install -y openssl zip unzip git cron
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
RUN apt-get clean && rm -rf /var/lib/apt/lists/*
RUN docker-php-ext-install pdo pdo_mysql
WORKDIR /app
COPY . .
RUN composer install
ADD config/laravel_cron /etc/cron.d/cron
RUN chmod 0644 /etc/cron.d/cron
RUN touch /var/log/cron.log
RUN chmod 0777 /var/log/cron.log
RUN crontab /etc/cron.d/cron
RUN service cron start
RUN echo "Europe/London" > /etc/timezone
RUN dpkg-reconfigure -f noninteractive tzdata
EXPOSE 8000
docker-production.yml
version: '3.7'
services:
horse-racing-api:
container_name: horse_racing_api
restart: unless-stopped
build:
context: .
dockerfile: DockerFile
stdin_open: true
tty: true
working_dir: /app
volumes:
- ./:/app
web-server:
container_name: web_server
ports:
- 80:80
build:
context: nginx
dockerfile: DockerFile
depends_on:
- horse-racing-api
links:
- horse-racing-api
volumes:
- ./:/app
volumes:
app:
nginx/DockerFile
FROM nginx:latest
COPY ./default.conf /etc/nginx/conf.d/default.conf
nginx/default.conf
server {
listen 80;
index index.php index.html;
error_log /var/log/nginx/error.log;
access_log /var/log/nginx/access.log;
root /var/www/public;
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass horse-racing-api:8000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
location / {
try_files $uri $uri/ /index.php?$query_string;
gzip_static on;
}
}
Honestly been piecing this together from resources around the internet :/

Docker-Compose with PHP and Nginx not working on production

I have a very simple config in docker-compose with php:7-fpm and nginx that I want to use to host simple php websites.
Can someone please tell me what I did wrong?
Here is docker-compose.prod.yml:
version: '3.8'
services:
web:
image: nginx:latest
ports:
- "8080:80"
volumes:
- ../nurock/hidden_creste:/code
- ./site.prod.conf:/etc/nginx/conf.d/default.conf
php:
image: php:7-fpm
volumes:
- ../nurock/hidden_creste:/code
Here is the site.prod.conf file:
server {
listen 80;
index index.php index.html;
server_name example.com;
error_log /var/log/nginx/error.log;
access_log /var/log/nginx/access.log;
root /code;
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass php:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
}
I can compose up and the logs appear to be fine and when I run docker ps:
docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
c268a9cf4716 php:7-fpm "docker-php-entrypoi…" 27 minutes ago Up 16 seconds 9000/tcp example_code-php-1
beaaec39209b nginx:latest "/docker-entrypoint.…" 27 minutes ago Up 16 seconds 0.0.0.0:8080->80/tcp, :::8080->80/tcp example_code-web-1
Then checking the ports, I think this looks fine:
netstat -tulpn | grep :80
tcp 0 0 0.0.0.0:8080 0.0.0.0:* LISTEN 204195/docker-proxy
tcp6 0 0 :::8080 :::* LISTEN 204207/docker-proxy
You need to expose TCP port 9000 of the PHP container to made other containers able to use it (see What is the difference between docker-compose ports vs expose):
php:
image: php:7-fpm
expose:
- "9000"
...
Do you really want your sites to be available on TCP port 8080, not the standard port 80? If not, change "8080:80" to "80:80".
Besides the PHP handler, use a default location (although your site should be workable even without it, it is a bad practice to not add it to your nginx config):
location / {
try_files $uri $uri/ =404;
}
You must check the logs to find out the error. https://docs.docker.com/engine/reference/commandline/logs/
These issues can happen :
A php module is missing
user / permission are not correct. Is www-data defined in your nginx and php-fpm config ?
Use HTTPS and port 443 instead of HTTP and port 80. HTTP may be blocked by your browser. You can define a free SSL certificate with Let's Encrypt Docker image.
PHP 7.0 is EOL (end or life) since January 10, 2019. Please use PHP 8.0 or PHP 8.1. https://endoflife.date/php
Do not use use tag nginx:latest on production. You may have serious issues when you update your container, because last version will be downloaded.
Do not mount directory on production. Please use COPY in your Dockerfile.
Check the firewall on your server
Here is Docker Docker best practices : https://docs.docker.com/develop/dev-best-practices/
https://docs.docker.com/develop/develop-images/dockerfile_best-practices/
Here, I suggest this docker-compose.prod.yml
version: '3.8'
services:
web:
image: nginx:1.21
depends_on:
- my-php-container-name
container_name: my-nginx-container-name
working_dir: /code
ports:
- '80:80'
- '443:443'
volumes:
- ../nurock/hidden_creste:/code
- ./site.prod.conf:/etc/nginx/conf.d/default.conf
restart: always
php:
build: php-fpm
container_name: my-php-container-name
working_dir: /code
volumes:
- ../nurock/hidden_creste:/code
restart: always
In the same directory as this docker-compose.prod.yml file, create a php-fpm directory: mkdir php-fpm (or directory architecture written under build in docker-compose.prod.yml file.)
In php-fpm directory, please add this Dockerfile called Dockerfile
FROM php:8.1-fpm
COPY --from=composer:latest /usr/bin/composer /usr/local/bin/composer
WORKDIR "/code"
RUN apt-get update && apt-get install -y --no-install-recommends \
libfreetype6-dev \
libjpeg62-turbo-dev \
libpng-dev \
libicu-dev
&& docker-php-ext-configure gd --with-freetype --with-jpeg \
&& docker-php-ext-install -j$(nproc) gd pdo_mysql bcmath mysqli intl
Of course, add the PHP extensions that you need for your project. Here you have an example how to install gd, pdo_mysql, bcmatch, mysqli, intl. But there are others extension as curl, xml, xdebug, mcrypt, memcache, etc... https://github.com/mlocati/docker-php-extension-installer
In your nginx configuration, you should define config for HTTPS with port 443. Please also update this line fastcgi_pass php:9000;. Replace php by the container name. Of course, container name must be unique.
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass my-php-container-name:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
Then, build your set-up
docker-compose -f docker-compose.prod.yml build && docker-compose -f docker-compose.prod.yml up

500 (Internal Server Error) with Laravel & Docker [duplicate]

This question already has answers here:
How do I get PHP errors to display?
(27 answers)
Closed 10 months ago.
I create Laravel PHP application in Docker. First I setup Laravel app using
laravel new laravelDockerApp
it creates successfully.I verify it's setup by built-in server
php artisan serve
Then setup Local environment with Docker
docker-compose.yml
version: '2'
services:
web:
build:
context: ./
dockerfile: web.docker
volumes:
- ./:/var/www
ports:
- "8080:80"
links:
- app
app:
build:
context: ./
dockerfile: app.docker
volumes:
- ./:/var/www
app.docker
FROM php:7-fpm
RUN apt-get update && apt-get install -y libmcrypt-dev mysql-client \
&& docker-php-ext-install mcrypt pdo_mysql
WORKDIR /var/www
web.docker
FROM nginx:1.10
ADD ./vhost.conf /etc/nginx/conf.d/default.conf
WORKDIR /var/www
vhost.conf
server {
listen 80;
index index.php index.html;
root /var/www/public;
location / {
try_files $uri /index.php?$args;
}
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass app:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
}
I run docker-compose up -d command. app & web containers up successfully.When I check app in Browser using
localhost:8080
I got
500(Internal Server Error)
Please, can you help to solve this? Thanks.
I found a solution. I set the permission on my Laravel app using:
sudo chmod -R 777 storage && sudo chmod -R 777 bootstrap/cache
This solution might not apply to you since you are using Nginx, but in my case I am using the php:7.0-apache as source image, so I made the Apache user the owner of my app's files.
In my Dockerfile I have:
...
USER www-data
WORKDIR /var/www/html
COPY --chown=www-data:www-data . .
...
This solved the problem, so it could be worth trying, either modifying your Dockerfile or maybe Docker Compose has some option for user permissions when mounting volumes.
I ran into this today, and the issue for me was that while I'd created my directory structure, I'd failed to copy the .env file from .env.example. Copying this and hitting the webpage gave me a page which had this in the top right corner:
Clicking "Generate App Key" resolved this issue for me, but it's probably worth giving the .env file a once-over to make sure it's not got some other unset variables you'll need!

File Not Found when running PHP with Nginx

Recently I installed the latest version of Nginx and looks like I'm having hard time running PHP with it.
Here is the configuration file I'm using for the domain:
server {
listen 80;
server_name localhost;
location / {
root /usr/share/nginx/html;
index index.php;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
include fastcgi_params;
}
}
Here is the error I'm getting on the error log file:
FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream
Try another *fastcgi_param* something like
fastcgi_param SCRIPT_FILENAME /usr/share/nginx/html$fastcgi_script_name;
I had the "file not found" problem, so I moved the "root" definition up into the "server" bracket to provide a default value for all the locations. You can always override this by giving any location it's own root.
server {
root /usr/share/nginx/www;
location / {
#root /usr/share/nginx/www;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi_params;
}
}
Alternatively, I could have defined root in both my locations.
Probably it's too late to answer but a couple things since this is a really annoying error. Following solution worked on Mac OS X Yosemite.
It's the best if you have
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
The include with fast cgi params should go above that line.
All your directories down to the PHP file you're executing (including that file too) should have a+x permissions, e.g.
sudo chmod a+x /Users/
sudo chmod a+x /Users/oleg/
sudo chmod a+x /Users/oleg/www/
sudo chmod a+x /Users/oleg/www/a.php
I had been having the same issues,
And during my tests, I have faced both problems:
1º: "File not found"
and
2º: 404 Error page
And I found out that, in my case:
I had to mount volumes for my public folders both on the Nginx volumes and the PHP volumes.
If it's mounted in Nginx and is not mounted in PHP, it will give: "File not found"
Examples (Will show "File not found error"):
services:
php-fpm:
build:
context: ./docker/php-fpm
nginx:
build:
context: ./docker/nginx
volumes:
#Nginx Global Configurations
- ./docker/nginx/nginx.conf:/etc/nginx/nginx.conf
- ./docker/nginx/conf.d/:/etc/nginx/conf.d
#Nginx Configurations for you Sites:
# - Nginx Server block
- ./sites/example.com/site.conf:/etc/nginx/sites-available/example.com.conf
# - Copy Public Folder:
- ./sites/example.com/root/public/:/var/www/example.com/public
ports:
- "80:80"
- "443:443"
depends_on:
- php-fpm
restart: always
If it's mounted in PHP and is not mounted in Nginx, it will give a 404 Page Not Found error.
Example (Will throw 404 Page Not Found Error):
version: '3'
services:
php-fpm:
build:
context: ./docker/php-fpm
volumes:
- ./sites/example.com/root/public/:/var/www/example.com/public
nginx:
build:
context: ./docker/nginx
volumes:
#Nginx Global Configurations
- ./docker/nginx/nginx.conf:/etc/nginx/nginx.conf
- ./docker/nginx/conf.d/:/etc/nginx/conf.d
#Nginx Configurations for you Sites:
# - Nginx Server block
- ./sites/example.com/site.conf:/etc/nginx/sites-available/example.com.conf
ports:
- "80:80"
- "443:443"
depends_on:
- php-fpm
restart: always
And this would work just fine (mounting on both sides) (Assuming everything else is well configured and you're facing the same problem as me):
version: '3'
services:
php-fpm:
build:
context: ./docker/php-fpm
volumes:
# Mount PHP for Public Folder
- ./sites/example.com/root/public/:/var/www/example.com/public
nginx:
build:
context: ./docker/nginx
volumes:
#Nginx Global Configurations
- ./docker/nginx/nginx.conf:/etc/nginx/nginx.conf
- ./docker/nginx/conf.d/:/etc/nginx/conf.d
#Nginx Configurations for you Sites:
# - Nginx Server block
- ./sites/example.com/site.conf:/etc/nginx/sites-available/example.com.conf
# - Copy Public Folder:
- ./sites/example.com/root/public/:/var/www/example.com/public
ports:
- "80:80"
- "443:443"
depends_on:
- php-fpm
restart: always
Also here's a Full working example project using Nginx/Php, for serving multiple sites:
https://github.com/Pablo-Camara/simple-multi-site-docker-compose-nginx-alpine-php-fpm-alpine-https-ssl-certificates
I hope this helps someone,
And if anyone knows more about this please let me know,
Thanks!
I just spent like 40 minutes trying to debug a non-working /status with:
$ SCRIPT_NAME=/status SCRIPT_FILENAME=/status QUERY_STRING= REQUEST_METHOD=GET cgi-fcgi -bind -connect /var/run/php5-fpm.sock
It just produced "File not found" error, while the actual scripts (that are found on the filesystem) worked just fine.
Turned out, I had a couple of orphaned processes of php5-fpm. After I killed everything and restarted php5-fpm cleanly, it just went back to normal.
Hope this helps.
The error message “Primary script unknown or in your case is file not found.” is almost always related to a wrongly set in line SCRIPT_FILENAME in the Nginx fastcgi_param directive (Quote from https://serverfault.com/a/517327/560171).
In my case, I use Nginx 1.17.10 and my configuration is:
location ~ \.php$ {
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
include fastcgi_params;
fastcgi_read_timeout 600;
}
You just change $document_root to $realpath_root, so whatever your root location, like /var/www/html/project/, you don't need write fastcgi_param SCRIPT_FILENAME /var/www/html/project$fastcgi_script_name; each time your root is changes. This configuration is more flexible. May this helps.
=================================================================================
For more information, if you got unix:/run/php/php7.2-fpm.sock failed (13: Permission denied) while connecting to upstream, just change in /etc/nginx/nginx.conf, from user nginx; to user www-data;.
Because the default user and group of PHP-FPM process is www-data as can be seen in /etc/php/7.2/fpm/pool.d/www.conf file (Qoute from https://www.linuxbabe.com/ubuntu/install-nginx-latest-version-ubuntu-18-04):
user = www-data
group = www-data
May this information gives a big help
In my case the PHP-script itself returned 404 code. Had nothing to do with nginx.
In my case, it was because the permissions on the root web directory were not set correctly. To do this, you need to be in the parent folder when you run this in terminal:
sudo chmod -R 755 htmlfoldername
This will chmod all files in your html folder, which is not recommended for production for security reasons, but should let you see the files in that folder, to be sure that isn't the issue while troubleshooting.
I had this error as well. In my case it was because there was another virtual host that was pointing to the same root directory.
After upgrading to PHP72, we had an issue where the php-fpm.d/www.conf lost the settings for user/group which was causing this error. Be sure to double check those if your setup involves php-fpm.
The website will show "File Not Found" error.
You should check this configure file: /etc/nginx/nginx.conf (error_log) to get the nginx webservice log location.
Then check nginx log: /var/log/nginx/error.log to get the root cause:
Keyword: FastCGI sent in stderr: "Primary script unknown"
Root cause: php-fpm service's account: apache doesn't have access permission to open webapps directory
Step 0. Find your root directory:
open /etc/nginx/nginx.conf file and find root keyword
Root directory: /var/lib/nginx/webapps/
Step 1. Make sure apache account can access the ROOT directory.
sudo -u apache ls -l /var/lib/nginx/webapps/
Step 2. chmod a+x permission for all ROOT folder
sudo chmod a+x /var/
sudo chmod a+x /var/lib/
sudo chmod a+x /var/lib/nginx/
sudo chmod a+x /var/lib/nginx/webapps/
For me, problem was Typo in location path.
Maybe first thing to check out for this kind of problem
Is path to project.
When getting "File not found", my problem was that there was no symlink in the folder where was pointing this line in ngix config:
root /var/www/claims/web;
in case it helps someone, my issue seems to be just because I was using a subfolder under my home directory, even though permissions seem correct and I don't have SELinux or anything like that.
changing it to be under /var/www/something/something made it work.
(if I ever found the real cause, and remember this answer, I'll update it)
try this command
sudo chmod 755 -R htdocs/
my case: I used relative dir
location ~* \.(css|js)\.php$ {
root ../dolibarr/htdocs;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_index index.php;
include /etc/nginx/fastcgi_params;
}
this line did not work too : fastcgi_param SCRIPT_FILENAME /vagrant/www/p1/../p2/htdocs/core/js/lib_head.js.php;
So I discovered fastcgi_param does not support relative path.
This works
fastcgi_param SCRIPT_FILENAME /vagrant/www/p2/htdocs/core/js/lib_head.js.php;
I have solved this issue in nginx version: nginx/1.21.3 PHP 7.4.23 macOS Catalina version 10.15.7
nano /usr/local/etc/nginx/nginx.conf
location ~ \.php$ {
root html;
include fastcgi.conf;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
#Comment bellow Line
#fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
#Add This line
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
For me, this File not found problem was because i started php-fpm as sudo. First, stop it as sudo and then start without sudo.

Categories