feat: implement Nginx and PHP service management IPC handlers with dynamic configuration generation
This commit is contained in:
+39
-1
@@ -187,11 +187,26 @@ export function registerIpcHandlers(): void {
|
||||
if (!fs.existsSync(sessionDir)) fs.mkdirSync(sessionDir, { recursive: true })
|
||||
if (!fs.existsSync(tempDir)) fs.mkdirSync(tempDir, { recursive: true })
|
||||
|
||||
// --- 1. Get extensions from local php.ini ---
|
||||
let extensionsList = ''
|
||||
const localIniPath = path.join(phpDir, 'php.ini')
|
||||
if (fs.existsSync(localIniPath)) {
|
||||
const localIniContent = fs.readFileSync(localIniPath, 'utf8')
|
||||
const extMatches = localIniContent.match(/^\s*extension\s*=.*$/gm)
|
||||
if (extMatches) {
|
||||
extensionsList = extMatches.join('\n')
|
||||
}
|
||||
} else {
|
||||
// Fallback to minimal set if missing
|
||||
extensionsList = 'extension=curl\nextension=mbstring\nextension=openssl\nextension=mysqli\nextension=pdo_mysql'
|
||||
}
|
||||
|
||||
const configPath = await configService.generateConfig('php.ini.template', `php_${phpVersion || 'default'}.ini`, {
|
||||
EXT_DIR: extDir,
|
||||
GD_EXT: gdExtName,
|
||||
SESSION_DIR: sessionDir,
|
||||
TEMP_DIR: tempDir
|
||||
TEMP_DIR: tempDir,
|
||||
EXTENSIONS: extensionsList
|
||||
})
|
||||
|
||||
const success = await processManager.startService(serviceName, binPath, ['-b', `127.0.0.1:${phpPort}`, '-c', configPath], false)
|
||||
@@ -370,6 +385,29 @@ export function registerIpcHandlers(): void {
|
||||
return result
|
||||
})
|
||||
|
||||
ipcMain.handle('php:config:get', async (_event, version: string) => {
|
||||
const phpDir = path.join(configService.getBasePath(), 'bin', `php-${version}`)
|
||||
const iniPath = path.join(phpDir, 'php.ini')
|
||||
if (fs.existsSync(iniPath)) {
|
||||
return fs.readFileSync(iniPath, 'utf8')
|
||||
}
|
||||
return ''
|
||||
})
|
||||
|
||||
ipcMain.handle('php:config:save', async (_event, { version, content }) => {
|
||||
const phpDir = path.join(configService.getBasePath(), 'bin', `php-${version}`)
|
||||
const iniPath = path.join(phpDir, 'php.ini')
|
||||
fs.writeFileSync(iniPath, content)
|
||||
|
||||
// Return a result that indicates a restart is needed
|
||||
const serviceName = `php:${version}`
|
||||
const isRunning = processManager.isServiceRunning(serviceName)
|
||||
if (isRunning) {
|
||||
await processManager.stopService(serviceName)
|
||||
}
|
||||
return { success: true, message: `php.ini saved.${isRunning ? ' Current PHP service stopped. Please restart to apply.' : ''}` }
|
||||
})
|
||||
|
||||
// MariaDB Versions
|
||||
ipcMain.handle('mariadb:versions', async () => {
|
||||
return await mariaDbManagerService.getVersions()
|
||||
|
||||
Reference in New Issue
Block a user