The OP has a good answer. Though sometimes you don't have access to the terminal or a secure shell (ssh
), especially in a shared hosting environment to be able to run those commands.
I got a similar issue while working on a new project. I noticed that this normally happened because my application failed to write session files in the writable/session
folder of my root project directory because of permission restrictions. I was using the CodeIgniter\Session\Handlers\FileHandler
as my configured "session storage driver".
I managed to solve it by instructing the application to write these temporary files in the server's tmp
directory.
This is by default in the /tmp
directory.
Excerpt from php-src/php.ini-production
; Directory where the temporary files should be placed.
; Defaults to the system default (see sys_get_temp_dir)
;sys_temp_dir = "/tmp"
Solution
I opened my .env
file residing at the root of my project directory and added the line below.
app.sessionSavePath = '/tmp/my_project_name/ci4_session'
If you don't have this .env
file, create one starting with this default file content:
Notice the dot (.
) in front of the filename.
CodeIgniter4 env
file
Addendum
Similarly, in your case, the application fails to write cache files in the writable/cache
folder of your root project directory because of permission restrictions. You most certainly are using file
as your cache handler.
Solution
Open your .env
file residing at the root of your project directory and add the line below.
cache.storePath = '/tmp/my_project_name/ci4_cache'
TIP(S)
These and more configurations can be found/modified in your .env
file using the rules below:
- The configuration class file name, in lower case. I.e
cache
.
- Followed by a dot(
.
).
- Then the
public
configuration class's property name. I.e storePath
.
- Steps 1,2,3 combined makes,
cache.storePath
, which becomes your .env
file's key declaration. Then an equals sign =
. And lastly, the .env
file's value ('/tmp/my_project_name/ci4_cache'
) declaration. Finally coming up with, cache.storePath = '/tmp/my_project_name/ci4_cache'
.
The configuration classes can be found in the app/Config
folder of your root project directory. I.e:
app/Config/Cache.php
app/Config/App.php