CSS 在 Magento 2 中安装后无法正常工作
CSS is not working after installation in Magento 2
我已经安装了 Magento 2。
一切都已成功完成,但 CSS 未加载。
我试过这些命令
php bin/magento cache:flush
php bin/magento indexer:reindex
php bin/magento setup:static-content:deploy
您应该提供一些权限
运行 这个命令
sudo find . -type d -exec chmod -R 777 {} \;
&& sudo find . -type f -exec chmod -R 777 {} \;
&& sudo chmod u+x bin/magento
请检查您的网络服务器是否启用了 mod_rewrite
。
拜托,在做任何事情之前去 magento2 basedir 然后做:
nano vendor/magento/framework/Filesystem/DriverInterface.php
并改变
const WRITEABLE_DIRECTORY_MODE = 0770;
从 0770 到 0775
和
const WRITEABLE_FILE_MODE = 0660;
从 0660 到 0644
上面 generated/cached 个实体
上的文件夹设置为 0775,文件设置为 0644
然后将整个 magento2 文件系统更改为相同的权限
find . -type d -exec chmod 775 {} \; && find . -type f -exec chmod 644 {} \; && chmod u+x bin/magento
重要,
您应该以普通用户而不是 root 身份执行 bin/magento。因此,如果您在 bin/ 文件夹中,您可以使用例如:
sudo -u youasuser php -d memory_limit=512M magento setup:upgrade
您需要 memory_limit=512,因为像 setup:di:compile 这样的调用需要更多内存。
- 首先创建一个 magento_user:
adduser <username>
并给用户一个密码 passwd <username>
(可能必须使用 sudo,如果还不是 root)
- 查找您的 Web 服务器组:
ps aux | grep apache
通常 www-data
- 向该组添加新用户:
usermod -g www-data <username>
groups <username>
应该显示用户名所属的组。
- 重启webserver,权限生效
service apache2 restart
- 在 Magento 根目录中设置文件的所有权。
chown -R :<your web server group name> .
- 终于设置权限了
find . -type d -exec chmod 770 {} \; && find . -type f -exec chmod 660 {} \; && chmod u+x bin/magento
参考:Set file system ownership and permissions and Create the Magento file system owner
我已经安装了 Magento 2。
一切都已成功完成,但 CSS 未加载。
我试过这些命令
php bin/magento cache:flush
php bin/magento indexer:reindex
php bin/magento setup:static-content:deploy
您应该提供一些权限
运行 这个命令
sudo find . -type d -exec chmod -R 777 {} \;
&& sudo find . -type f -exec chmod -R 777 {} \;
&& sudo chmod u+x bin/magento
请检查您的网络服务器是否启用了 mod_rewrite
。
拜托,在做任何事情之前去 magento2 basedir 然后做:
nano vendor/magento/framework/Filesystem/DriverInterface.php
并改变
const WRITEABLE_DIRECTORY_MODE = 0770;
从 0770 到 0775
和
const WRITEABLE_FILE_MODE = 0660;
从 0660 到 0644
上面 generated/cached 个实体
上的文件夹设置为 0775,文件设置为 0644然后将整个 magento2 文件系统更改为相同的权限
find . -type d -exec chmod 775 {} \; && find . -type f -exec chmod 644 {} \; && chmod u+x bin/magento
重要, 您应该以普通用户而不是 root 身份执行 bin/magento。因此,如果您在 bin/ 文件夹中,您可以使用例如:
sudo -u youasuser php -d memory_limit=512M magento setup:upgrade
您需要 memory_limit=512,因为像 setup:di:compile 这样的调用需要更多内存。
- 首先创建一个 magento_user:
adduser <username>
并给用户一个密码passwd <username>
(可能必须使用 sudo,如果还不是 root) - 查找您的 Web 服务器组:
ps aux | grep apache
通常www-data
- 向该组添加新用户:
usermod -g www-data <username>
groups <username>
应该显示用户名所属的组。- 重启webserver,权限生效
service apache2 restart
- 在 Magento 根目录中设置文件的所有权。
chown -R :<your web server group name> .
- 终于设置权限了
find . -type d -exec chmod 770 {} \; && find . -type f -exec chmod 660 {} \; && chmod u+x bin/magento
参考:Set file system ownership and permissions and Create the Magento file system owner