Zend certified PHP/Magento developer

Installation of Magento 2 in Ubuntu loaclhost

Hi I have been trying to install Magento 2 on my Ubuntu localhost. I followed the below-mentioned command.

 sudo composer create-project --repository-url=https://repo.magento.com/ magento/project-community-edition mag2

Then

cd /var/www/html/mag2

sudo find var generated vendor pub/static pub/media app/etc -type f -exec chmod g+w {} +
sudo find var generated vendor pub/static pub/media app/etc -type d -exec chmod g+ws {} +
sudo chown -R user_name:www-data .
sudo chmod u+x bin/magento

Then running.

     sudo php bin/magento setup:install 
--base-url=http://localhost/magento2 
--db-host=localhost 
--db-name=magento2 
--db-user=magento2 
--db-password=<pasword> 
--admin-firstname=admin 
--admin-lastname=admin 
--admin-email=admin@admin.com 
--admin-user=admin 
--admin-password=admin123 
--language=en_US 
--currency=USD 
--timezone=America/Chicago 
--use-rewrites=1 
--search-engine=elasticsearch7 
--elasticsearch-host=localhost 
--elasticsearch-port=9200

But when I go the `http://localhost/magento2/. I’m getting below mention error on my browser.

<?php
/**
 * Public alias for the application entry point
 *
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */

use MagentoFrameworkAppBootstrap;

try {
    require __DIR__ . '/../app/bootstrap.php';
} catch (Exception $e) {
    echo <<<HTML
<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 = Bootstrap::create(BP, $_SERVER);
/** @var MagentoFrameworkAppHttp $app */
$app = $bootstrap->createApplication(MagentoFrameworkAppHttp::class);
$bootstrap->run($app);

I try installing it by vhost which didn’t work. I check all the dependences of Magento 2 like Apache2, Php and its modules, elasticsearch all the packages are working fine.

Can someone help me with resolving and debugging this issue?
One more thing when I ran the composer installation it’s not asking for a Username or password as mentioned in the installation guide.