简体   繁体   中英

Magento PHP-FPM cannot set Mage_Run_Code

I recently came across a issue when I am trying to set up multi site for a client. Everything works fine from my local, but after I deploy to the server and found out the MAGE_RUN_CODE is not displayed from the $_SERVER , instead it is displaying REDIRECT_MAGE_RUN_CODE

the store code for the second store is : comm

在此处输入图片说明

在此处输入图片说明

The server configuration is PHP-FPM + Mysql, it looks to me that Mage_Run_Code is not set. Because everything is working fine on my local, therefore, I think it is a server configuration issue.


Christophe has posted a perfect work around this, and it works perfectly.

I think I found the cause of this issue. it is the "suExec" in the Apache which securing the PHP that cause this issue.

To run magento under PHP-FPM environment, we replace (in index.php)

/* Store or website code */
$mageRunCode = isset($_SERVER['MAGE_RUN_CODE']) ? $_SERVER['MAGE_RUN_CODE'] : '';

/* Run store or run website */
$mageRunType = isset($_SERVER['MAGE_RUN_TYPE']) ? $_SERVER['MAGE_RUN_TYPE'] : 'store';

By

/* Store or website code */
$mageRunCode = isset($_SERVER['REDIRECT_MAGE_RUN_CODE']) ?
$_SERVER['REDIRECT_MAGE_RUN_CODE'] :
(isset($_SERVER['MAGE_RUN_CODE']) ? $_SERVER['MAGE_RUN_CODE'] : '');
//$mageRunCode = isset($_SERVER['MAGE_RUN_CODE']) ? $_SERVER['MAGE_RUN_CODE'] : '';

/* Run store or run website */
$mageRunType = isset($_SERVER['REDIRECT_MAGE_RUN_TYPE']) ?
$_SERVER['REDIRECT_MAGE_RUN_TYPE'] :
(isset($_SERVER['MAGE_RUN_TYPE']) ? $_SERVER['MAGE_RUN_TYPE'] : 'store');/* Store or website code */

Here is a clean patch you can add to the top of your Magento2 index.php and pub/index.php files, or simply include it in app/bootstrap.php . This effectively fixes the issues when running Magento behind PHP-FPM.

This patch will fix any $_SERVER environment variables which have the REDIRECT_ prefix.

// Fix Server Environment Variables when Using PHP-FPM
// Only run if we detect a known server variable
if (isset($_SERVER['REDIRECT_MAGE_RUN_CODE'])) {
    foreach ($_SERVER as $key => &$value) {
        if (substr($key, 0, 9) === 'REDIRECT_') {
            $_SERVER[substr($key, 9)] = $value;
        }
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM