Storing Content in a Database

Statamic stores your content in "flat files" by default, however, as you scale, you might reach a point where a traditional database might work better. In this short article, we'l show you how to move your entries (& other content) into a database.

Overview

Out of the box, Statamic stores your content in "flat files". However, there's a number of reasons you might find yourself reaching for a traditional database. Whether it fits better into your existing workflows or to enhance your site's performance, you'll be glad to know it's easy to switch.

Moving content to the database

  1. First things first, ensure your database is configured correctly. By default, Statamic sites are configured to use a SQLite database. However, you're free to change this in your .env:

    DB_CONNECTION=sqlite
    # DB_HOST=127.0.0.1
    # DB_PORT=3306
    # DB_DATABASE=laravel
    # DB_USERNAME=root
    # DB_PASSWORD=
  2. Run php please install:eloquent-driver. It'll install the Eloquent Driver addon, publish it's configuration file and prompt you to select the repositories you wish to move to the database.

    You might find it useful to keep "configuration" repositories as flat files, whilst storing the actual content in the database. For example: moving entries to the database but leaving collections flat-file.

  3. And that's you done! Wasn't that easy?

Change your mind?

If you change your mind about moving content to the database, you can always move it back. Just use one of the following commands to export your content back into flat-files:

  • Assets: php please eloquent:export-assets
  • Blueprints and Fieldsets: php please eloquent:export-blueprints
  • Collections: php please eloquent:export-collections
  • Entries: php please eloquent:export-entries
  • Forms: php please eloquent:export-forms
  • Globals: php please eloquent:export-globals
  • Navs: php please eloquent:export-navs
  • Revisions: php please eloquent:export-revisions
  • Taxonomies: php please eloquent:export-taxonomies
HR: Section
Learn More!

There is more to learn more in these related articles:

shipment-container

Repositories

HR: Section
Docs feedback

Submit improvements, related content, or suggestions through Github.

Betterify this page →