Location: PHPKode > scripts > Apache-MySQL-PHP Manager > web.php
<?php

$setting = array (
	"APPLICATION" => array (
		//    APPLICATIONNAME, HTDOCS,                     APACHECONFFILE,                         PHPDIR,       PHPINIDIR
		array("GenericPHP52",  "/web/htdocs",              '/web/Apache/conf/httpd-modified.conf', '/web/php52', '/web/php52'),
		array("GenericPHP53",  "/web/htdocs",              '/web/Apache/conf/httpd-modified.conf', '/web/php53', '/web/php53'),
		array("Pimcore"     ,  "/web/htdocs/pimcore",      '/web/Apache/conf/httpd-modified.conf', '/web/php53', '/web/php53'),
		array("Phreeze"     ,  "/web/htdocs/phreeze",      '/web/Apache/conf/httpd-modified.conf', '/web/php53', '/web/php53'),
		array("zfdatagrid"  ,  "/web/htdocs/zfdatagrid",   '/web/Apache/conf/httpd-modified.conf', '/web/php53', '/web/php53'),
		array("Kohana"      ,  "/web/htdocs/kohana-3.1.2", '/web/Apache/conf/httpd-modified.conf', '/web/php53', '/web/php53')
	),
	"PORTNUMBER" => array(80, 81, 82, 83, 84)
);

$webIniTemplate1 = <<<'EOS1'
[Config]
ImageList=web.bmp
TrayIconAllRunning=9
TrayIconSomeRunning=10
TrayIconNoneRunning=1

[StartupAction]
Action: "run"; FileName: "\web\php53\php.exe"; Parameters: "-f %AeTrayMenuPath%\web.php"; Flags: "waituntilterminated"; ShowCmd: "hidden";
Action: "readconfig";
;Action: "run"; FileName: "\web\mysql\bin\mysqld.exe"; ShowCmd: "hidden";

[Menu.Left.Settings]
BarVisible=yes
BarCaptionAlignment=bottom
BarCaptionCaption=WEB SERVER: Apache - PHP - MySQL
BarCaptionFont=Tahoma,10

[Menu.Left]
EOS1;

$webIniTemplate2 = 'Type: "item"; Action: "run"; FileName: "nul"; Flags: "ignoreerrors"; Caption: "port <PORTNUMBER>: -";';

$webIniTemplate3 = <<< 'EOS3'
	Type: "separator";
Type: "item"; Caption: "MySQL console"; Action: "run"; FileName: "\web\mysql\bin\mysql.exe";  Parameters: "-u root";
EOS3;

$webIniTemplate4 = 'Type: "submenu"; Caption: "<APPLICATIONNAME>"; <SPACER>SubMenu: "SubMenu.<APPLICATIONNAME>";';

$webIniTemplate5 = <<<'EOS5'
	Type: "separator";
Type: "item"; Caption: "Stop all and Reload Menu"; Action: "multi"; Actions: "StopAndReload";
Type: "item"; Caption: "Exit"; Action: "multi"; Actions: "Exit";

[StopAndReload]
EOS5;

$webIniTemplate6 = <<<'EOS6'
Action: "run"; ShowCmd: "hidden"; Flags: "waituntilterminated"; FileName: "\web\Apache\bin\httpd.exe"; Parameters: "-k stop -n Apache.<APPLICATIONNAME>.<PORTNUMBER>";
Action: "run"; ShowCmd: "hidden"; Flags: "waituntilterminated"; FileName: "\web\Apache\bin\httpd.exe"; Parameters: "-k uninstall -n Apache.<APPLICATIONNAME>.<PORTNUMBER>";
EOS6;

$webIniTemplate7 = <<<'EOS7'
Action: "run"; FileName: "\web\php53\php.exe"; Parameters: "-f %AeTrayMenuPath%\web.php"; Flags: "waituntilterminated"; ShowCmd: "hidden";
Action: "readconfig";
EOS7;

$webIniTemplate8 = '[SubMenu.<APPLICATIONNAME>]';

$webIniTemplate9 = 'Type: "item"; Caption: "port <PORTNUMBER>"; Action: "multi"; Actions: "Run.<APPLICATIONNAME>.<PORTNUMBER>"; Glyph: "18";';

$webIniTemplate10 = '[Run.<APPLICATIONNAME>.<PORTNUMBER>]';

$webIniTemplate11 = <<<'EOS9'
Action: "run"; ShowCmd: "hidden"; Flags: "waituntilterminated"; FileName: "\web\php53\php.exe"; Parameters: "-f %AeTrayMenuPath%\web.php -- Run.<APPLICATIONNAME>.<PORTNUMBER>";
Action: "run"; ShowCmd: "hidden"; Flags: "waituntilterminated"; FileName: "\web\Apache\bin\httpd.exe"; Parameters: "-k install -n Apache.<APPLICATIONNAME>.<PORTNUMBER>";
Action: "run"; ShowCmd: "hidden"; Flags: "waituntilterminated"; FileName: "\web\Apache\bin\httpd.exe"; Parameters: "-k start -n Apache.<APPLICATIONNAME>.<PORTNUMBER> -f <APACHECONFFILE>";
Action: "readconfig";
EOS9;

