Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Box Laravel Package

humbug/box

View on GitHub
Deep Wiki
Context7

Getting Started

First Steps

  1. Installation Add the package via Composer:

    composer require humbug/box --dev
    

    No additional configuration is requiredโ€”Box is designed to be zero-config.

  2. Basic Usage Run the following command in your Laravel project root to generate a PHAR:

    vendor/bin/box compile
    

    This creates a public/box.phar file containing your application and dependencies.

  3. First Use Case: Deployment Use Box to bundle your Laravel app for deployment (e.g., shared hosting without Composer):

    vendor/bin/box compile --output=public/app.phar
    

    Upload app.phar to your server and execute it via:

    php public/app.phar
    

Implementation Patterns

Common Workflows

  1. Bundling for Production Exclude unnecessary files (e.g., .env, node_modules) via .boxignore:

    .env
    node_modules/
    storage/logs/
    

    Compile with:

    vendor/bin/box compile --output=public/app.prod.phar
    
  2. Custom Entry Points Override the default index.php by specifying a custom entry file:

    vendor/bin/box compile --entry=public/custom-entry.php
    
  3. Including External Files Add non-PHP assets (e.g., fonts, images) via --include:

    vendor/bin/box compile --include=public/assets/fonts/
    
  4. Integration with Laravel Mix Use Box alongside Laravel Mix for frontend assets:

    npm run dev && vendor/bin/box compile --output=public/app.phar
    
  5. Automating with CI/CD Add Box to your GitHub Actions workflow:

    - name: Build PHAR
      run: vendor/bin/box compile --output=public/app.phar
    

Advanced Patterns

  • Multi-PHAR Deployments Bundle different environments (e.g., app.dev.phar, app.staging.phar) with environment-specific configs.
  • PHAR as a CLI Tool Use --bin to expose a custom CLI command:
    vendor/bin/box compile --bin=app:command=MyCommand
    
    Access via php app.phar my:command.

Gotchas and Tips

Common Pitfalls

  1. Missing Dependencies Ensure all required Composer packages are installed before compiling:

    composer install --optimize-autoloader
    

    Box does not auto-resolve missing dependencies.

  2. Class Loading Issues If autoloading fails, regenerate the Composer autoloader:

    composer dump-autoload
    
  3. File Permissions PHARs require executable permissions on the server:

    chmod +x public/app.phar
    
  4. Environment Variables .env files are ignored by default. Use --env to embed them:

    vendor/bin/box compile --env=.env.production
    
  5. Large PHAR Sizes Exclude unused dependencies or files to reduce size. Use --exclude:

    vendor/bin/box compile --exclude=vendor/doctrine/*
    

Debugging Tips

  • Verify PHAR Contents List files in the PHAR:
    php -r "print_r(Box\Phar::getFiles('public/app.phar'));"
    
  • Check for Errors Run with --verbose for detailed logs:
    vendor/bin/box compile --verbose
    
  • Test Locally Use --test to validate the PHAR before deployment:
    vendor/bin/box compile --test
    

Extension Points

  1. Custom Build Scripts Extend Box with a box.json config file:
    {
      "entry": "public/index.php",
      "includes": ["public/assets/"],
      "excludes": ["vendor/monolog/*"]
    }
    
  2. Post-Compile Hooks Use post-compile scripts in package.json or composer.json:
    {
      "scripts": {
        "post-box": "php artisan optimize"
      }
    }
    
  3. PHAR-Specific Logic Detect if running inside a PHAR in your Laravel code:
    if (Phar::running()) {
        // Custom logic for PHAR execution
    }
    
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
codifyo/ts-generator-bundle
andydefer/laravel-cluster
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky
spatie/mailcoach-vapor