I have upload.php file in magento2 root folder.

How can i access directly www.example.com/upload.php directly in magento2?

  • want to include this file from another file or your want to call this url
    – Amit Bera
    Jul 2 '18 at 9:43
  • I want to call directly form magento2 root folder Jul 2 '18 at 9:43
  • Why would you want this? Jul 2 '18 at 9:46
  • I want my custom script there for perform custom functionality Jul 2 '18 at 9:48
  • have you tried with a die in the end of file?
    – Gagan
    Jul 2 '18 at 9:51

Create upload.php file in your magento root folder

use Magento\Framework\App\Bootstrap;
$bootstrap = Bootstrap::create(BP, $_SERVER);
$objectManager = $bootstrap->getObjectManager();
$storeManager = $objectManager->get('Magento\Store\Model\StoreManagerInterface'); 
echo $baseUrl= $storeManager->getStore()->getBaseUrl(); 
  • Not working !!! ithink it's need any htaccess rule Jul 2 '18 at 9:51
  • NO htacsess needed for script, it's custom script i'm using. May be your store not configured well prntscr.com/k1jbfe Jul 2 '18 at 9:53

The root of Magento 2 is http/pub/.

So if you upload you file there, you should be able to access it via www.example.com/upload.php

If you want to keep the file in /http/ directory and still access it, you can do it in NginX (if you use NginX). Something like this would do the trick:

# upload.php
location = /upload.php {
    alias /full/path/to/your/magentoproject/http/upload.php;

PLEASE NOTE execution of PHP files might be restricted when trying to access the file inside of the pub directory. If you want to execute the file from inside the PUB directory, try adding something like this:

   location ~* \.(php) {
     include fastcgi_params;


If you are using Apache, try following:

alias "/upload.php" "/full/path/to/your/magentoproject/http/upload.php"

And reload your Apache services.

  • Not working !!! have tried Jul 2 '18 at 9:46
  • Are you using Apache or NginX?
    – Greg
    Jul 2 '18 at 9:52
  • apache @Bare Feet Jul 2 '18 at 9:57
  • Updated the answer.
    – Greg
    Jul 2 '18 at 10:37

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