$webIniTemplate12 = '[Stop.<APPLICATIONNAME>.<PORTNUMBER>]';

$webIniTemplate13 = <<<'EOS13'
Action: "run"; ShowCmd: "hidden"; Flags: "waituntilterminated"; FileName: "\web\php53\php.exe"; Parameters: "-f %AeTrayMenuPath%\web.php -- Stop.<APPLICATIONNAME>.<PORTNUMBER>";
Action: "run"; ShowCmd: "hidden"; Flags: "waituntilterminated"; FileName: "\web\Apache\bin\httpd.exe"; Parameters: "-k stop -n Apache.<APPLICATIONNAME>.<PORTNUMBER>";
Action: "run"; ShowCmd: "hidden"; Flags: "waituntilterminated"; FileName: "\web\Apache\bin\httpd.exe"; Parameters: "-k uninstall -n Apache.<APPLICATIONNAME>.<PORTNUMBER>";
Action: "readconfig";
EOS13;

$webIniTemplate14 = '[Replace.<APPLICATIONNAME>.<PORTNUMBER>]';

$webIniTemplate15 = <<< 'EOS15'
Action: "run"; ShowCmd: "hidden"; Flags: "waituntilterminated"; FileName: "\web\Apache\bin\httpd.exe"; Parameters: "-k stop -n Apache.<APPLICATIONNAME>.<PORTNUMBER>";
Action: "run"; ShowCmd: "hidden"; Flags: "waituntilterminated"; FileName: "\web\Apache\bin\httpd.exe"; Parameters: "-k uninstall -n Apache.<APPLICATIONNAME>.<PORTNUMBER>";
EOS15;

$webIniTemplate16 = <<< 'EOS16'
Action: "run"; ShowCmd: "hidden"; Flags: "waituntilterminated"; FileName: "\web\Apache\bin\httpd.exe"; Parameters: "-k install -n Apache.<APPLICATIONNAME>.<PORTNUMBER>";
Action: "run"; ShowCmd: "hidden"; Flags: "waituntilterminated"; FileName: "\web\Apache\bin\httpd.exe"; Parameters: "-k start -n Apache.<APPLICATIONNAME>.<PORTNUMBER> -f <APACHECONFFILE>";
Action: "run"; ShowCmd: "hidden"; Flags: "waituntilterminated"; FileName: "\web\php53\php.exe"; Parameters: "-f %AeTrayMenuPath%\web.php -- Replace.<APPLICATIONNAME>.<PORTNUMBER>";
Action: "readconfig";
EOS16;


//--------------------------------------------------------------------------------------------

$argv = preg_replace("|^\w+:|", "", $argv);

$maxSpacer = 0;
foreach ($setting["APPLICATION"] as $key => $val) {
	$maxSpacer = $maxSpacer > strlen($val[0]) ? $maxSpacer : strlen($val[0]);
}

