4

I created a phpinfo.php page in my Magento2 project but when I try to access it via URL it shows a 404 page.

It's set up here in the magento root:

|-Magento2
|-----<other folders etc.>
|-----phpinfo.php

url I try to go to: site.local/phpinfo.php - returns 404

I tried running all the commands but still 404s.. is it something with routing that's preventing me from just accessing a file normally?

Edit: my phpinfo code:

<?php
    phpinfo();
15
  • Can you please add your code here Commented Dec 17, 2018 at 9:16
  • are you using nginx? Commented Dec 17, 2018 at 9:19
  • @trey Bake !!, Give a try to adding index.php after your domain. Like http://site.local/index.php/phpinfo.php If still not work than rename .htaccess than check.
    – anonymous
    Commented Dec 17, 2018 at 9:19
  • site.local this runs your magento2 website correctly? What is the document root of your magento2 instance? Commented Dec 17, 2018 at 9:23
  • @WebDeveloper lemme give it a go :)
    – treyBake
    Commented Dec 17, 2018 at 9:25

3 Answers 3

5

As Jaimie Dijstra mentioned, your phpinfo.php file has to be placed inside the <magento_root>/pub directory.

However, if you are using Nginx as a webserver, you also have to edit the <magnto_root>/nginx.conf file (I assume you include the <magento_root>/nginx.conf file in your server configuration as advised by Magento). Search for

# PHP entry point for main application
location ~ ^/(index|get|static|errors/report|errors/404|errors/503|health_check)\.php$ {

and add phpinfo as follows

# PHP entry point for main application
location ~ ^/(index|get|static|errors/report|errors/404|errors/503|health_check|phpinfo)\.php$ {

After you have saved the file, you have to restart your Nginx service.

Now you should be able to access the phpinfo page your.magento.domain/phpinfo.php.

1
  • Big up you, worked a treat, everyone should be aware that placing in the pub/ folder and restarting Nginx are important notes though! Commented Nov 16, 2020 at 20:09
2

I tried it on my instance and it works nicely. I added the file in the root folder and when calling it in the browser it shows my PHP info.
Make sure you disable the cache (especially full page cache). Maybe the page is cached from a previous request.
Also if you are on nginx where .htaccess has no effect, maybe you have a rule configured that redirects everything to index.php and Magento does not find the info page.

1
  • yeah was my bad - forgot I set docroot to pub/ so obviously pub/phpinfo.php 404s
    – treyBake
    Commented Dec 17, 2018 at 9:29
0

For Magento 2 the file to load on the front end (i.e. mywebsite.com/phpinfo.php), the php file needs to go in the pub folder of the magento install. Simple as this.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.