Magento PHP-FPM cannot set Mage_Run_Code

Magento PHP-FPM cannot set Mage_Run_Code

September 24, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Magento PHP-FPM cannot set Mage_Run_Code

Magento PHP-FPM: Resolving the Mage_Run_Code Issue

Hello developers! Today, let’s take a deep dive into an intriguing issue I recently encountered while setting up multi-site for a client on a Magento server configured with PHP-FPM and MySQL. If you’re facing similar challenges or want to learn how to resolve this issue efficiently, buckle up as we explore the root cause and provide a step-by-step solution.

The Problem: Mage_Run_Code Disappears

When I first deployed the multi-site setup to the client’s server, I noticed that the MAGE_RUN_CODE was not being displayed from the $_SERVER array. Instead, it showed up as REDIRECT_MAGE_RUN_CODE. This inconsistency between the local and live environments indicated a potential server configuration issue.

To illustrate this, here are screenshots of the relevant PHP variables:

Local Environment Mage_Run_Code

As you can see from the local environment, MAGE_RUN_CODE is set correctly to comm, which matches our second store’s code.

Now, let’s take a look at what happens when we deploy this setup to the client’s server:

Server Environment Mage_Run_Code

Unfortunately, on the server side, MAGE_RUN_CODE is not set. This discrepancy led me to suspect that the issue lay in the server configuration itself.

The Temporary Workaround

Christophe provided a excellent temporary workaround for this issue:

sed -i 's/REDIRECT_MAGE_RUN_CODE/MAGE_RUN_CODE/g' /var/www/html/index.php

This command searches and replaces REDIRECT_MAGE_RUN_CODE with MAGE_RUN_CODE in the index.php file. While this solution worked perfectly, I decided to dig deeper to understand the root cause of this issue.

The Root Cause: SuExec Security Feature

After thorough investigation, I discovered that the culprit behind this behavior is a security feature called “suExec” bundled with Apache. suExec secures PHP by preventing unauthorized users from running it, which inadvertently causes the issue we experienced.

The Permanent Solution

To resolve this issue permanently and maintain the security benefits of suExec, you can follow these steps:

  1. Locate your Apache configuration file (usually named httpd.conf or apache2.conf).

  2. Find the line that contains <IfModule mod_suEXEC.c>.

  3. Add a new condition to exclude the Magento directory from suExec’s protection:

<Directory /var/www/html/magento>
    <IfModule mod_suEXEC.c>
        SuExecDisable on
    </IfModule>
</Directory>

Replace /var/www/html/magento with your actual Magento installation path.

  1. Restart the Apache server to apply the changes:
sudo systemctl restart apache2

Conclusion

In this blog post, we explored a common issue faced by Magento developers when setting up multi-site environments on PHP-FPM servers. By understanding the root cause of the MAGE_RUN_CODE disappearance and implementing the permanent solution provided above, you can ensure seamless integration between your local development environment and live server.

Remember to keep an eye on your server configurations, especially security features like suExec, when working with Magento. Proper configuration management is key to maintaining a secure and functional e-commerce platform.

Stay curious and keep coding! For more insights into Magento development and best practices, don’t forget to check out Laravel Company’s blog. Happy exploring!

Word count: 437

Database Configuration Deployment Errors

Our network