Multiple Domain with SSL points to same document root

Recently we migrated an application from cpanel to virtualmin manually and we are struggling to understand how to create a virtualhost which points to an existing document root. In cpanel you can do this with an addon domain with same document root and also you can install a separate ssl certificate.

Example:
https://primary.com (ssl enabled and pointing to /home/primary/public_html)
https://secondary.com (trying to point to the same document root /home/primary/public_html with a separate ssl certificate)

I know you can use alias for this purpose but alias wont allow you to install a new certificate.

Any suggestions or ideas greatly appreciated!

just an update:
OS: CentOS 7

https://www.virtualmin.com/node/37631
I followed the above instructions and edited the document root manually ‘/etc/httpd/conf/httpd.conf’ to point to the same path, but it leads to some other serious issues…

  1. PHP script execution mode changes to Apache mod_php and cannot be changed
  2. PHP Version selection not working

here is the edited config

SuexecUserGroup “#506” “#506
ServerName secondary.com
ServerAlias www.secondary.com
ServerAlias webmail.secondary.com
ServerAlias admin.secondary.com
DocumentRoot /home/primary.com/public_html
ErrorLog /var/log/virtualmin/secondary.com_error_log
CustomLog /var/log/virtualmin/secondary.com_access_log combined
ScriptAlias /cgi-bin/ /home/primary.com/domains/secondary.com/cgi-bin/
DirectoryIndex index.html index.htm index.php index.php4 index.php5

<Directory /home/primary.com/public_html>
Options -Indexes +IncludesNOEXEC +SymLinksIfOwnerMatch +ExecCGI
allow from all
AllowOverride All Options=ExecCGI,Includes,IncludesNOEXEC,Indexes,MultiViews,SymLinksIfOwnerMatch
Require all granted
AddType application/x-httpd-php .php
AddHandler fcgid-script .php
AddHandler fcgid-script .php5
AddHandler fcgid-script .php5.6
FCGIWrapper /home/primary.com/domains/secondary.com/fcgi-bin/php5.6.fcgi .php
FCGIWrapper /home/primary.com/domains/secondary.com/fcgi-bin/php5.fcgi .php5
FCGIWrapper /home/primary.com/domains/secondary.com/fcgi-bin/php5.6.fcgi .php5.6

<Directory /home/primary.com/domains/secondary.com/cgi-bin>
allow from all
AllowOverride All Options=ExecCGI,Includes,IncludesNOEXEC,Indexes,MultiViews,SymLinksIfOwnerMatch
Require all granted

RewriteEngine on
RewriteCond %{HTTP_HOST} =webmail.secondary.com
RewriteRule ^(.) https://secondary.com:20000/ [R]
RewriteCond %{HTTP_HOST} =admin.secondary.com
RewriteRule ^(.
) https://secondary.com:10000/ [R]
RemoveHandler .php
RemoveHandler .php5
RemoveHandler .php5.6
php_admin_value engine Off
FcgidMaxRequestLen 1073741824
SSLEngine on
SSLCertificateFile /home/primary.com/domains/secondary.com/ssl.cert
SSLCertificateKeyFile /home/primary.com/domains/secondary.com/ssl.key
SSLProtocol all -SSLv2 -SSLv3 -TLSv1 -TLSv1.1
SSLCACertificateFile /home/primary.com/domains/secondary.com/ssl.ca
IPCCommTimeout 31

I got it fixed by changing all the paths on the config to primary domain except for ssl path

SuexecUserGroup "#506" "#506" ServerName secondary.com ServerAlias www.secondary.com ServerAlias webmail.secondary.com ServerAlias admin.secondary.com DocumentRoot /home/primary.com/public_html ErrorLog /var/log/virtualmin/secondary.com_error_log CustomLog /var/log/virtualmin/secondary.com_access_log combined ScriptAlias /cgi-bin/ /home/primary.com/cgi-bin/ DirectoryIndex index.html index.htm index.php index.php4 index.php5

<Directory /home/primary.com/public_html>
Options -Indexes +IncludesNOEXEC +SymLinksIfOwnerMatch +ExecCGI
allow from all
AllowOverride All Options=ExecCGI,Includes,IncludesNOEXEC,Indexes,MultiViews,SymLinksIfOwnerMatch
Require all granted
AddType application/x-httpd-php .php
AddHandler fcgid-script .php
AddHandler fcgid-script .php5
AddHandler fcgid-script .php5.6
FCGIWrapper /home/primary.com/fcgi-bin/php5.6.fcgi .php
FCGIWrapper /home/primary.com/fcgi-bin/php5.fcgi .php5
FCGIWrapper /home/primary.com/fcgi-bin/php5.6.fcgi .php5.6

<Directory /home/primary.com/cgi-bin>
allow from all
AllowOverride All Options=ExecCGI,Includes,IncludesNOEXEC,Indexes,MultiViews,SymLinksIfOwnerMatch
Require all granted

RewriteEngine on
RewriteCond %{HTTP_HOST} =webmail.secondary.com
RewriteRule ^(.) https://secondary.com:20000/ [R]
RewriteCond %{HTTP_HOST} =admin.secondary.com
RewriteRule ^(.
) https://secondary.com:10000/ [R]
RemoveHandler .php
RemoveHandler .php5
RemoveHandler .php5.6
php_admin_value engine Off
FcgidMaxRequestLen 1073741824
SSLEngine on
SSLCertificateFile /home/primary.com/domains/secondary.com/ssl.cert
SSLCertificateKeyFile /home/primary.com/domains/secondary.com/ssl.key
SSLProtocol all -SSLv2 -SSLv3 -TLSv1 -TLSv1.1
SSLCACertificateFile /home/primary.com/domains/secondary.com/ssl.ca
IPCCommTimeout 31