Laravel file_put_contents error on shared hosting

12,551

Solution 1

What you should do is looking for occurrences of xampp in your application because it seems you have sessions that are written to same folder that you have on your machine and obviously such directory doesn't exist on web server.

Especially make sure you in session.php you have:

'files' => storage_path('framework/sessions'),

and remove config cache from bootstrap/cache directory just in case

Solution 2

I had the same issue here. I tried to run php artisan config:cache but it didn't work out

Then I delete all my sessions in /myprojectname/storage/framework/ but still didn't work out on shared hosting but worked fine on localhost.

Here's what worked:

I delete the cache folder in /myprojectname/bootstrap/ and ran the application and got this error:

Exception thrown with message "The /hosthome/hostuser/myprojectname/bootstrap/cache directory must be present and writable."

I then made a new cache folder in /myprojectname/bootstrap/ and ran the site and it was up

in short terms

  • Navigate to your projects /bootstrap/cache/ folder.

  • Delete the contents of the directory and your good to go 😀

Share:
12,551

Related videos on Youtube

Martin Yakimov
Author by

Martin Yakimov

A pupil with great interest in programming.

Updated on June 04, 2022

Comments

  • Martin Yakimov
    Martin Yakimov almost 2 years

    I created my Laravel app and I am uploading on shared hosting. It's show error:

    file_put_contents(D:\xampp\htdocs\Laravel\storage\framework/sessions/FlEPsHNW7Rggfb9wvDZ71K7D2YQNNQK0epRBRQnW): failed to open stream: No such file or directory

    This is folder from my computer. I read same problems but I am on shared hosting and I don't have a composer or artisan for operations.

    Thanks in advance!

    • teeyo
      teeyo over 6 years
      well there's no D:\xampp\htdocs\Laravel\storage\framework/sessions/FlEPsHNW7‌​Rggfb9wvDZ71K7D2YQNN‌​QK0epRBRQnW in your shared host if I'm guessing right !! I mean D:\xampp... noway
    • teeyo
      teeyo over 6 years
      You probably need to clear some cache or something, because there's still your local xampp configuration somewhere
    • Martin Yakimov
      Martin Yakimov over 6 years
      Yes, this folder does not exist. It's from my computer.
    • Martin Yakimov
      Martin Yakimov over 6 years
      How I clear cache? I don't have artisan
  • Martin Yakimov
    Martin Yakimov over 6 years
    'files' => storage_path('framework/sessions'), -> this is right. In bootstrap/cache hasn't cache
  • Marcin Nabiałek
    Marcin Nabiałek over 6 years
    And have you searched for all occurrences of xampp already?
  • Martin Yakimov
    Martin Yakimov over 6 years
    Yes, I searched.
  • Marcin Nabiałek
    Marcin Nabiałek over 6 years
    It has to be somewhere. In case you are using very custom code you should search it also in database dump
  • Marcin Nabiałek
    Marcin Nabiałek over 6 years
    As I said there is no way - there should be xampp somewhere. Webhosting haven't used D:\xampp from nowhere for sure so it has to be somewhere in files when you copied it or in database if you used custom configuration
  • Martin Yakimov
    Martin Yakimov over 6 years
    Oh yeah. I found this path in boostrap/cache/config.php. Now how I change?
  • Marcin Nabiałek
    Marcin Nabiałek over 6 years
    Just a moment before you don't have file in this directory :) Just remove this file - it's for performance reasons only. If you care about performance I would recommend you to use VPS not shared hosting
  • Martin Yakimov
    Martin Yakimov over 6 years
    I removed file, but will it harm the project?
  • Marcin Nabiałek
    Marcin Nabiałek over 6 years
    No, it will only affect performance a bit. If you care as I said use VPS and run php artisan config:cache to cache it or you can run this from your code but this is completely other thing.
  • Martin Yakimov
    Martin Yakimov over 6 years
    Thanks for helping! I fixed it.
  • zonecc
    zonecc over 4 years
    The files are created again once you run the website again.
  • Mitch M
    Mitch M over 3 years
    Thanks a bunch. I had renamed the existing ones to .old e.g config.php.old just to be safe . But it's worked well and the files were recreated the files when I reloaded the site url.