ubuntu16.04系统使用magento的19.24版本,用apache2.4.18+php7.1配置完环境后,打开站点却报了以下的错误。

Notice: Array to string conversion  in /var/www/html/magento1924/app/code/core/Mage/Core/Model/Layout.php on line 555

#0 /var/www/html/magento1924/app/code/core/Mage/Core/Model/Layout.php(555): mageCoreErrorHandler(8, 'Array to string...', '/var/www/html/m...', 555, Array)
#1 /var/www/html/magento1924/app/code/core/Mage/Core/Controller/Varien/Action.php(390): Mage_Core_Model_Layout->getOutput()
#2 /var/www/html/magento1924/app/code/core/Mage/Cms/Helper/Page.php(137): Mage_Core_Controller_Varien_Action->renderLayout()
#3 /var/www/html/magento1924/app/code/core/Mage/Cms/Helper/Page.php(52): Mage_Cms_Helper_Page->_renderPage(Object(Mage_Cms_IndexController), 'home')
#4 /var/www/html/magento1924/app/code/core/Mage/Cms/controllers/IndexController.php(45): Mage_Cms_Helper_Page->renderPage(Object(Mage_Cms_IndexController), 'home')
#5 /var/www/html/magento1924/app/code/core/Mage/Core/Controller/Varien/Action.php(418): Mage_Cms_IndexController->indexAction()
#6 /var/www/html/magento1924/app/code/core/Mage/Core/Controller/Varien/Router/Standard.php(254): Mage_Core_Controller_Varien_Action->dispatch('index')
#7 /var/www/html/magento1924/app/code/core/Mage/Core/Controller/Varien/Front.php(172): Mage_Core_Controller_Varien_Router_Standard->match(Object(Mage_Core_Controller_Request_Http))
#8 /var/www/html/magento1924/app/code/core/Mage/Core/Model/App.php(365): Mage_Core_Controller_Varien_Front->dispatch()
#9 /var/www/html/magento1924/app/Mage.php(683): Mage_Core_Model_App->run(Array)
#10 /var/www/html/magento1924/index.php(85): Mage::run('', 'store')
#11 {main}

apache的error.log文件报了以下的错

PHP Fatal error:  Uncaught Error: Function name must be a string in /var/www/html/magento1924/app/code/core/Mage/Core/Model/Layout.php:555\nStack trace:\n#0 /var/www/html/magento1924/app/code/core/Mage/Core/Controller/Varien/Action.php(390): Mage_Core_Model_Layout->getOutput()\n#1 /var/www/html/magento1924/app/code/core/Mage/Cms/Helper/Page.php(137): Mage_Core_Controller_Varien_Action->renderLayout()\n#2 /var/www/html/magento1924/app/code/core/Mage/Cms/Helper/Page.php(52): Mage_Cms_Helper_Page->_renderPage(Object(Mage_Cms_IndexController), 'home')\n#3 /var/www/html/magento1924/app/code/core/Mage/Cms/controllers/IndexController.php(45): Mage_Cms_Helper_Page->renderPage(Object(Mage_Cms_IndexController), 'home')\n#4 /var/www/html/magento1924/app/code/core/Mage/Core/Controller/Varien/Action.php(418): Mage_Cms_IndexController->indexAction()\n#5 /var/www/html/magento1924/app/code/core/Mage/Core/Controller/Varien/Router/Standard.php(254): Mage_Core_Controller_Varien_Action->dispatch('index')\n#6 /var/www/html/magento1924/app/code/core/Mage/C in /var/www/html/magento1924/app/code/core/Mage/Core/Model/Layout.php on line 555

查看了错误的文件代码,发现是用array的方式去使用了字符串的变量,具体原因不清楚,估计是php7.1有对变量类型做了强限制,这情况下,也不可能去修改magento的核心代码来适应php7.1,除了这一个地方,可能也还会有其它地方。记得M1好像用不了那么高的php版本,所以用低一点的php5.6版本来试试看吧。

先进行php5.6安装,如下:

sudo add-apt-repository ppa:ondrej/php && sudo apt-get update
sudo apt-get install -y php5.6-dev php5.6-common php5.6-mbstring php5.6-bcmath php5.6-mcrypt php5.6-mysql php5.6-xml php5.6-gd php5.6-curl php5.6-json php5.6-fpm php5.6-zip php5.6-mcrypt libapache2-mod-php5.6 php5.6-intl php5.6-soap

#开启重写转向
sudo a2enmod rewrite
sudo a2enmod headers

#开启代理模块
sudo a2enmod proxy proxy_fcgi

#开机启用php5.6
sudo systemctl enable php5.6-fpm
#启动php5.6-fpm
sudo service php5.6-fpm start

进行站点配置,sudo vim /ect/apache/site-enable/000-default.conf,配置如下:

<VirtualHost *:81>
        ServerName magento.yroot.win

        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/html/magento1924
        
        #加上这一段,使用php5.6-fpm方式加载php文件,要不然,还是会使用php7.1
        <FilesMatch \.php$>
           SetHandler "proxy:unix:/run/php/php5.6-fpm.sock|fcgi://localhost"
        </FilesMatch>

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
使用apache代理方式调用php5.6-fpm

最后,重启apache2,访问网站,正常显示了,但分类页及详情页面访问却是404结果,在地址栏加上index.php后,就能正常显示,原因明确了,apache的rewrite重写功能未配置完成,再次修改以下文件sudo vim /etc/apache2/apache2.conf,找到AllowOverride None,修改为AllowOverride All,如下:

<Directory />
        Options FollowSymLinks
        #AllowOverride None
        AllowOverride All
        Require all denied
</Directory>

<Directory /usr/share>
        #AllowOverride None
        AllowOverride All
        Require all granted
</Directory>

<Directory /var/www/>
        Options Indexes FollowSymLinks
        #AllowOverride None
        AllowOverride All
        Require all granted
</Directory>

最后重启apache2,页面访问正常了。

关于apache2的代理方式加载php不同的版本,可见以下文章

ubuntu php多版本共存切换,为每个站点设置不同的php版本
做开发时,由于本机开发的php版本跟线上发布的php版本不一致,很容易在上线后,发现因版本的影响导致一些bug,但又不想重新去换本机的php版本,那么多版本共存就很方便了!有必要时,切换到指定版本测试下,没问题再上线就OK了! LMAP环境安装记录如下: sudo apt-get install -y apache2 安装:mysql5.7(ubuntu16.04自带)sudo apt instal -y mysql-server mysql-client libmysqlclient-dev mysql-workbench 安装:php5.6sudo add-apt-reposi…