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

earmsby's avatar

Deploying app to Forge that uses sqlite database

I have been testing an app that currently runs on a sqlite db. I deployed it to a Forge site via my git repo. How do I push the sqlite file up to the server? Do I just add the database file to the git repo?

0 likes
3 replies
LaryAI's avatar
Level 58

When deploying an application that uses an SQLite database to a server like Laravel Forge, you have a few options for handling the SQLite database file. Here’s a recommended approach:

  1. Avoid Committing the SQLite File to Git:

    • Generally, it's not a good practice to commit your SQLite database file to your Git repository, especially if it contains sensitive data or if it's expected to change frequently. Instead, you should manage it separately.
  2. Transfer the SQLite File to the Server:

    • You can manually upload the SQLite file to your server using SFTP or SCP. This way, you can place it in a secure location on your server.
  3. Configure Your Application:

    • Ensure your Laravel application is configured to use the SQLite database. In your .env file, you should have something like this:

      DB_CONNECTION=sqlite
      DB_DATABASE=/path/to/your/database.sqlite
      
    • Make sure the path specified in DB_DATABASE matches the location where you uploaded your SQLite file on the server.

  4. Set Correct Permissions:

    • Ensure that the web server user has the necessary permissions to read and write to the SQLite file. You can set the permissions using the following command:

      chmod 664 /path/to/your/database.sqlite
      chown www-data:www-data /path/to/your/database.sqlite
      
    • Replace www-data with the appropriate user and group for your web server.

  5. Automate Deployment (Optional):

    • If you frequently update your SQLite database, consider automating the deployment process using a script that uploads the latest version of your database file to the server.

By following these steps, you can effectively manage your SQLite database when deploying your application to a server like Laravel Forge.

martinbean's avatar

Do I just add the database file to the git repo?

@earmsby No, as that means you’re storing content in your Git repository, and it’s also going to get out of sync very quickly as it’ll only ever hold changes from when you last committed the database.

Data (and configuration) should be held separately from code. You also shouldn’t be mixing data between environments. Your local environment should have data for testing; your production environment should have production data, and data shouldn’t be going between environments. It just takes one “bad” upload for you to lost live data by accidentally uploading your local database, or accidentally sending a mail to real customers because you forgot you had pulled live data to your machine and then ran a bulk command to test something.

Snapey's avatar

when you run your first migrations post deployment, Laravel will suggest there is no database file, and would you like to create it. It then adds the tables to your empty database according to migrations.

Please or to participate in this conversation.