diff --git a/install/lib/install.lib.php b/install/lib/install.lib.php
index bf93cad1f9d14008f1ee2d316550588d2bf495b0..4af0d54dba2255e48001258a709ea777f2cc7af2 100644
--- a/install/lib/install.lib.php
+++ b/install/lib/install.lib.php
@@ -530,6 +530,9 @@ function replaceLine($filename,$search_pattern,$new_line,$strict = 0) {
 			}
 		}
 		if($found == 0) {
+			//* add \n if the last line does not end with \n or \r
+			if(substr($out,-1) != "\n" && substr($out,-1) != "\r") $out .= "\n";
+			//* add the new line at the end of the file
 			$out .= $new_line."\n";
 		}
 		file_put_contents($filename,$out);
diff --git a/install/lib/installer_base.lib.php b/install/lib/installer_base.lib.php
index d05bf60333ebd3b200a8cafe331d483d23f21b2a..ea4e382cc0868ce88da29dd26f020017aacd5f39 100644
--- a/install/lib/installer_base.lib.php
+++ b/install/lib/installer_base.lib.php
@@ -706,6 +706,11 @@ class installer_base {
 			replaceLine('/etc/apache2/sites-available/000-default','<VirtualHost *>','<VirtualHost *:80>',1);
 		}
 		
+		if(is_file('/etc/apache2/ports.conf')) {
+			// add a line "Listen 443" to ports conf if line does not exist
+			replaceLine('/etc/apache2/ports.conf','Listen 443','Listen 443',1);
+		}
+		
 		
 		//* Copy the ISPConfig configuration include
         $vhost_conf_dir = $conf['apache']['vhost_conf_dir'];