|
|
@@ -293,62 +293,14 @@ class SiteController {
|
|
|
echo json_encode(['error' => 'Missing required parameters']);
|
|
|
return;
|
|
|
}
|
|
|
- $webDir = "/home/$username/prod.$domain";
|
|
|
- $configFile = "/etc/apache2/sites-enabled/prod.$domain.conf";
|
|
|
- $configTemplate = '/etc/apache2/site-config.in';
|
|
|
- exec("sudo /usr/bin/mkdir $webDir", $mkdirOutput, $mkdirReturnCode);
|
|
|
- if ($mkdirReturnCode !== 0) {
|
|
|
- http_response_code(500);
|
|
|
- echo json_encode(['error' => 'Failed to create web dir', 'details' => implode("\n", $mkdirOutput)]);
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- exec("sudo /usr/bin/chown $username:$username $webDir", $chownOutput, $chownReturnCode);
|
|
|
- if ($chownReturnCode !== 0) {
|
|
|
- http_response_code(500);
|
|
|
- echo json_encode(['error' => 'Failed to chown web dir', 'details' => implode("\n", $chownOutput)]);
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- $configContent = file_get_contents($configTemplate);
|
|
|
- $configContent = str_replace(['DOCUMENTROOT', 'SERVERNAME','USERNAME','DOMAINNAME', 'SERVERALIAS'], [$webDir, "prod.$domain","prod.$domain", "www.$domain" ], $configContent);
|
|
|
- file_put_contents($configFile, $configContent);
|
|
|
-
|
|
|
- exec("sudo /usr/bin/certbot certonly --webroot -w /etc/apache/letsencrypt -d www.$domain -d $domain --non-interactive --agree-tos --email admin@$domain", $output, $returnCode);
|
|
|
- if ($returnCode !== 0) {
|
|
|
- http_response_code(500);
|
|
|
- echo json_encode(['error' => 'Certbot failed', 'details' => implode("\n", $output)]);
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- exec('sudo /usr/bin/systemctl reload apache2', $apacheOutput, $apacheReturnCode);
|
|
|
- if ($apacheReturnCode !== 0) {
|
|
|
- http_response_code(500);
|
|
|
- echo json_encode(['error' => 'Failed to reload Apache', 'details' => implode("\n", $apacheOutput)]);
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
// Deployment from dev to prod
|
|
|
- exec("sudo /usr/bin/cp -r /home/$username/dev.$domain/* $webDir",$cpOutput,$cpReturnCode);
|
|
|
+ exec("sudo /usr/bin/cp -a /home/$username/dev.$domain/* /home/$username/$domain/.",$cpOutput,$cpReturnCode);
|
|
|
if ($cpReturnCode !== 0) {
|
|
|
http_response_code(500);
|
|
|
echo json_encode(['error' => 'Failed to copy dev installation into prod directory', 'details' => implode("\n", $cpOutput)]);
|
|
|
return;
|
|
|
}
|
|
|
-
|
|
|
- //TODO Replace Settings in Prod Environment
|
|
|
-
|
|
|
- if ($GLOBALS['debug'] == true) { error_log("Chown WebDir $webDir"); }
|
|
|
- exec("sudo /usr/bin/chown $username:$username $webDir -R 2>&1", $chownOutput, $chownReturnCode);
|
|
|
- if ($chownReturnCode !== 0) {
|
|
|
- error_log("deploy: chown error on $webDir, details => " . implode("\n", $chownOutput));
|
|
|
- http_response_code(500);
|
|
|
- echo json_encode(['error' => 'Failed to chown web dir', 'details' => implode("\n", $chownOutput)]);
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
echo json_encode(['success' => 'Production site successfully from dev']);
|
|
|
-
|
|
|
}
|
|
|
|
|
|
public static function undeploy($data): void {
|