Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Heroku deploy deletes server files automatically?

I'm new to HEROKU APPS.

In my heroku app i have a problem. that is I'm using a php script to save data on server.

Example :

<?PHP

$file = "example.txt";

$data = "Something...";

file_put_contents($file,$data);

?>

This PHP script run successfully and save data perfectly.

But, when I deploy my APP to HEROKU to update -> in this precess example.txt file is automatically deleted.

like image 703
Jooxa Avatar asked Dec 25 '12 15:12

Jooxa


People also ask

Does Heroku delete images?

The Heroku filesystem is ephemeral - that means that any changes to the filesystem whilst the dyno is running only last until that dyno is shut down or restarted. Each dyno boots with a clean copy of the filesystem from the most recent deploy.

Does Heroku have persistent storage?

Heroku does not provide any sort of persistent storage on dynos. If you need to persist files across sessions, you must use object storage such as Amazon S3.

Can Heroku save files?

Files are uploaded directly to the cloud from your user's browser, without passing through your application. Adding direct uploads to your app allows you to offload the storage of static files from your app. This is crucial on Heroku, because your app's dynos have an ephemeral filesystem.


3 Answers

Heroku File Systems

Heroku behavior varies depending a little on the stack you use. With Bamboo, most of the file system is read-only. With Cedar, it is ephemeral.

In either case, the file systems are not shared between dynos, and should not be used for storage. To reliably store data server-side, you will need to use the database (perhaps storing your uploads as blobs), or as external assets on another host or service.

like image 64
Todd A. Jacobs Avatar answered Nov 10 '22 13:11

Todd A. Jacobs


Heroku does not supply hard disk space to persistent files between git pushes, you'll have to use something like Amazon S3 for file storage. That is why Heroku calls their filesystem Ephemeral filesystem. It was even read-only in earlier versions of the stack.

Heroku has a tutorial on it: Using AWS S3 to Store Static Assets and File Uploads

like image 45
Femaref Avatar answered Nov 10 '22 11:11

Femaref


Please see the docs:

Ephemeral filesystem

Each dyno gets its own ephemeral filesystem, with a fresh copy of the most recently deployed code. During the dyno’s lifetime its running processes can use the filesystem as a temporary scratchpad, but no files that are written are visible to processes in any other dyno and any files written will be discarded the moment the dyno is stopped or restarted.

So you can not save much with your Heroku dyno. Especially after you've pushed your new version, the dyno is restarted and the file-system is reset then.

You need to store files into a remote location then if they should survive the dyno reset.

like image 1
hakre Avatar answered Nov 10 '22 11:11

hakre