diff --git a/app/Factories/NginxVhostFactory.php b/app/Factories/NginxVhostFactory.php index 253be5a..beb3756 100644 --- a/app/Factories/NginxVhostFactory.php +++ b/app/Factories/NginxVhostFactory.php @@ -168,9 +168,18 @@ class NginxVhostFactory // check status if ($menu->getSelectedItem()->getChecked()) { symlink('/etc/nginx/sites-available/'.$vhost['file'], '/etc/nginx/sites-enabled/'.$vhost['file']); + exec('nginx -c /etc/nginx/nginx.conf -t 2>&1', $output); + $result = preg_match_all("/syntax is ok/", implode(' ', $output), $output); + + // restart if success message was found + if ($result > 0) { + exec('service nginx restart'); + $menu->confirm('Success! ')->display('OK!'); - if ($output) { + $vhost['enabled'] = true; + $status = 'enabled'; + } else { unlink('/etc/nginx/sites-enabled/'.$vhost['file']); $menu->confirm('Error! Configuration not Working!')->display('OK!'); @@ -179,15 +188,6 @@ class NginxVhostFactory $vhost['enabled'] = false; $status = 'disabled'; - } else { - - // restart - exec('service nginx restart'); - $menu->confirm('Success! ')->display('OK!'); - - $vhost['enabled'] = true; - $status = 'enabled'; - } } else { unlink('/etc/nginx/sites-enabled/'.$vhost['file']);