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 [email protected] --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.


11 Answers 11


Do not move to 2.4.2 without careful planning if you aren't already using the "server root is pub/" setup.

In the Magento 2.4.2 deployment the whole logic is changed to move the site document root to the pub subfolder. It is not mentioned in the changes at all (at least it wasnt 2 weeks after release) and the change is hidden in a "peformance" commit so it might be a surprise. The "installation" instructions have changed to say the pub subfolder must be the server root but there is no advice in the upgrade instructions or release notes.

Any custom rewrites that might have been in your magento main folder must be moved to the htaccess file in the pub folder

If your magento is installed in a subfolder, upgrade will break it. You either have to change your site to the new architecture (and stop using a subfolder - that's what I did in the end), experiment trial and error with rewrites to make it work, or manually revert the .htaccess out of the pub folder.

If you had other applications installed in subfolders in the site, it will also break them.

Your options

  1. modify your site to use the new architecture (this means losing a path or making it virtual)

  2. revert those changes (at every upgrade)

  3. depending on server, clever rewrite rules might be possible? (see frontend and admin not working magento 2.4.2 upgrade i'm partly there but not 100%)


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.


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 So instead of this now we need to use 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/'
  • thanks Kamal, it works for me. Commented Aug 29, 2021 at 10:20
  • @wakarAhamad Great! Commented Aug 31, 2021 at 5:23

This .htaccess rule in magento base folder works for me (remove the slash before pub/):

RewriteEngine on
RewriteCond %{REQUEST_URI} !^pub/
RewriteCond %{REQUEST_URI} !^/setup/
RewriteCond %{REQUEST_URI} !^/update/
RewriteCond %{REQUEST_URI} !^/dev/
RewriteRule .* pub/$0 [L]
DirectoryIndex index.php
  • this works for dev installation (Apache + centos 7) Commented Jun 16, 2021 at 14:39
  • its not work if we remove index.php from url. Is work for you ? Commented Jul 28, 2021 at 15:13

The Magento 2.4 is missing the index.php file from root folder as the standard process is to point your web server (nginx/apache) to pub/ folder by default where the index.php file is located.

Jus to be sure the index.php file is not at fault - copy it from pub/ into the root directory.

The proper solution is to make sure the web server root directory is in pub/ folder.

  • please consider marking your own answer as solution so others can see it too.
    – Diana
    Commented Mar 4, 2021 at 11:52


Well what a headache, it seems version 2.4.2 is a quarterly update and not the full package.

You will need to download version 2.4.1 and then update to version 2.4.2.

I have had the same headache for a while now seems to be resolved now.

How to fix using composer while using ubuntu 20.04 (new install only) please read config and replace missing details!

Using Terminal: Enter: composer create-project --repository-url=https://repo.magento.com/ magento/project-community-edition=2.4.1 /var/www/html/www.YOUR_SITE.com

Once downloaded install using the (cli) command line installer like so!

cd /var/www/html/www.YOUR_SITE.com

bin/magento setup:install
[email protected]
--elasticsearch-host=localhost \ --elasticsearch-port=9200

Once installed run:

composer require magento/product-community-edition=2.4.2

and then run

composer update.

That should fix all your issues...

:( Sad time i rebuild my server like five times next time vm ware!


Step 1: -

We need to set document root to pub, to do this go to file C:\xampp\apache\conf\extra\httpd-vhosts.conf

<VirtualHost *:80>
    DocumentRoot "C:/xampp/htdocs/magento2/pub"
    ServerName yourname.magento.com

paste this code at the bottom of the file.

DocumentRoot - set where your magento pub directory is yourname.magento.com - this is domain name which you set as per your wish. So now you need to access magento frontend and admin with base url "yourname.magento.com".

Step 2:-

Now lets edit C:\Windows\System32\drivers\etc\hosts file and add the below line at the bottom of the file.  yourname.magento.com

Step 3: - Update the base URL:

Go to our magento database and run below command

  UPDATE core_config_data SET value='http://yourname.magento.com/' WHERE path='web/unsecure/base_url';

Step 4:- Update the app/etc/env.php file

The following node needs to be appended to the env.php file.

'directories' => [
    'document_root_is_pub' => true

Step 5 : - Switch to developer mode.

php bin/magento deploy:mode:set developer
php bin/magento cache:flush

Hurray !!! All done .... Lets check your homepage and admin page.

  • I followed your all steps but unfortunately couldn't find C:\xampp\apache\conf\extra\httpd-vhosts.conf as I m using centos7 linux server. Can you assist me for this - [https://magento.stackexchange.com/questions/337273/frontend-and-backend-is-not-working-magento-2-4-2-internal-server-error] Commented May 18, 2021 at 12:30

OK I had this issue and it took me a day to figure it out but in my case it was quite simple in the end. Look at your .htaccess file and look for rewriteBase sometimes when you upgrade you end up with

rewriteBase magento/ 

it only needs

rewriteBase /

Hope this helps

  • That is assuming of course magento is in the route folder Commented Feb 28, 2021 at 22:01
  • by root do you mean /root or /var/www/html Commented Mar 1, 2021 at 15:49

I had also faced same problem, tried every available tricks and the solutions on the internet, but got no success. In recent Magento 2.4.2 version, index.php and static folder are moved inside the pub folder. I have tried to copy index.php file from pub folder to root folder, it worked but all the CSS and JS files failed to open and gave 404 file not found error.

Then I have copied static folder in the root folder from the pub/static, and it did the trick to load the frontend as well as admin of the Magento. I don't know the exact solution and this solution is correct or not, but hope this will resolve your issue for Magento 2.4.2. latest version.


I am facing the same problem on Magento 2.4.3, here is my solution

I have url for my website "www.mywebsite.fr//" (fr/en/nl)

  1. create a file in root magento "nginx_map.conf"

map $host$request_uri $MAGE_RUN_CODE {
    default admin;
    ~^www\.mywebsite\.fr/fr/ "site_fr";
    ~^www\.mywebsite\.fr/en/ "site_en";
    ~^www\.mywebsite\.fr/nl/ "site_nl";

# rewrite requets_uri if uri start with lang
map $request_uri $REQUEST_URI2 {
    default $request_uri;
    ~^/(fr|en|nl)/(?<p>.*) "/$p";

# extract lang
map $request_uri $CURRENT_LANG {
    default "";
    ~^/(?<lang>fr|en|nl)/ "$lang";

  1. my nginx vhost file (sites.conf)

include <path to magento>/nginx_map.conf;

server {
    listen 80;
    server_name www.mywebsite.fr;

    set $MAGE_ROOT <path to magento>;
    set $MAGE_MODE developer;
    set $MAGE_RUN_TYPE store;

    include <path to magento>/nginx.conf;

  1. Nginx modification (nginx.conf magento file), put it before "location /.user.ini {"

location /fr/ {
    rewrite /fr/(.*)$ /$1 last;
location /en/ {
    rewrite /en/(.*)$ /$1 last;
location /nl/ {
    rewrite /nl/(.*)$ /$1 last;

in location "location ~ ^/(index|get|static|errors/report|errors/404|errors/503|health_check|info).php$ {", add this line after "include fastcgi_params;"

fastcgi_param  MAGE_RUN_TYPE $MAGE_RUN_TYPE;
fastcgi_param  MAGE_RUN_CODE $MAGE_RUN_CODE;
fastcgi_param  REQUEST_URI $REQUEST_URI2;

  1. restart nginx

  2. create a module to break base_url_checker, you need to create registration.php, etc/module.xml files

  • create file : {namespace}/{module}/Plugin/BaseUrlChecker.php

use Magento\Store\Model\BaseUrlChecker as Subject;

class BaseUrlChecker
    public function afterExecute(
        Subject $subject,
    ) {
        if ($result === false) {
            if (isset($_SERVER['CURRENT_LANG']) && in_array($_SERVER['CURRENT_LANG'], ['fr', 'en', 'nl'])) {
                $result = true;

        return $result;

  • create file : {namespace}/{module}/etc/di.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <type name="Magento\Store\Model\BaseUrlChecker">
        <plugin name="<namespace>_<module>_baseurlchecked" type="<namespace>/<module>\Plugin\BaseUrlChecker"/>

After that "normaly" it's working :)


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/'

Below is the solution I used (based on https://meetanshi.com/blog/install-magento-2-4-2-on-localhost-using-xampp/ that was shared on https://community.magento.com/t5/Installing-Magento-2-x/What-s-next-after-running-magento-setup-install/td-p/489276).

Copy the index.php and .htaccess files from the pub folder and paste into the root directory.

In the pasted index.php file, replace

require __DIR__ . '/../app/bootstrap.php';


require __DIR__ . '/app/bootstrap.php';

Insert the below four rows in the core_config_data table (path / value columns).

web/secure/base_static_url    http://localhost/magento/pub/static/
web/unsecure/base_static_url    http://localhost/magento/pub/static/
web/secure/base_media_url    http://localhost/magento/pub/media/
web/unsecure/base_media_url    http://localhost/magento/pub/media/

Execute the command php bin/magento cache:flush.

You should also make sure URL rewriting is enabled, for example with Apache on Debian with the command a2enmod rewrite and by setting AllowOverride All for the /var/www/ directory in /etc/apache2/apache2.conf.

For 404 errors on the CSS / JavaScript files, see the answer Static files version folders not found hence design collapsed and getting 404 for all css and js.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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