问题
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:
- First create a magento_user:
adduser <username>
and give user a passwordpasswd <username>
(May have to use sudo, if not already root) - Find your web server group:
ps aux | grep apache
Typicallywww-data
- Add new user to this group:
usermod -g www-data <username>
groups <username>
should show the groups that username belongs to.- Restart webserver, so permissions can take effect
service apache2 restart
- Set ownerships of files in Magento root.
chown -R :<your web server group name> .
- 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