I have an problem about magento 2.4.2 Installed magento 2.4.2 using Composer-CLI. But I can't access magento homepage (http://localhost:8888/magento2)
The requested URL /pub/ was not found on this server.
My .htaccess file
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
Changed .htaccess file
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
If I change the RewriteRule from .* /pub/0ドル [L] to .* pub/0ドル [L] , i can see magento home page with some errors.
The page you requested was not found, and we have a fine guess why. If you typed the URL directly, please make sure the spelling is correct. If you clicked on a link to get here, the link is outdated.
How can solve this problem?
-
Change your webroot to the "pub" directory in the apache config file.Amit Saini– Amit Saini2021年03月04日 09:23:16 +00:00Commented Mar 4, 2021 at 9:23
-
@AmitSaini How to do ? Please show here or post your answer.Msquare– Msquare2021年03月04日 09:36:08 +00:00Commented Mar 4, 2021 at 9:36
-
@Said Setup apache document root like this devdocs.magento.com/guides/v2.4/install-gde/tutorials/…Amit Saini– Amit Saini2021年03月04日 09:44:40 +00:00Commented Mar 4, 2021 at 9:44
-
Using RewriteRule .* pub/0ドル [L] instead of RewriteRule .* /pub/0ドル [L] worked for me... Home page is getting loaded properly but all inner pages are throwing error like 404zuber bandi– zuber bandi2021年08月15日 07:11:19 +00:00Commented Aug 15, 2021 at 7:11
2 Answers 2
I think your problem is already known issue when using 2.4.2 for the first time and with a setup that doesn't point to /pub folder (the webserver doesn't know that it has to serve the requests from the /pub folder)
I suggest you create a virtual host dedicated solely to your magento 2.4.2 instance:
- enter/ create the Apache config by running
vim /etc/apache2/sites-available/000-default.conf - update the 'DocumentRoot' directive to point to 'pub' folder (note that you need to replace '/var/www/html/magento2ce' with the path to your magento installation):
<VirtualHost *:80>
ServerName magento.local
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html/magento2ce/pub
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<Directory "/var/www/html">
AllowOverride all
</Directory>
</VirtualHost>
3.a. if you didn't have the virtual host, then run sudo a2ensite 000-default.conf, otherwise, skip this step.
3.b. restart Apache by running systemctl restart apache2 command
3.c. if you didnt have the virtual host before, then add the new website to your hosts vim /etc/hosts and add the line 127.0.0.1 magento.local inside it
- update the magento base URL - I see you appended a directory name to your server’s hostname when you installed Magento (
http://localhost:8888/magento2), you’ll need to remove it and change it to the virtual host name. This can be achieved by logging into the database and running the command:
UPDATE core_config_data SET value='http://magento.local/' WHERE path='web/unsecure/base_url';
UPDATE core_config_data SET value='http://magento.local/' WHERE path='web/secure/base_url';
- make sure you are serving the requests from the 'pub' folder by checking the 'env.php' file, it should contain the following piece:
'directories' => [
'document_root_is_pub' => true
]
Source: the documentation https://devdocs.magento.com/guides/v2.4/install-gde/tutorials/change-docroot-to-pub.html.
-
Please give solution not linkMsquare– Msquare2021年03月04日 10:14:52 +00:00Commented Mar 4, 2021 at 10:14
-
I updated my answer, but surely if someones checks the link will find the same steps.Diana– Diana2021年03月04日 10:29:50 +00:00Commented Mar 4, 2021 at 10:29
-
I install in to my local pc and there are so many magento installed, so how to manage multiple magento setup with magento 2.4.2Msquare– Msquare2021年03月04日 10:33:04 +00:00Commented Mar 4, 2021 at 10:33
-
for the m2.4.2 install you will have to have a dedicated virtual hostDiana– Diana2021年03月04日 10:34:59 +00:00Commented Mar 4, 2021 at 10:34
-
i am not understanding what you say. please explain bit more.Msquare– Msquare2021年03月04日 10:43:48 +00:00Commented Mar 4, 2021 at 10:43
You can create a Virtual Hosts following this instruction: https://www.digitalocean.com/community/tutorials/how-to-set-up-apache-virtual-hosts-on-ubuntu-18-04-quickstart
Explore related questions
See similar questions with these tags.