// initialization: OK!
if (!$argv[1]) {
	foreach ($setting["PORTNUMBER"] as $key => $val) {
		$webIniString2 .= str_replace('<PORTNUMBER>', $val, $webIniTemplate2) . "\n";
	}

	foreach ($setting["APPLICATION"] as $key => $val1) {
		$spacerCount = $maxSpacer - strlen($val1[0]);
		$spacer = "";
		for ($i=0; $i<$spacerCount; $i++) {
			$spacer .= " ";
		}
		$temp = str_replace('<APPLICATIONNAME>', $val1[0], $webIniTemplate4) . "\n";
		$temp = str_replace('<SPACER>', $spacer, $temp);
		$webIniString4 .= $temp;

		$webIniString8 = str_replace('<APPLICATIONNAME>', $val1[0], $webIniTemplate8);
		$webIniString9 = "";
		$webIniString10_11 = "";
		$webIniString12_13 = "";
		foreach ($setting["PORTNUMBER"] as $key => $val2) {
			$pattern     = array('<PORTNUMBER>', '<APPLICATIONNAME>', '<HTDOCS>', '<APACHECONFFILE>', '<PHPDIR>', '<PHPINIDIR>');
			$replacement = array($val2,          $val1[0],            $val1[1],   $val1[2],           $val1[3],   $val1[4]);

			$webIniString6 .= str_replace($pattern, $replacement, $webIniTemplate6) ."\n";
		
			$webIniString9 .= str_replace($pattern, $replacement, $webIniTemplate9) . "\n";
			$webIniString10_11 .= str_replace($pattern, $replacement, $webIniTemplate10) ."\n".
								  str_replace($pattern, $replacement, $webIniTemplate11) . "\n\n";
			$webIniString12_13 .= str_replace($pattern, $replacement, $webIniTemplate12) ."\n".
								  str_replace($pattern, $replacement, $webIniTemplate13) . "\n\n";

			$webIniArray14[$val1[0]]["port$val2"] = str_replace($pattern, $replacement, $webIniTemplate14) ."\n";
			$webIniArray15["port$val2"] .= str_replace($pattern, $replacement, $webIniTemplate15) . "\n";
			$webIniArray16[$val1[0]]["port$val2"] = str_replace($pattern, $replacement, $webIniTemplate16) . "\n\n\n";
		}
		
		$webIniString8_9_10_11_12_13 .= $webIniString8 ."\n". $webIniString9 ."\n". $webIniString10_11 ."\n". $webIniString12_13;
	}

	foreach ($webIniArray14 as $webIniArray14MainKey => $webIniArray14Item) {
		foreach ($webIniArray14Item as $webIniArray14Key => $webIniArray14Val) {
			$webIniString14_15_16 .= $webIniArray14Val . $webIniArray15[$webIniArray14Key] . $webIniArray16[$webIniArray14MainKey][$webIniArray14Key];
		}
	}

	$webIniContent =
		$webIniTemplate1 ."\n".
		$webIniString2 .
		$webIniTemplate3 ."\n".
		$webIniString4 .
		$webIniTemplate5 ."\n".
		$webIniString6 .
		$webIniTemplate7 ."\n\n\n".
		"[Exit]" ."\n".
		$webIniString6 .
		'Action: "exit";' ."\n\n\n".
		$webIniString8_9_10_11_12_13 ."\n".
		$webIniString14_15_16;

// port status: OK!
} else {
	$webIniContent = file_get_contents("/web/web.ini");

	$params = explode('.', $argv[1]);
	$processStatus = $params[0];
	$applicationName = $params[1];
	$portNumber = $params[2];

	if ($processStatus == 'Run') {
		$spacerCount = $maxSpacer - strlen($applicationName);
		$glyphNumber = 16;
		$portUsedBy = $applicationName;
		$newProcess = 'Stop';
	} else {
		$spacerCount = $maxSpacer - 1;
		$glyphNumber = 18;
		$portUsedBy = '-';
		$newProcess = 'Run';
	}
	$spacer = "";
	for ($i=0; $i<$spacerCount; $i++) {
		$spacer .= " ";
	}

	// port description: OK!
	$webIniContent = preg_replace(
						'/"(port ' .$portNumber. ': )[^"]+";/',
						'"$1' .$portUsedBy. '";',
						$webIniContent
					);

	// menu icon: OK!
	if ($processStatus == 'Run') {
		$webIniContent = preg_replace(
							'/Run(\.\w+\.' .$portNumber. ')"; Glyph: "1\d";/',
							"Replace$1". '"; Glyph: "17";',
							$webIniContent
						);
		$webIniContent = preg_replace(
						'/Replace' .".$applicationName.$portNumber". '"; Glyph: "1\d";/',
						$argv[1]. '"; Glyph: "' .$glyphNumber. '";',
						$webIniContent
					);
	} else if ($processStatus == 'Stop') {
		$webIniContent = preg_replace(
						'/(Stop|Replace)(\.\w+\.' .$portNumber. ')"; Glyph: "1\d";/',
						"Run$1". '"; Glyph: "18";',
						$webIniContent
					);
	} else if ($processStatus == 'Replace') {
		$webIniContent = preg_replace(
						'/Stop(\.\w+\.' .$portNumber. ')"; Glyph: "1\d";/',
						"Replace$1". '"; Glyph: "17";',
						$webIniContent
					);
		$webIniContent = preg_replace(
						'/Replace(' .".$applicationName.$portNumber". ')"; Glyph: "1\d";/',
						"Stop$1". '"; Glyph: "16";',
						$webIniContent
					);
	}

	// run-stop switch: OK!
	$webIniContent = str_replace(
					'Actions: "' .$argv[1],
					'Actions: "' ."$newProcess.$applicationName.$portNumber",
					$webIniContent
				);

	// httpd.conf: OK!
	if ($processStatus == 'Run' or $processStatus == 'Replace') {
		foreach ($setting["APPLICATION"] as $itemKey => $itemVal) {
			if ($itemVal[0] == $applicationName) {
				$phpIniContent = file_get_contents($itemVal[2]);

				$pattern = array(
					'/^LoadModule\s+php5_module\s+.+/m',
					'/^PHPIniDir\s+.+/m',
					'/^Listen\s+.+/m',
					'/^DocumentRoot\s+.+/m',
					'/(This should be changed to whatever you set DocumentRoot to.\r*\n#\r*\n<Directory)\s+.+/m',
				);
				$replacement = array(
					'LoadModule php5_module "' .$itemVal[3]. '/php5apache2_2.dll"',
					'PHPIniDir "' .$itemVal[3]. '"',
					'Listen "' .$portNumber. '"',
					'DocumentRoot "' .$itemVal[1]. '"',
					'$1 "' .$itemVal[1]. '">',
				);
				$phpIniContent = preg_replace(
					$pattern,
					$replacement,
					$phpIniContent
				);

				file_put_contents($itemVal[2], $phpIniContent);
			}
		}
	}
}
file_put_contents("/web/web.ini", $webIniContent);

?>
Return current item: Apache-MySQL-PHP Manager