PHP code example of phattarachai / laravel-db-tunnel

1. Go to this page and download the library: Download phattarachai/laravel-db-tunnel 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/ */

    

phattarachai / laravel-db-tunnel example snippets


'claude-prod' => [
    'driver' => 'pgsql',
    'host' => '127.0.0.1',
    'port' => env('PROD_DB_PORT'),
    'database' => env('PROD_DB_DATABASE'),
    'username' => env('PROD_DB_USERNAME', 'claude-prod'),
    'password' => env('PROD_DB_PASSWORD'),
    'sslmode' => 'prefer',
],

'tunnels' => [
    'claude-prod' => [
        'alias' => 'prod',          // the ~/.ssh/config Host you already log in with
        'remote_port' => 5432,      // the database port on that box
    ],
],

return [
    'tunnels' => [
        'claude-qas' => [
            'alias' => 'qas',             //  where the DB listens, as seen from the box
            'port_env' => 'QAS_DB_PORT',  // default: DB_PORT for the default connection, else <NAME>_DB_PORT
                                          //          with a `claude-` prefix dropped
            'auto_open' => true,
            'host' => '203.0.113.5',      // only used to print a Host block when the alias is missing
            'user' => 'deploy',
        ],
    ],
    'auto_open' => env('DB_TUNNEL_AUTO_OPEN'),    // null → local only
    'port_range' => [15440, 15999],
    'registry' => env('DB_TUNNEL_REGISTRY'),      // null → ~/.config/db-tunnel/ports.json
    'ssh_config' => env('DB_TUNNEL_SSH_CONFIG'),  // null → ~/.ssh/config
    'probe' => env('DB_TUNNEL_PROBE', 'auto'),    // auto | lsof | ss
    'connect_timeout' => 30,                      // seconds before a detached dial is abandoned
    'wait' => 10,                                 // seconds `open` waits for the port to listen
    'keepalive' => ['interval' => 15, 'count_max' => 8],
    'watch' => ['establish_timeout' => 90, 'redial_delay' => 3],
];
bash
php artisan db:tunnel install claude-prod
json
"dev": [
    "Composer\\Config::disableProcessTimeout",
    "npx concurrently -c \"#fdba74,#93c5fd,#c4b5fd\" \"php artisan db:tunnel watch mysql\" \"php artisan db:tunnel wait mysql && php artisan serve\" \"php artisan db:tunnel wait mysql && php artisan queue:listen --tries=1\" --names=tunnel,server,queue --kill-others"
]
sql
CREATE ROLE "claude-prod" LOGIN PASSWORD '<generated>';
GRANT CONNECT ON DATABASE app TO "claude-prod";
GRANT USAGE ON SCHEMA public TO "claude-prod";
GRANT SELECT ON ALL TABLES IN SCHEMA public TO "claude-prod";
GRANT SELECT ON ALL SEQUENCES IN SCHEMA public TO "claude-prod";
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT SELECT ON TABLES TO "claude-prod";
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT SELECT ON SEQUENCES TO "claude-prod";