PHP code example of aflorea4 / laravel-source-obfuscator

1. Go to this page and download the library: Download aflorea4/laravel-source-obfuscator library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

aflorea4 / laravel-source-obfuscator example snippets



// Define encryption key (use the key shown after obfuscation)
define('PHP_BOLT_KEY', 'your-encryption-key-here');

// Or load from environment
define('PHP_BOLT_KEY', env('PHPBOLT_KEY'));

// Rest of your Laravel bootstrap code...

'extension_name' => 'bolt',  // Extension name to check
'encryption_key' => env('PHPBOLT_KEY', ''),  // Leave empty to auto-generate
'key_length' => env('PHPBOLT_KEY_LENGTH', 6),  // Key length if auto-generated

'    'app',
    'routes',
    'config',
    'database/migrations',
    'database/seeders',
],

'exclude_paths' => [
    'tests',
    'vendor',
    'node_modules',
    'storage',
    '*.blade.php',  // Exclude Blade templates
    '*.md',
    '*.json',
],

'obfuscation' => [
    'strip_comments' => true,        // Remove comments before encryption
    'strip_whitespace' => true,      // Remove unnecessary whitespace
    // Note: String encoding, variable scrambling, integrity checks,
    // and encryption are handled by bolt_encrypt() automatically
],

'backup' => [
    'enabled' => true,
    'path' => env('OBFUSCATOR_BACKUP_DIR', 'backups/pre-obfuscation'),
    'keep_last' => 5,  // Keep only the last 5 backups
],

'ci_mode' => [
    'fail_on_error' => true,
    'generate_report' => true,
    'report_path' => 'build/obfuscation-report.json',
],

'performance' => [
    'parallel_processes' => 0,      // 0 = auto-detect CPU cores
    'memory_limit' => '512M',
    'timeout' => 60,                // Timeout per file in seconds
],

'exclude_paths' => [
    '*.blade.php',
],

'scramble_functions' => false,
'scramble_classes' => false,

'backup' => [
    'enabled' => true,
    'keep_last' => 5,
],

'performance' => [
    'parallel_processes' => 4,  // Adjust based on available CPU
    'memory_limit' => '1G',
    'timeout' => 120,
],

'performance' => [
    'memory_limit' => '1G',  // Increase as needed
],
bash
# Download bolt.so for your PHP version from https://github.com/arshidkv12/phpBolt
# Or use the provided installation script

# Copy to PHP extensions directory
sudo cp bolt.so $(php-config --extension-dir)/

# Enable the extension
echo "extension=bolt.so" | sudo tee /etc/php/$(php -r 'echo PHP_MAJOR_VERSION.".".PHP_MINOR_VERSION;')/mods-available/bolt.ini
sudo phpenmod bolt

# Restart PHP-FPM
sudo systemctl restart php$(php -r 'echo PHP_MAJOR_VERSION.".".PHP_MINOR_VERSION;')-fpm

# Verify installation
php -m | grep bolt
bash
php artisan vendor:publish --provider="Aflorea4\LaravelSourceObfuscator\ObfuscatorServiceProvider" --tag="config"
bash
# The bolt.so extension MUST be installed in production
sudo cp bolt.so $(php-config --extension-dir)/
echo "extension=bolt.so" | sudo tee /etc/php/8.2/mods-available/bolt.ini
sudo phpenmod bolt
sudo systemctl restart php8.2-fpm
bash
php artisan obfuscate:run
bash
php artisan obfuscate:check
bash
php artisan obfuscate:status
bash
php artisan obfuscate:status --report
bash
php artisan obfuscate:clear
yaml
stages:
    - build
    - obfuscate
    - deploy

obfuscate:
    stage: obfuscate
    image: php:8.2
    before_script:
        - composer install --no-dev --optimize-autoloader
        - bash install-phpbolt.sh
    script:
        - php artisan obfuscate:check
        - php artisan obfuscate:run --force
    artifacts:
        paths:
            - production/obfuscated/
            - build/obfuscation-report.json
        expire_in: 1 week
bash
# Check if extension is loaded
php -m | grep bolt

# Check extension directory
php -i | grep extension_dir

# Verify bolt.so exists
ls -l $(php-config --extension-dir)/bolt.so

# Check if enabled
php -r "var_dump(extension_loaded('bolt'));"

# If not loaded, enable it
echo "extension=bolt.so" | sudo tee /etc/php/8.2/mods-available/bolt.ini
sudo phpenmod bolt
sudo systemctl restart php8.2-fpm