diff --git a/install/lib/installer_base.lib.php b/install/lib/installer_base.lib.php
index 5e7a14a5cd261f65ac69ca80efbf9bc47487746f..b788fd7c6309bca65d7fe38baf15915dfb7225b7 100644
--- a/install/lib/installer_base.lib.php
+++ b/install/lib/installer_base.lib.php
@@ -1666,6 +1666,9 @@ class installer_base {
 		wf($conf['amavis']['config_dir'].'/conf.d/50-user', $content);
 		chmod($conf['amavis']['config_dir'].'/conf.d/50-user', 0640);
 
+		$config_dir = $conf['postfix']['config_dir'];
+		$quoted_config_dir = preg_quote($config_dir, '|');
+
 		$mail_config = $server_ini_array['mail'];
 		//* only change postfix config if amavisd is active filter
 		if($mail_server && $mail_config['content_filter'] === 'amavisd') {
@@ -1717,8 +1720,6 @@ class installer_base {
 				caselog($command." &> /dev/null", __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
 			}
 
-			$config_dir = $conf['postfix']['config_dir'];
-
 			// Adding amavis-services to the master.cf file if the service does not already exists
 			// (just remove the old service definitions and add them again)
 			$add_amavis = $this->remove_postfix_service('amavis','unix');
@@ -1779,6 +1780,9 @@ class installer_base {
 		$mail_server = ($server_ini_rec['mail_server']) ? true : false;
 		unset($server_ini_rec);
 
+		$config_dir = $conf['postfix']['config_dir'];
+		$quoted_config_dir = preg_quote($config_dir, '|');
+
 		$mail_config = $server_ini_array['mail'];
 		//* only change postfix config if rspamd is active filter
 		if($mail_server && $mail_config['content_filter'] === 'rspamd') {