Drupal 8 - Refused to apply style because its MIME type ('text/html') is not a supported stylesheet MIME type

By xngo on November 15, 2020

Issue

I decided to do a clean install of my Drupal. So, I deleted whole the Drupal root directory and started to install it. After installation, I opened the website and there is only text and no CSS styles.

Drupal 8 - No CSS style

I checked Google Chrome Developer Console, I got the following error message:

Refused to apply style from 'http://localhost/' because its MIME type ('text/html') is not a supported stylesheet MIME type, and strict MIME checking is enabled.

I checked Drupal's Recent Log Messages, I got the following error message:

User warning: mkdir(): Permission Denied in Drupal\Component\PhpStorage\FileStorage->createDirectory()

Solution

Given the error messages that I got, it is logically related to access permission. I checked the permission of ./sites/default/.

$ ls -al ./sites/default/
    -rw-r--r-- 1 www-data www-data 6.7K Nov  5 11:55 default.services.yml
    -rw-r--r-- 1 www-data www-data  32K Nov  5 11:55 default.settings.php
    drwxrwxr-x 4 root     root     4.0K Nov 15 11:19 files/
    -r--r--r-- 1 root     root      32K Nov 15 11:18 settings.php

I found out that the files directory and settings.php file are not owned by www-data. So, I changed them ownership back to www-data.

$ chown -R www-data:www-data ./sites/default/*
    -rw-r--r-- 1 www-data www-data 6.7K Nov  5 11:55 default.services.yml
    -rw-r--r-- 1 www-data www-data  32K Nov  5 11:55 default.settings.php
    drwxrwxr-x 7 www-data www-data 4.0K Nov 15 12:55 files/
    -r--r--r-- 1 www-data www-data  32K Nov 15 12:53 settings.php

About the author

Xuan Ngo is the founder of OpenWritings.net. He currently lives in Montreal, Canada. He loves to write about programming and open source subjects.