Chapter 12. Framework integrations


The laravel-phpbu package integrates phpbu into the Laravel framework so you can use the artisan command to execute your backups and a Laravel style PHP configuration to set them up.


  • PHP 7.0

  • Laravel 5.*

  • phpbu 6.0.*


Use Composer to install the package.

composer require "phpbu/phpbu-laravel"

Add the package ServiceProvider to your config/app.php configuration file.

'providers' => [
    * phpbu Backup Service Providers...

Finally use the Laravel artisan command to create a configuration skeleton by publishing the package.

php artisan vendor:publish --provider="phpbu\Laravel\ServiceProvider"

After publishing the ServiceProvider a phpbu.php configuration file is created in your config directory.


There are two ways of configuring your backup.

  1. Use the created phpbu.php configuration file

  2. Use a standard phpbu.xml or phpbu.json configuration file

The main difference between those two options is the implemented feature set.

While the PHPBU configuration files give you full access to all features of PHPBU the Laravel configuration file currently does not support all features of PHPBU, for example: encryption.

Using the Laravel configuration

The main concept of configuring backups stays the same. A backup consists of a source and a target. The source represents the data you want to backup. The target represents the location where you want to store your backup. You can add checks, cleanups and syncs to a backup to validate, cleanup or sync your backup to another location.

In the Laravel configuration file you can specify two types of backups, directories and databases (MySQL, PostgreSQL).


Define the directory you want to backup and the target location where to store your backup.

    'directories' => [
            'source' => [
                'path'    => storage_path('app'),
                'options' => [],
            'target' => [
                'dirname'     => storage_path('/backup/app'),
                'filename'    => 'app-%Y%m%d-%H%i.tar',
                'compression' => 'bzip2',


Just define the Laravel database connection configured in your databases.php configuration you want to backup and you are done. You can overwrite every setting defined with the specific option, for example username or password in case you have to use different credentials to backup your database.

You can use every option the mysqldump source supports for example to exclude some tables. Just use the option-name as index and the option-value as value.

    'databases' => [<emphasise>
            'source' => [
                'connection' => 'mysql',
                'options'    => []
            'target' => [
                'dirname'     => storage_path('backup/db'),
                'filename'    => 'dump-%Y%m%d-%H%i.sql',
                'compression' => 'bzip2',

Adding Check, Sync and Cleanup

Add check, sync and cleanup definitions to your backup configuration.

            'check' => [
                'type'  => 'SizeMin',
                'value' => '10B',
            'sync' => [
              'filesystem' => 's3',
              'path'       => '/backups/db'
            'cleanup' => [
                'type'    => 'quantity',
                'options' => [
                    'amount' => '20'

For a list of available checks and cleanups check the corresponding documentation sections.

To sync your backups you can use every filesystem defined in your Laravel filesystems.php configuration file.

Using a PHPBU configuration file

If you want to use a PHPBU configuration file your Laravel phpbu.php configuration should look something like this.

return [
    | phpbu configuration
    | Path to a phpbu configuration xml or json file.

    'phpbu' => base_path('phpbu.xml'),

For this to work you have to setup a valid phpbu.xml configuration file in your project root.

Remember that all paths in a PHPBU configuration have to be absolute or relative to the specified PHPBU configuration file.


To execute the backup use the artisan command line tool.

php artisan phpbu:backup

To execute a dry-run without making any changes.

php artisan phpbu:backup --phpbu-simulate
Please open a ticket on GitHub to suggest improvements to this page. Thanks!