Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

YasserHaddad's avatar

File Put Contents Error

Versions: php: 7.2.0

laravel: 6.18.1

The system on the server is: Centos 8

So I am working on a e-commerce project in laravel, using laravel 6 and I am using the bagisto plugin for the e-commerce system, everthing was going will locally but when I deployed the project on the server I kept having this error:

"file_put_contents(/var/www/bagisto/storage/framework/sessions/DRnJtIDM2SubOI9rmibCvvDFoZwycupVIhfIgAE4): failed to open stream: Permission denied"

I've been looking for a solution for this problem a week now and I couldn't find anything to help me solve this problem, I tried the following methods:

1- Changed the permission for the sessions folder to 777.

2- Changed the permission for the whole storage folder using chmod -R 777 storage.

3- Cleared the cache using this command php artisan cache:clear

4- Changed the owner for the whole project using this command sudo chown -R apache:apache bagisto

5- Installed a new project on the server using the root permissions and followed the specific instructions to install the project and the same error kept showing up.

The last thing I've done is moving to the bootstrap/cache folder but I didn't find a folder with the name config.php, So I uploaded the folder from the local project and it gave me this error "There is no existing directory at "C:\xampp\htdocs\bagisto\storage\logs" and its not buildable: Permission denied" Wich is right since the home directory changed from one place to another and when I delete the folder that I uploaded "config.php" that error comes back again.

Could you please help me? Thanks in advance

0 likes
10 replies
bobbybouwmann's avatar

You can try to run the following commands

chmod -R gu+w storage

chmod -R guo+w storage

php artisan cache:clear

If that doesn't work we need more information. It seems that you're using apache. What kind of server are you running? Is it shared hosting or your own server?

1 like
YasserHaddad's avatar

@bobbybouwmann Thank you for your answer.

I've also tried these things and nothing worked with me and I think that using these two commands is the same as changing the folder to 777 permissions. (I tried this solution and the error kept showing up)

Yes, I am using apache, and I have my own server. (note that I am using a virtual host for this website)

bobbybouwmann's avatar

The owner of the directories and files is that the same user that is running apache?

YasserHaddad's avatar

@bobbybouwmann yes, it is apache because I ran this command sudo chown -R apache:apache bagisto to make sure that the user in apache so that it would run the project properly

bobbybouwmann's avatar

@yasserhaddad But is that also the user that is actually running the webserver? If those are different users it won't have access.

bobbybouwmann's avatar

You can run ps aux | grep httpd or ps aux | grep apache to find out which user is running. In most cases, Apache runs as the www-data user but it can be different.

I would try to change the use of the files to www-data and see if that works.

YasserHaddad's avatar
YasserHaddad
OP
Best Answer
Level 1

@bobbybouwmann Thank you for your reply.

As it turns out it was selinux problem which prevented the system to write in the project folder and I ran these commands to change the folder selinux tag:

semanage fcontext -a -t httpd_sys_rw_content_t '/var/www/bagisto/bootstrap/cache(/.*)?'
semanage fcontext -a -t httpd_sys_rw_content_t '/var/www/bagisto/storage(/.*)?'
restorecon -Rv '/var/www/bagisto'
bobbybouwmann's avatar

Make sure you mention selinux next time in your question...

1 like

Please or to participate in this conversation.