0

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

3
  • did u tried downgrading ur php version – Pramod Aug 16 '20 at 15:02
  • No i did not, i am beginner in this field and i do not know what is the right version – S J Aug 16 '20 at 15:06
  • did the updated ans works for you? – Pramod Aug 17 '20 at 6:51
1

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

11
  • I am follow your instructions, and i don't know if the server read the file properly or not, but now shows a blank page, no errors appear, i don't know where is the problem. – S J Aug 17 '20 at 8:11
  • where exactly ur getting the blank page? while accessing admin panel? – Pramod Aug 17 '20 at 8:11
  • where access same address localhost.com/magento2 to get Magento Setup Wizard as the following:link – S J Aug 17 '20 at 8:17
  • please confirm that its not the permission issue if yes then run this command sudo chmod -R 777 var/www/html/magento2 change the location according to your requirement – Pramod Aug 17 '20 at 8:18
  • I don't know how to check if the issue is permission issue, anyway I used this command but nothing changed – S J Aug 17 '20 at 8:28
0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.