Magento 2.4.2 – Fixing 404 Not Found After Fresh Installation

magento2.4.2

I have never had any issues with fresh install of magento before 2.4.1.
I have a new Linux VM machine (Ubuntu server 18.04).

  1. Installed PHP 7.4 , Apache and Mysql from this link Installation of
    PHP, MYSQL and APACHE

  2. Installed Composer

  3. Installed Elastic search

  4. Created composer project using this command composer create-project --repository-url=https://repo.magento.com/ magento/project-enterprise-edition=2.3.2-p1 <install-directory-name>

  5. Added sample data using php bin\magento sampledata:deploy

  6. Installed magento using following command

    php bin/magento setup:install --base-url=http://localhost/me242 --backend-frontname=admin --db-host=localhost --db-name=me242 --db-user=root --db-password='dbpas' --admin-firstname=firstname --admin-lastname=lastname --admin-email=fn@ln.com --admin-user=user --admin-password='passs!' --language=en_US --currency=USD --timezone=America/Los_Angeles --use-rewrites=1 --search-engine=elasticsearch7 --elasticsearch-host=localhost --elasticsearch-port=9200

This has worked for me fine up until 2.4.1. I am trying all possible ways to get it up and running 2.4.2 version but getting 404 error right away. The requested URL was not found on this server.

Can someone help me troubleshoot this in right direction.

Edit 1: I did not upgrade from 2.4.1 to 2.4.2. it was a fresh install.

Best Answer

It seems now Magento will only load from pub folder. By default it will not be possible to load it from the root of Magento.

So the best solution for this is to create a virtual host and point it to pub directory.

Alternative

Meanwhile, as an alternative to run this on local machine I tried something else that seems to be working fine with the default setup. Like earlier we were using the base_url as http://127.0.0.1/magento. So instead of this now we need to use http://127.0.0.1/magento/pub as the base_url. Secure and Unsecure URL needs to be setup on the basis of this.

Setting this up will avoid the issue of 404 page coming.

Note: Verified this with the default Magento only. Not sure for the projects having much complex functionalities. But you can give this a try.

We have another option without adding /pub follow below steps

1. Copy .httaccess file from pub folder and override it to root .htaccess file

2. Upload pub/index.php file to root magento directory

3. Add below code in app/etc/env.php file

'system' => [
    'default' => [
        'web' => [
            'unsecure' => [
                'base_media_url' => '{{secure_base_url}}pub/media/',
                'base_static_url' => '{{secure_base_url}}pub/static/'
            ],
            'secure' => [
                'base_media_url' => '{{secure_base_url}}pub/media/',
                'base_static_url' => '{{secure_base_url}}pub/static/'
            ]
        ]
    ]
],
Related Topic