How do I back up a Laravel site?
Why Laravel backups matter
At HostingDuty, we treat backups as a non-negotiable part of deployment. A Laravel site consists of code, configuration, database, and user uploads. Losing any of these can break your application or cause data loss. We recommend a three-part strategy: database, code, and storage.
Database backups
The database holds your application state. We export it using mysqldump or Laravel's native backup packages like Spatie Laravel Backup. For MySQL, run:
``bash
mysqldump -u [user] -p [database_name] > backup.sql
`
Schedule this with cron or use a CI/CD pipeline. We also support automated backups on our managed Laravel hosting plans. See our guide on database backup best practices for more details.
Code and configuration backups
Your application code lives in Git. We recommend version control for all changes. Back up your .env file separately, as it contains sensitive credentials. Never commit .env to Git. Store it securely and restore it during deployment. For more on secure configuration, read our Laravel environment security guide.
Storage backups
User uploads and generated files live in storage/app. We archive this directory along with public/uploads. Use tar` or similar tools to compress and store the archive off-site. For automated storage backups, see our Laravel storage backup tutorial.
Automation and verification
We automate backups using cron jobs or CI/CD pipelines. At HostingDuty, we test restores monthly to ensure recoverability. A backup is only useful if you can restore from it. Learn more about backup verification and disaster recovery planning.
External resources
For deeper technical details, refer to the Laravel documentation on backups and the Spatie Laravel Backup package.
People also ask
- How do I restore a Laravel site from backup?
- What is the best way to automate Laravel backups?
- How do I secure Laravel environment variables?
- What is the recommended frequency for Laravel backups?
- How do I test Laravel backup restoration?