mirror of
https://github.com/crivion/laranode.git
synced 2026-06-08 10:22:44 +08:00
php version manager attempt #1
This commit is contained in:
@@ -15,4 +15,153 @@ class PHPManagerController extends Controller
|
||||
|
||||
return response()->json($versions);
|
||||
}
|
||||
|
||||
/**
|
||||
* Render the PHP management page
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
return inertia('PHP/Index');
|
||||
}
|
||||
|
||||
/**
|
||||
* List all installed PHP versions with their systemctl status
|
||||
*/
|
||||
public function list(): JsonResponse
|
||||
{
|
||||
$scriptPath = base_path('laranode-scripts/bin/laranode-php-list.sh');
|
||||
$output = shell_exec("sudo bash {$scriptPath}");
|
||||
|
||||
$phpVersions = json_decode($output, true) ?? [];
|
||||
|
||||
return response()->json($phpVersions);
|
||||
}
|
||||
|
||||
/**
|
||||
* Install a new PHP version
|
||||
*/
|
||||
public function install(Request $request): JsonResponse
|
||||
{
|
||||
$request->validate([
|
||||
'version' => 'required|string|regex:/^\d+\.\d+$/',
|
||||
]);
|
||||
|
||||
$version = $request->input('version');
|
||||
$scriptPath = base_path('laranode-scripts/bin/laranode-php-install.sh');
|
||||
|
||||
// Execute installation script
|
||||
$output = shell_exec("sudo bash {$scriptPath} {$version} 2>&1");
|
||||
|
||||
// Check if installation was successful
|
||||
if (strpos($output, 'installed successfully') !== false) {
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => "PHP {$version} installed successfully",
|
||||
'output' => $output
|
||||
]);
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => "Failed to install PHP {$version}",
|
||||
'output' => $output
|
||||
], 500);
|
||||
}
|
||||
|
||||
/**
|
||||
* Uninstall a PHP version
|
||||
*/
|
||||
public function uninstall(Request $request): JsonResponse
|
||||
{
|
||||
$request->validate([
|
||||
'version' => 'required|string|regex:/^\d+\.\d+$/',
|
||||
]);
|
||||
|
||||
$version = $request->input('version');
|
||||
$scriptPath = base_path('laranode-scripts/bin/laranode-php-uninstall.sh');
|
||||
|
||||
// Execute uninstallation script
|
||||
$output = shell_exec("sudo bash {$scriptPath} {$version} 2>&1");
|
||||
|
||||
// Check if uninstallation was successful
|
||||
if (strpos($output, 'uninstalled successfully') !== false) {
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => "PHP {$version} uninstalled successfully",
|
||||
'output' => $output
|
||||
]);
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => "Failed to uninstall PHP {$version}",
|
||||
'output' => $output
|
||||
], 500);
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggle PHP-FPM service (enable/disable)
|
||||
*/
|
||||
public function toggleService(Request $request): JsonResponse
|
||||
{
|
||||
$request->validate([
|
||||
'version' => 'required|string|regex:/^\d+\.\d+$/',
|
||||
'enabled' => 'required|boolean',
|
||||
]);
|
||||
|
||||
$version = $request->input('version');
|
||||
$enabled = $request->input('enabled');
|
||||
$action = $enabled ? 'enable' : 'disable';
|
||||
|
||||
$scriptPath = base_path('laranode-scripts/bin/laranode-php-service.sh');
|
||||
|
||||
// Execute service management script
|
||||
$output = shell_exec("sudo bash {$scriptPath} {$action} {$version} 2>&1");
|
||||
|
||||
// Check if action was successful
|
||||
if (strpos($output, 'completed successfully') !== false) {
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => "PHP {$version}-FPM service {$action}d successfully",
|
||||
'output' => $output
|
||||
]);
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => "Failed to {$action} PHP {$version}-FPM service",
|
||||
'output' => $output
|
||||
], 500);
|
||||
}
|
||||
|
||||
/**
|
||||
* Restart PHP-FPM service
|
||||
*/
|
||||
public function restartService(Request $request): JsonResponse
|
||||
{
|
||||
$request->validate([
|
||||
'version' => 'required|string|regex:/^\d+\.\d+$/',
|
||||
]);
|
||||
|
||||
$version = $request->input('version');
|
||||
$scriptPath = base_path('laranode-scripts/bin/laranode-php-service.sh');
|
||||
|
||||
// Execute restart script
|
||||
$output = shell_exec("sudo bash {$scriptPath} restart {$version} 2>&1");
|
||||
|
||||
// Check if restart was successful
|
||||
if (strpos($output, 'completed successfully') !== false) {
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => "PHP {$version}-FPM service restarted successfully",
|
||||
'output' => $output
|
||||
]);
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => "Failed to restart PHP {$version}-FPM service",
|
||||
'output' => $output
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user