This commit is contained in:
2026-06-03 14:21:20 +02:00
parent f36a9906a2
commit abb39e62f9
2 changed files with 39 additions and 19 deletions
+34 -19
View File
@@ -206,6 +206,19 @@ if (in_array($mode, ['Fresh Install su Apache (LAMP tradizionale)', 'Restore da
}
}
// ── Web server user detection ─────────────────────────
$wwwUser = 'www-data';
$sudo = '';
if (strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN') {
$detected = trim(shell_exec('ps aux | grep -E "apache|httpd" | grep -v grep | head -1 | awk \'{print $1}\'') ?: '');
if ($detected !== '' && $detected !== 'root') {
$wwwUser = $detected;
}
if (function_exists('posix_getuid') && posix_getuid() === 0) {
$sudo = "sudo -u {$wwwUser} ";
}
}
// ══════════════════════════════════════════════════════
// MODE 1: FRESH INSTALL APACHE
// ══════════════════════════════════════════════════════
@@ -251,7 +264,7 @@ if ($mode === 'Fresh Install su Apache (LAMP tradizionale)') {
}
// APP_KEY
runCapture("php artisan key:generate --force");
runCapture("{$sudo}php artisan key:generate --force");
ok('APP_KEY generata');
// Config
@@ -332,7 +345,7 @@ if ($mode === 'Fresh Install su Apache (LAMP tradizionale)') {
println(color(' 3/7 — INSTALLAZIONE DIPENDENZE', 'yellow'));
println(color('══════════════════════════════════════════', 'yellow'));
run('composer install --no-dev --optimize-autoloader', 'Installazione dipendenze Composer...');
run("{$sudo}composer install --no-dev --optimize-autoloader", 'Installazione dipendenze Composer...');
ok('Dipendenze PHP installate');
// ── Step 4: Package discovery ────────────────────
@@ -341,7 +354,7 @@ if ($mode === 'Fresh Install su Apache (LAMP tradizionale)') {
println(color(' 4/7 — REGISTRAZIONE PACCHETTI', 'yellow'));
println(color('══════════════════════════════════════════', 'yellow'));
runCapture("php artisan package:discover --ansi 2>/dev/null");
runCapture("{$sudo}php artisan package:discover --ansi 2>/dev/null");
ok('Pacchetti registrati');
// ── Step 5: Schema + Seed ────────────────────────
@@ -362,13 +375,13 @@ if ($mode === 'Fresh Install su Apache (LAMP tradizionale)') {
}
} else {
// SQLite fallback: usa le migration (install.sql è solo per MySQL)
if (!run('php artisan migrate --seed --force', 'Esecuzione migration e seed...')) {
if (!run("{$sudo}php artisan migrate --seed --force", 'Esecuzione migration e seed...')) {
fail('Migration fallita. Verifica la configurazione SQLite.');
}
}
ok('Database popolato con struttura e dati base');
runCapture('php artisan storage:link --force 2>/dev/null');
runCapture("{$sudo}php artisan storage:link --force 2>/dev/null");
// ── Step 6: Admin user (via PDO — no tinker) ─────
println();
@@ -385,12 +398,12 @@ if ($mode === 'Fresh Install su Apache (LAMP tradizionale)') {
} else {
// SQLite: usa seeder (l'admin verrà creato da DatabaseSeeder)
// Poi aggiorna la password con quella scelta dall'utente
runCapture("php artisan tinker --execute=" . escapeshellarg(
runCapture("{$sudo}php artisan tinker --execute=" . escapeshellarg(
"\$u = \App\Models\User::first(); " .
"if (\$u) { " .
"\$u->name = " . var_export($adminName, true) . "; " .
"\$u->email = " . var_export($adminEmail, true) . "; " .
"\$u->password = bcrypt(" . var_export($adminPass, true) . "); " .
"\$u->name = " . var_export(\$adminName, true) . "; " .
"\$u->email = " . var_export(\$adminEmail, true) . "; " .
"\$u->password = bcrypt(" . var_export(\$adminPass, true) . "); " .
"\$u->is_admin = true; " .
"\$u->status = 'active'; " .
"\$u->permissions = " . var_export([
@@ -406,6 +419,10 @@ if ($mode === 'Fresh Install su Apache (LAMP tradizionale)') {
ok("Amministratore {$adminEmail} configurato");
}
// Clear all caches after schema + admin creation
runCapture("{$sudo}php artisan optimize:clear 2>/dev/null");
ok('Cache ottimizzate');
// ── Step 7: Asset ────────────────────────────────
println();
println(color('══════════════════════════════════════════', 'yellow'));
@@ -414,8 +431,8 @@ if ($mode === 'Fresh Install su Apache (LAMP tradizionale)') {
$hasNpm = checkCmd('npm');
if ($hasNpm && confirm('Compilare gli asset frontend con npm?')) {
run('npm install', 'Installazione dipendenze npm...');
run('npm run build', 'Compilazione asset...');
run("{$sudo}npm install", 'Installazione dipendenze npm...');
run("{$sudo}npm run build", 'Compilazione asset...');
ok('Asset compilati');
} else {
if (!$hasNpm) warn('npm non disponibile — asset non compilati (AdminLTE via CDN)');
@@ -425,7 +442,6 @@ if ($mode === 'Fresh Install su Apache (LAMP tradizionale)') {
// ── Permissions ──────────────────────────────────
if (strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN') {
info('Impostazione permessi...');
$wwwUser = trim(shell_exec('ps aux | grep -E "apache|httpd" | grep -v grep | head -1 | awk \'{print \$1}\'') ?: 'www-data');
runCapture("chown -R {$wwwUser}:{$wwwUser} storage bootstrap/cache 2>/dev/null");
chmod("{$scriptDir}/storage", 0775);
chmod("{$scriptDir}/bootstrap/cache", 0775);
@@ -691,7 +707,7 @@ if ($mode === 'Restore da Backup (Apache)') {
file_put_contents('.env', $dotenv);
// Generate APP_KEY
runCapture('php artisan key:generate --force');
runCapture("{$sudo}php artisan key:generate --force");
ok('APP_KEY rigenerata');
// Import database
@@ -721,16 +737,15 @@ if ($mode === 'Restore da Backup (Apache)') {
}
// Composer
run('composer install --no-dev --optimize-autoloader', 'Installazione dipendenze Composer...');
runCapture('php artisan package:discover --ansi 2>/dev/null');
run("{$sudo}composer install --no-dev --optimize-autoloader", 'Installazione dipendenze Composer...');
runCapture("{$sudo}php artisan package:discover --ansi 2>/dev/null");
// Storage link + cache
runCapture('php artisan storage:link --force 2>/dev/null');
runCapture('php artisan optimize:clear');
runCapture("{$sudo}php artisan storage:link --force 2>/dev/null");
runCapture("{$sudo}php artisan optimize:clear");
// Permissions
if (strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN') {
$wwwUser = trim(shell_exec('ps aux | grep -E "apache|httpd" | grep -v grep | head -1 | awk \'{print \$1}\'') ?: 'www-data');
runCapture("chown -R {$wwwUser}:{$wwwUser} storage bootstrap/cache 2>/dev/null");
chmod("{$scriptDir}/storage", 0775);
chmod("{$scriptDir}/bootstrap/cache", 0775);
@@ -758,7 +773,7 @@ if ($mode === 'Restore da Backup (Apache)') {
}
} else {
// SQLite fallback: usa tinker
$result = runCapture("php artisan tinker --execute=" . escapeshellarg(
$result = runCapture("{$sudo}php artisan tinker --execute=" . escapeshellarg(
"\$e = \App\Models\User::where('email', " . var_export($adminEmail, true) . ")->exists(); " .
"if (!\$e) { " .
"\$u = new \App\Models\User; " .
@@ -0,0 +1,5 @@
<?php $__env->startSection('title', __('Page Expired')); ?>
<?php $__env->startSection('code', '419'); ?>
<?php $__env->startSection('message', __('Page Expired')); ?>
<?php echo $__env->make('errors::minimal', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH /var/www/html/glastree/vendor/laravel/framework/src/Illuminate/Foundation/Exceptions/views/419.blade.php ENDPATH**/ ?>