Laravel Bootstrap Cache Permissions Error Message

Posted on

An article relates on Laravel framework which is powering a web-based application. The focus on this article is about the error message generated because of the Laravel Bootstrap Cache. So, the discussion will be fully covering the Laravel bootstrap cache directory permissions which is the caused of the error message. Below is the error message acquired from the laravel.log stored in storage/logs. The location itself  is shown in the tree format as follows :

user@hostname:/var/www/html/laravel-project$ tree -r storage/logs/
└── laravel.log

0 directories, 8 files

Below is the content of the laravel.log :

[2017-08-08 08:27:26] development.ERROR: exception 'Exception' with message 'The bootstrap/cache directory must be present and writable.' in /var/www/html/laravel-project/vendor/laravel/framework/src/Illuminate/Foundation/ProviderRepository.php:190
Stack trace:

So, in order to solve the problem, check the folder specified in the error message which is ‘bootstrap/cache’. It is actually located normally in the following output generated by the ‘tree’ command in a tree format :

user@hostname:/var/www/html/laravel-project$ tree -r bootstrap/
├── cache
│   └── services.php
├── autoload.php
└── app.php

1 directory, 3 files

So, the permission which is needed to be corrected is in the folder located as specified in the above output. The permission of the folder is important because the SELinux in the operating system is activated. As it has already recognized from the SELinux functionality, it is actually a feature which is owned by linux as a kernel module responsible for managing access control policies. Every folders and files available in the Linux operating system is being labeled with a proper security context so there are rules and policies defined with that security context which SELinux implemented.

The normal security context label on the folder which is executed through an Apache Webserver for an example as the main webserver processed the Laravel powered web-based application or any web-based application which is powered with another web framework is ‘httpd_sys_content_t’. Off course after confirming the permission for the folders and files in the default permission must be pertained as shown below :

user@hostname:/var/www/html/laravel-project$ ls -lZ
total 448
drwxrwxr-x 8 apache apache unconfined_u:object_r_httpd_sys_content_t:s0 4096 Aug 7 12:54 app
-rw-rw-r-- 1 apache apache unconfined_u:object_r_httpd_sys_content_t:s0 1645 Aug 7 12:54 artisan
drwxrwxr-x 3 apache apache unconfined_u:object_r_httpd_sys_content_t:s0 4096 Aug 7 12:54 bootstrap
-rw-rw-r-- 1 apache apache unconfined_u:object_r_httpd_sys_content_t:s0 1812 Aug 7 12:54 composer.json
-rw-rw-r-- 1 apache apache unconfined_u:object_r_httpd_sys_content_t:s0 155985 Aug 7 12:54 composer.lock
-rw-rw-r-- 1 apache apache unconfined_u:object_r_httpd_sys_content_t:s0 208057 Agu 7 12:54 yarn.lock

To solve it, if the problem is concerning the security label context managed by SELinux, just match or change it according to the rule of policy allowed by SELinux for a folder or files allowed to be written with the suitable security context label which is ‘httpd_sys_rw_content_t’ as shown below :

root@hostname laravel-project]# chcon -Rv -t httpd_sys_rw_content_t bootstrap/cache/
changing security context of ‘bootstrap/cache/.gitignore’
changing security context of ‘bootstrap/cache/’
[root@hostname laravel-project]# 

Check the security label again as shown below :

user@hostname:/var/www/html/laravel-project$ ls -lZ bootstrap/
total 12
-rwxrwxr-x 1 apache apache unconfined_u:object_r_httpd_sys_content_t:s0 1602 Sep 20 2016 app.php
-rwxrwxr-x 1 apache apache unconfined_u:object_r_httpd_sys_content_t:s0 1079 Sep 20 2016 autoload.php
drwxrwxr-x 2 apache apache unconfined_u:object_r_httpd_sys_rw_content_t:s0 4096 Aug 7 11:25 cache/

After the security context has been changed try to execute the web-based application powered by Laravel.

One thought on “Laravel Bootstrap Cache Permissions Error Message

Leave a Reply