I am trying to let a custom script which is in the root directory of the Magento 2 installation but when I navigate to it on my browser, it returns a 404 error. For testing I tried to create an empty php file (abc.php) then navigate to it in the browser (domain/abc.php) it will still return a 404 even though I am certain the file exists in the location. I have tried CHMODding to 777 and changing ownership of the file to the same as the rest of the directory but I still get this 404.
I am using ubuntu 18.04 + NGINX as web server to run Magento 2. The Magento 2 installation is working on the browser, just any custom script I navigate to returns a 404. Has anyone ever had anything similar or have an idea on what to do next to debug this problem :/?
2
Answers
Try This if Inside of domain:-
Try This if File outside of domain
If you’ve setup NGINX according to Magento 2 recommendations, then it will only allow PHP execution from a list of well defined, known PHP files. Namely, if you look here, you’ll take notice of:
And this:
Which essentially means to deny execution for any PHP file other than
/index.php
,/get.php
, etc.So to allow for execution of a custom PHP file, you will need to adjust REGEX in the first location, to include the name of the custom file, e.g.:
The above would allow execution of
/test.php
in addition to other known PHP entrypoints.Furthermore, if your Magento website’s root in NGINX configuration is
/path/to/pub
(again, as per recommendations), then you need to place your custom file within thatpub
subdirectory, and not inside actual root of Magento.