This commit is contained in:
Bozhidar 2024-05-14 13:15:26 +03:00
parent f3b7cebb21
commit 18dfe257fb
3 changed files with 56 additions and 41 deletions

View file

@ -42,23 +42,21 @@ class Settings extends BaseSettings
// Restart supervisor
shell_exec('service supervisor restart');
if ($oldMasterDomain != setting('general.master_domain')) {
// Make master domain virtual host
$masterDomain = new MasterDomain();
$masterDomain->configureVirtualHost();
}
$wildcardDomain = setting('general.wildcard_domain');
if ($oldWildcardDomain != $wildcardDomain) {
// Make wildcard domain virtual host
$masterDomain = new MasterDomain();
$masterDomain->domain = $wildcardDomain;
$masterDomain->configureVirtualHost();
}
file_put_contents('/var/www/html/index.html', setting('general.master_domain_page_html'));
$rebuildApache = false;
if ($oldMasterDomain != setting('general.master_domain')) {
$rebuildApache = true;
}
if ($oldWildcardDomain != setting('general.wildcard_domain')) {
$rebuildApache = true;
}
if ($rebuildApache) {
$apacheBuild = new \App\VirtualHosts\ApacheBuild();
$apacheBuild->fixPermissions();
$apacheBuild->build();
}
}
public function schema(): array|Closure

View file

@ -32,7 +32,7 @@ class MasterDomain
}
public function configureVirtualHost()
public function configureVirtualHost($fixPermissions = false)
{
// check is valid domain
if (!filter_var($this->domain, FILTER_VALIDATE_DOMAIN)) {
@ -49,14 +49,11 @@ class MasterDomain
$apacheBaseConfig = $apacheVirtualHostBuilder->buildConfig();
shell_exec('mkdir -p /var/www/logs/apache2');
shell_exec('touch /var/www/logs/apache2/bytes.log');
shell_exec('touch /var/www/logs/apache2/access.log');
shell_exec('touch /var/www/logs/apache2/error.log');
if (!empty($apacheBaseConfig)) {
file_put_contents('/etc/apache2/sites-available/zzz-'.$this->domain.'.conf', $apacheBaseConfig);
shell_exec('ln -s /etc/apache2/sites-available/zzz-'.$this->domain.'.conf /etc/apache2/sites-enabled/zzz-'.$this->domain.'.conf');
if ($fixPermissions) {
shell_exec('mkdir -p /var/www/logs/apache2');
shell_exec('touch /var/www/logs/apache2/bytes.log');
shell_exec('touch /var/www/logs/apache2/access.log');
shell_exec('touch /var/www/logs/apache2/error.log');
}
// Install SSL
@ -88,6 +85,8 @@ class MasterDomain
}
}
$apacheBaseConfigWithSSL = null;
if ($findDomainSSLCertificate) {
$certsFolderName = $findDomainSSLCertificate->domain;
@ -122,27 +121,12 @@ class MasterDomain
$apacheVirtualHostBuilder->setSSLCertificateChainFile($sslCertificateChainFile);
$apacheBaseConfigWithSSL = $apacheVirtualHostBuilder->buildConfig();
if (!empty($apacheBaseConfigWithSSL)) {
// Add SSL options conf file
$apache2SSLOptionsSample = view('actions.samples.ubuntu.apache2-ssl-options-conf')->render();
$apache2SSLOptionsFilePath = '/etc/apache2/phyre/options-ssl-apache.conf';
if (!file_exists($apache2SSLOptionsFilePath)) {
if (!is_dir('/etc/apache2/phyre')) {
mkdir('/etc/apache2/phyre');
}
file_put_contents($apache2SSLOptionsFilePath, $apache2SSLOptionsSample);
}
file_put_contents('/etc/apache2/sites-available/zzz-'.$this->domain.'-ssl.conf', $apacheBaseConfigWithSSL);
shell_exec('ln -s /etc/apache2/sites-available/zzz-'.$this->domain.'-ssl.conf /etc/apache2/sites-enabled/zzz-'.$this->domain.'-ssl.conf');
}
}
// End install SSL
if ($fixPermissions) {
$domainIndexFile = $this->domainPublic . '/index.html';
if (file_exists($domainIndexFile)) {
$domainIndexFileContent = file_get_contents($domainIndexFile);
@ -154,6 +138,12 @@ class MasterDomain
shell_exec('chown -R www-data:www-data ' . $this->domainPublic);
shell_exec('chmod -R 755 ' . $this->domainPublic);
shell_exec('systemctl restart apache2');
}
return [
'apacheBaseConfig' => $apacheBaseConfig,
'apacheBaseConfigWithSSL' => $apacheBaseConfigWithSSL ?? null
];
}
}

View file

@ -2,6 +2,7 @@
namespace App\VirtualHosts;
use App\MasterDomain;
use App\Models\Domain;
class ApacheBuild
@ -94,6 +95,32 @@ IncludeOptional conf-enabled/*.conf
}
}
if (!empty(setting('general.master_domain'))) {
// Make master domain virtual host
$masterDomain = new MasterDomain();
$domainVirtualHost = $masterDomain->configureVirtualHost($this->fixPermissions);
if (isset($domainVirtualHost['apacheBaseConfig'])) {
$virtualHostMerged .= $domainVirtualHost['apacheBaseConfig'] . "\n\n";
}
if (isset($domainVirtualHost['apacheBaseConfigWithSSL'])) {
$virtualHostMerged .= $domainVirtualHost['apacheBaseConfigWithSSL'] . "\n\n";
}
}
$wildcardDomain = setting('general.wildcard_domain');
if (!empty($wildcardDomain)) {
// Make wildcard domain virtual host
$masterDomain = new MasterDomain();
$masterDomain->domain = $wildcardDomain;
$domainVirtualHost = $masterDomain->configureVirtualHost($this->fixPermissions);
if (isset($domainVirtualHost['apacheBaseConfig'])) {
$virtualHostMerged .= $domainVirtualHost['apacheBaseConfig'] . "\n\n";
}
if (isset($domainVirtualHost['apacheBaseConfigWithSSL'])) {
$virtualHostMerged .= $domainVirtualHost['apacheBaseConfigWithSSL'] . "\n\n";
}
}
file_put_contents('/etc/apache2/apache2.conf', $virtualHostMerged);
shell_exec('systemctl reload apache2');