Magento 2安装问题:尝试加载管理页面时出现404错误


11

我已经在wamp服务器上成功安装了Magento 2,但是在加载管理页面时却遇到了一个小问题,因为它为我提供了404。此外,在加载其主页时,默认情况下我使用的亮度主题不适用而是给我以下错误:

Failed to load resource: the server responded with a status of 404 (Not Found)
http://127.0.0.1/test1/pub/static/frontend/Magento/luma/en_US/mage/calendar.css     
Failed to load resource: the server responded with a status of 404 (Not Found)
http://127.0.0.1/test1/pub/static/frontend/Magento/luma/en_US/css/styles-m.css 
Failed to load resource: the server responded with a status of 404 (Not Found)
http://127.0.0.1/test1/pub/static/frontend/Magento/luma/en_US/css/styles-l.css 
Failed to load resource: the server responded with a status of 404 (Not Found)
http://127.0.0.1/test1/pub/static/frontend/Magento/luma/en_US/css/print.css 
Failed to load resource: the server responded with a status of 404 (Not Found)
http://127.0.0.1/test1/pub/static/frontend/Magento/luma/en_US/images/logo.svg    
Failed to load resource: the server responded with a status of 404 (Not Found)
http://127.0.0.1/test1/pub/static/frontend/Magento/luma/en_US/css/styles-m.css 
Failed to load resource: the server responded with a status of 404 (Not Found)
http://127.0.0.1/test1/pub/static/frontend/Magento/luma/en_US/css/styles-l.css 
Failed to load resource: the server responded with a status of 404 (Not Found)
http://127.0.0.1/test1/pub/static/frontend/Magento/luma/en_US/requirejs/require.js 
Failed to load resource: the server responded with a status of 404 (Not Found)
http://127.0.0.1/test1/pub/static/frontend/Magento/luma/en_US/css/print.css     
Failed to load resource: the server responded with a status of 404 (Not Found)
http://127.0.0.1/test1/pub/static/frontend/Magento/luma/en_US/mage/requirejs/mixins.js 
Failed to load resource: the server responded with a status of 404 (Not Found)
requirejs-config.js:602 Uncaught ReferenceError: require is not defined
127.0.0.1/:24 Uncaught ReferenceError: require is not defined
127.0.0.1/:26 Uncaught ReferenceError: require is not defined

Answers:


18

将在运行时在pub / static文件夹中创建CSS和JS第一次,如果缺少CSS和JS,请在以下命令下运行

如果您使用的是Windows: php bin\magento setup:static-content:deploy

如果使用'git bash'的linux: php bin/magento setup:static-content:deploy


此外,请确保您启用的Apache服务器改写
史蒂夫·约翰逊

如果您可以分解步骤,将不胜感激。如何运行Windows命令?如何知道它是否真的有效?
Mohammed Joraid

如果您是从github下载源代码并通过浏览器安装的,则将需要启用开发人员模式,这毫无价值。上面的命令会抱怨您不需要setup:static-content:deploy在开发人员模式下运行,因此请确保将其追加-f到上面的命令。如果您设置的语言不是en_US,则还需要提供以下语言:php bin\magento setup:static-content:deploy -f en_US en_GB
BugHunterUK

12

我也面临这个问题。管理员给出了404错误,并且前端未附加CSS(即Luma没有以正确的格式显示..)。所以我执行了以下步骤来解决magento 2中的这两个问题。1)转到终端并运行此命令

sudo gedit /etc/apache2/apache2.conf

并更改:-

<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride none
Require all granted

<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted

仅更改允许全部覆盖

2)转到终端并运行命令:

sudo a2enmod rewrite
sudo service apache2 restart

然后将权限授予您的var,pub和app / etc。然后转到管理员并使其前端正常运行。


1
我尝试了数千个解决方案的人,但只有这个对我有用,非常感谢!
Wasif Khalil'4

8

对于使用wamp服务器的用户,然后在CLI中运行这些命令。

C:\ wamp \ bin \ php \ php5.5.12> php.exe
C:\ wamp \ www \\ bin \ magento设置:静态内容:部署


6

我也面临这个问题。在本地环境中导航到前端和后端时,重新安装带有演示数据的magento 2。得到calendar.css和require.js的MIME类型不匹配错误。除非通过以下方式部署静态内容,否则对我没有任何帮助

php bin/magento setup:static-content:deploy

在git bash中,虽然它是默认模式。



2

启用URL重写。

1)在Ubuntu中打开终端并执行以下命令:

sudo a2enmod rewrite

sudo service apache2 restart

2)确保没有.htaccess文件在magento的根目录中。htaccess文件复制/pub/.htaccess文件并将其粘贴到根目录中

3)/etc/apache2/apache2.conf使用以下命令打开文件:

sudo nano /etc/apache2/apache2.conf

并更改以下代码行:

<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride none
Require all granted

<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted

保存并关闭文件 Ctrl + X

  • 重新启动Apache

    sudo服务apache2重新启动

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.