Css not working after installation in Magento 2

偶尔善良 提交于 2019-12-12 18:35:04

问题


I have Installed Magento 2. Everything completed successfully but css is not loading. I tried these commands

php bin/magento cache:flush

php bin/magento indexer:reindex

php bin/magento setup:static-content:deploy

Please help me


回答1:


You should Provide Some permissions

run this command

sudo find . -type d -exec chmod -R 777 {} \; 
&& sudo find . -type f -exec chmod -R 777  {} \; 
&& sudo chmod u+x bin/magento



回答2:


Please, before doing anything go to magento2 basedir and do:

nano vendor/magento/framework/Filesystem/DriverInterface.php

and change

const WRITEABLE_DIRECTORY_MODE = 0770;

from 0770 to 0775

and

const WRITEABLE_FILE_MODE = 0660;

from 0660 to 0644

The above set 0775 for folders and 0644 for files on generated/cached entities

Then change whole magento2 filesystem to the same permissions

find . -type d -exec chmod 775 {} \; && find . -type f -exec chmod 644 {} \; && chmod u+x bin/magento

Important, you should execute bin/magento as a common user, and not as root. So if you are in bin/ folder you may use for example:

sudo -u youasuser php -d memory_limit=512M magento setup:upgrade

You need memory_limit=512 as some callings like setup:di:compile needs more memory.

Hope it helps!!




回答3:


Please check mod_rewrite is enabled on your web server.




回答4:


  1. First create a magento_user: adduser <username> and give user a password passwd <username> (May have to use sudo, if not already root)
  2. Find your web server group: ps aux | grep apache Typically www-data
  3. Add new user to this group: usermod -g www-data <username>
  4. groups <username> should show the groups that username belongs to.
  5. Restart webserver, so permissions can take effect service apache2 restart
  6. Set ownerships of files in Magento root. chown -R :<your web server group name> .
  7. Finally set permissions find . -type d -exec chmod 770 {} \; && find . -type f -exec chmod 660 {} \; && chmod u+x bin/magento

Reference: Set file system ownership and permissions and Create the Magento file system owner



来源:https://stackoverflow.com/questions/36301066/css-not-working-after-installation-in-magento-2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!