0

I just installed Magento 2, it shown the success page result however the homepage and admin is not found.

enter image description here

404 Not Found The requested URL was not found on this server.

Apache/2.4.46 (Win64) OpenSSL/1.1.1j PHP/7.4.16 Server at localhost Port 80

enter image description here enter image description here

Magento 2.4.2 Window10 64 XAMPP 3.2.4 Elasticsearch-7.11.2 Composer 2.0.11

6 Answers 6

8

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/magento24/pub"
    ServerName yourname.magento.com
</VirtualHost>

paste this code at the bottom of the file.

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.

 127.0.0.1  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 http://yourname.magento.com/ and

admin page http://yourname.magento.com/admin

3
  • Your solution is the most perfect, it really works normally. I want to give you 100 likes.
    – Angelo
    Commented Mar 25, 2021 at 13:09
  • Thank You Angelo. I am happy that it helped you. Commented Mar 31, 2021 at 9:53
  • 1
    I don't undestand, why I can not use localhost/magento2 ?
    – Perry
    Commented May 12, 2022 at 6:43
2

This is not a Magento issue, most likely your question will be closed.

This seems to be a XAMPP issue. You will have to set up a virtual host in your XAMPP.

Learn how to setup Virtual Host in your XAMPP here: https://www.wpwhitesecurity.com/multiple-websites-xampp/

After setting virtual host, don't forget to add your domain in to your hosts file. https://www.wpwhitesecurity.com/windows-hosts-file/

1
  • Thanks Adarsh Khatri, I updated the issue.
    – Angelo
    Commented Mar 23, 2021 at 8:23
0

This issue is caused by the fact that you don't have a dedicated virtual host for your magento installation. As of Magento 2.4.2, the document root has to be point to the <magento_root>/pub folder otherwise you won't be able to access your shop's frontend or backend properly.

So if you don't have a dedicated virtual host, you can't tell your webserve how to serve the requests from the /pub folder.

Please follow this thread frontend and admin not working magento 2.4.2 upgrade in order to solve the issue, I gave more details there and the other comments and answers are also helpful.

Good luck!

0

estou tentanto instalar o magento 2 no win 10 sem sucesso, alguém pode me dizer o passo a passo da instalação? Obrigadu!

1
  • You should use English to reply. Otherwise no one understand.
    – PY Yick
    Commented Nov 12, 2021 at 2:49
0

Simply create .htaccess file on your root and copy that from Magento 2 directory CLICK HERE FOR THE FILE choose the version that you are using. Then create .htaccess inside pub and copy that also.

It will work fine

Run the below command:

sudo php bin/magento setup:upgrade && sudo php bin/magento setup:di:compile && sudo php bin/magento setup:static-content:deploy -f && sudo chmod 777 -R pub/* var/* generated/* && sudo php bin/magento cache:clean
0

It is not always necessary to change the host:

C:\Windows\System32\drivers\etc\hosts

It would also be enough to simply use a subdomain for localhost:

D:\xampp\apache\conf\extra\httpd-vhosts.conf

<VirtualHost *:80>
    DocumentRoot "D:/xampp/htdocs/magento2/pub"
    ServerName magento2.localhost
</VirtualHost>

Restart Apache after changes

Magento Config: web/unsecure/base_url = http://magento2.localhost/

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.