Skip to content
Advertisement

Nginx Php-fpm 7.3 Can’t read PHP files from a particular folder

We have a Magento 2 website. For some reason our Nginx/PHP-FPM is unable to read files from MAGEROOT/pub/ folder other than index.php.

We are getting the following error in Nginx Log "Unable to open primary script: /home/goodprice/public_html/releases/current/pub/get.php (No such file or directory)" and the browser shows No input file specified.

Here is the partial Nginx config file.

JavaScript

This causes a few problems. One is Magento 2 can’t serve the place holder image as it need to execute get.php. It’s not a permission issue as index.php is being executed. Can anybody help fix the problem in the above mentioned Nginx config? Any help will much appreciated.

ls -la from pub dir following

JavaScript

Php Fpm conf.d file extract users and groups.

JavaScript

nginx.conf as following

JavaScript

Advertisement

Answer

The issue here was php-fpm config. My mistake in asking the question was that I should have posted the whole php-fpm config with nginx config.

On our server the php-fpm settings are controlled from cpanel for each site. The problem was that php-fpm had php_value[doc_root] set to a folder above the pub folder. That was due to the fact the server and cpanel is configured to have code in /home/goodprice/public_html/. Which I modified to php_value[doc_root] = "/home/goodprice/public_html/releases/current/" thinking that’s Magento root so php should be reading there. But actually it should have been php_value[doc_root] = "/home/goodprice/public_html/releases/current/pub/". So on run time php is looking for a file, but the root (folder) is wrong where it’s looking at. This problem was confusing because php was erroring out with the path of the file but not where it was actually trying to locate the file. I Can’t explain why it would give out a correct path then look for just the file in it’s root folder.

So to summarise, if there is try_files in nginx config make sure that the nginx root, or the final path is same as folder php_value[doc_root] in php-fpm conf. Or better don’t have php_value[doc_root] in your php-fpm at all.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement