Moving Magento from subdirectory to root causes 'failed to open stream' errors

Moving Magento from subdirectory to root causes 'failed to open stream' errors

August 17, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Moving Magento from subdirectory to root causes 'failed to open stream' errors

Resolving Magento ‘Failed to Open Stream’ Errors After Subdirectory to Root Migration

Moving an e-commerce platform like Magento can be a complex task, especially when dealing with subdirectory migrations. I recently encountered this issue while helping a client move their development instance from /dev to the root directory (/public_html). Despite updating necessary configuration files and clearing caches, the system kept referencing the old /dev directory.

Understanding the Error Log

Let’s first dissect the error log message you provided:

PHP Warning: include_once(Mage/Core/functions.php): failed to open
stream: No such file or directory in /httpdocs/dev/app/Mage.php on line 49

PHP Warning: include_once(): Failed opening 'Mage/Core/functions.php'
for inclusion (include_path='/httpdocs/dev/app/code/local:/httpdocs/dev/app/code/community:/httpdocs/dev/app/code/core:/httpdocs/dev/lib:.:')
in /httpdocs/dev/app/Mage.php on line 49

PHP Warning: include_once(Varien/Autoload.php): failed to open stream:
No such file or directory in /httpdocs/dev/app/Mage.php on line 50

PHP Warning: include_once(): Failed opening 'Varien/Autoload.php' for
inclusion (include_path='/httpdocs/dev/app/code/local:/httpdocs/dev/app/code/community:/httpdocs/dev/app/code/core:/httpdocs/dev/lib:.:')
in /httpdocs/dev/app/Mage.php on line 50

PHP Fatal error: Class 'Varien_Autoload' not found in
/httpdocs/dev/app/Mage.php on line 53

This log indicates that Magento is still trying to include files from the old /dev directory, which no longer exists at the root level. The include path specified in these warnings is problematic.

Step-by-Step Solution

To resolve this issue:

  1. Update the Include Path: Open your index.php file located in the root directory (/public_html/index.php). This file controls the initial bootstrapping of Magento.
// Ensure that $includePath reflects the new directory structure
$includePaths = array();
if (!ini_get('include_path')) {
    $includePaths[] = '.';
}
$includePaths[] = 'app/code/local';
$includePaths[] = 'app/code/community';
$includePaths[] = 'app/code/core';
$includePaths[] = 'lib';
set_include_path(implode(PATH_SEPARATOR, $includePaths));

Replace the existing $includePaths values with the ones provided above. This ensures that Magento looks for its files in the correct directories of your new root installation.

  1. Clear All Cache Directories: Even after clearing /var/cache and /var/session, some cache files might still persist in other locations like /var/view_cache or /tmp.
rm -rf var/*

// Ensure that all tmp files are deleted
rm -f tmp/*
  1. Reindex All Data: After updating the include path and clearing caches, reindex your data to ensure the database is synchronized with the new file locations.
php shell/indexer.php --reindexall
  1. Check .htaccess File: Ensure that your .htaccess file contains the correct RewriteBase directive for the root directory:
RewriteBase /public_html/

Verifying the Solution

After implementing these steps, revisit your error log to confirm the changes have taken effect. The errors related to failed stream opens should now be resolved, indicating that Magento is correctly referencing the files in its new location.

Remember, when dealing with Magento migrations, always test thoroughly and ensure you have a reliable backup of your data before proceeding with any major changes.

If you’re looking for more in-depth guides on Magento development and migration strategies, feel free to explore our Magento tutorials at Laravel Company. They provide detailed walkthroughs on common tasks faced by Magento developers.

Happy coding! Let me know if you have any further questions.

Cache Configuration Errors CLI

Our network