Question

At final phase to install Magento 2, When i went to access my address http://localhost.com/magento2 i got an error cause of index.php file, my address does not read the file as php file

so i got the following error

run($app); * -------------------------------------------- * * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ try { require __DIR__ . '/app/bootstrap.php'; } catch (/Exception $e) { echo <<
Autoload error

{$e->getMessage()}
HTML; exit(1); } $bootstrap = \Magento\Framework\App\Bootstrap::create(BP, $_SERVER); /** @var \Magento\Framework\App\Http $app */ $app = $bootstrap->createApplication(\Magento\Framework\App\Http::class); $bootstrap->run($app); 

and the original file code is

<?php

/*
 * Application entry point
 *
 * Example - run a particular store or website:
 * --------------------------------------------
 * require __DIR__ . '/app/bootstrap.php';
 * $params = $_SERVER;
 * $params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE] = 'website2';
 * $params[\Magento\Store\Model\StoreManager::PARAM_RUN_TYPE] = 'website';
 * $bootstrap = \Magento\Framework\App\Bootstrap::create(BP, $params);
 * \/** @var \Magento\Framework\App\Http $app *\/
 * $app = $bootstrap-createApplication(\Magento\Framework\App\Http::class);
 * $bootstrap->run($app);
 * --------------------------------------------
 *
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */

try {
    require __DIR__ . '/app/bootstrap.php';
} catch (/Exception $e) {
    echo <<<HTML
<meta content="text/html;charset=utf-8" http-equiv="Content-Type">
<meta content="utf-8" http-equiv="encoding">
<div style="font:12px/1.35em arial, helvetica, sans-serif;">
    <div style="margin:0 0 25px 0; border-bottom:1px solid #ccc;">
        <h3 style="margin:0;font-size:1.7em;font-weight:normal;text-transform:none;text-align:left;color:#2f2f2f;">
        Autoload error</h3>
    </div>
    <p>{$e->getMessage()}</p>
</div>
HTML;
    exit(1);
}

$bootstrap = \Magento\Framework\App\Bootstrap::create(BP, $_SERVER);
/** @var \Magento\Framework\App\Http $app */
$app = $bootstrap->createApplication(\Magento\Framework\App\Http::class);
$bootstrap->run($app);

after my researching i got that my address does not read/run the php file as is, it is read/run it as html file, so my question is: how can i let the server run the php file as is ?

additional info : my file is in /var/www/html/magento2/index.php

php version is php 7.4.3

Was it helpful?

Solution 2

The error solved, what i do is removing the Apache2 Virtual Host and reinstalling it ,then there's syntax error here :

try {
    require __DIR__ . '/app/bootstrap.php';
} catch (/Exception $e) {  <-------------- here that '/' slash .
    echo <<<HTML
<meta content="text/html;charset=utf-8" http-equiv="Content-Type">
<meta content="utf-8" http-equiv="encoding">
<div style="font:12px/1.35em arial, helvetica, sans-serif;">
    <div style="margin:0 0 25px 0; border-bottom:1px solid #ccc;">
        <h3 style="margin:0;font-size:1.7em;font-weight:normal;text-transform:none;text-align:left;color:#2f2f2f;">
        Autoload error</h3>
    </div>
    <p>{$e->getMessage()}</p>
</div>
HTML;
    exit(1);
}

by removing it, the error disappeared.

OTHER TIPS

PHP ~7.4.0 Magento 2.x.x can be installed with 7.3, but it is not tested or recommended. It is intended for upgrading from Magento 2.3.x to Magento 2.4.0.

There is a bug in PHP 7.4.2 which causes some messages to not render properly. Magento recommends using other versions of 7.4.

Source:- https://devdocs.magento.com/guides/v2.4/install-gde/system-requirements-tech.html you can visit the link to learn more about magento technology requirement

UPDATE:- follow this terminal command to install php other version

sudo apt-get install -y php7.0 libapache2-mod-php7.0 php7.0 php7.0-common php7.0-gd php7.0-mysql php7.0-mcrypt php7.0-curl php7.0-intl php7.0-xsl php7.0-mbstring php7.0-zip php7.0-bcmath php7.0-iconv php7.0-soap

remember to change php version 7.0 with your required version 7.3 or 7.2 and then just disable php 7.4 and enable php 7.3 or 7.2 using below commands

sudo a2dismod php7.4 
 sudo a2enmod php7.2
 sudo service apache2 restart

UPDATE:- SET PERMISSION LIKE THIS THEN

sudo chown www-data:www-data -R /var/www/html/magento2

sudo chmod 777 -R /var/www/html/magento2

please note magento2 will be your root directory so replace it with yours

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top