Adding features to Virtualmin template

15 posts / 0 new
Last post
#1 Sun, 06/28/2009 - 16:59

Adding features to Virtualmin template

Hi! is a virtual server containing phpMyAdmin is for webmail

I host a few domains. Each time I create a VH for a new one I have to manually add an alias like




in their respective at httpd.conf

Is it possible to add those alias from the template each time a new VH is created?
Thank you

Mon, 06/29/2009 - 08:44

Hmm, I don't believe there is an option for specifically that -- but there is an option for executing a script during the creation of a Virtual Server.

What you could do is create a script that uses the command line tools to create the aliases (and anything else you might want) during the setup of any new Virtual Servers.

You can set that up withing System Settings -> Module Config -> Actions Upon User and Server Creation -> "Command to run after making changes to a server".

You can get a listing of what options are available to you on the command line by typing the command "virtualmin".


Mon, 06/29/2009 - 11:38

I don't know how to handle this.
modify-web is an option I found.
# virtualmin modify-web [args]

In command line what I need is something like this:
cp httpd.conf httpd.conf.BACK; sed -i 's/ServerAlias sql.newDomainAlias/' httpd.conf

In other words: make a backup of httpd.conf and substitute the text
ServerAlias sql.newDomainAlias

So the second alias listed alias would be the new one.
The first one already exists.

Thank you

Mon, 06/29/2009 - 11:52

Rather than "modify-web", it sounds like what you want is a new Alias Server.

So you could use something like:

virtualmin create-domain --domain --alias

Mon, 06/29/2009 - 12:35 (Reply to #4)

Eric, Can I test it from command line? Does this command 'contain' httpd restart? Thanks

Mon, 06/29/2009 - 13:21 (Reply to #5)

I'm not sure whether that restarts Apache or not. The best I can offer is that if it doesn't work, try restarting Apache :-)

That'd either be "/etc/init.d/apache2 restart" or "/etc/init.d/httpd restart" depending on your distro.

To test it from the command line, you could use a tool like links or wget.


Mon, 06/29/2009 - 15:40

Eric, My question was about adding a command line into a virtualmin template for new virtual hosts. That should be automatic.

Tue, 06/30/2009 - 10:22

I give up on this line. The option create-domain displays 'You are already hosting this domain'. There is an option modify-domain but it does not have an alias suboption.

Maybe it would be easier to add to the template something like

RewriteCond %{HTTP_HOST} RewriteRule ^(.*) [R]

You have some similar rules for other subdomains like webmail but I could not find where to add this rewrite rule.

RewriteEngine on RewriteCond %{HTTP_HOST} RewriteRule ^(.*) https:/ [R]

I also have researched in # virtualmin get-template --id 0

Thank you

Tue, 06/30/2009 - 10:02

Yeah, the webmail and admin aliases are added automatically by Virtualmin.

But, you could add something similar by editing the template in System Settings -> Server Templates -> Default -> Apache Website.

However, if you're getting the message "You are already hosting this domain" -- are you sure the address hasn't been setup somewhere else already? That could cause trouble if it has been ;-)


Tue, 06/30/2009 - 10:42

[quote]are you sure the address hasn't been setup somewhere else already? [/quote]
Well. I only am trying to add Alias into directory.

Under "Apache" template do not appear those rewrite conditions.
ServerName ${DOM}
ServerAlias www.${DOM}
DocumentRoot ${HOME}/public_html
ErrorLog /var/log/virtualmin/${DOM}_error_log
CustomLog /var/log/virtualmin/${DOM}_access_log combined
ScriptAlias /cgi-bin/ ${HOME}/cgi-bin/
DirectoryIndex index.php index.html index.htm index.php4 index.php5

Options -Indexes IncludesNOEXEC FollowSymLinks
allow from all
AllowOverride All

allow from all

I created a testing VS that contains
RewriteEngine on
RewriteCond %{HTTP_HOST}
RewriteRule ^(.*) [R]
RewriteCond %{HTTP_HOST}
RewriteRule ^(.*) [R]

Anyway I might add my rewrite conditions in Apache template but I should have to have 'RewriteEngine On' twice in httpd.conf

Fri, 07/03/2009 - 14:14

No answers for this?

Fri, 07/03/2009 - 14:31

It didn't sound like your latest post contained a question :-)

I'm not quite sure I'm following what you're trying to do there -- but if you're referring to the "" Alias you're trying to add giving you the "You are already hosting this domain" message -- are you sure that isn't setup somewhere else within Apache already?


Fri, 07/03/2009 - 14:44

Hi Eric,
Yes, this is an invented name, just to test.

The remaining question was about where do you have set those rewriting conditions in default template. I couldn't find them on any place. I would add to webmail and admin this RewriteCond %{HTTP_HOST} RewriteRule ^(.*) [R]

But I don't know where. Thank you!

Fri, 07/03/2009 - 14:51 (Reply to #13)

You should only ever see "You are already hosting this domain" when adding a domain that's already defined in Apache.

I'd double, perhaps triple check that it's not in there anywhere, as I suspect it's hiding in there somewhere :-)

But, if you're super-super-super sure that it exists no where in Apache, then it's a bug, so you may need to file a bug report in the Support Tracker for that.

Regarding the mod_rewrite stuff -- the webmail and admin parts are automatically added by Virtualmin that's not defined in any template.

Virtualmin will add it if the "Redirect webmail.domain to Usermin" and "Redirect admin.domain to Usermin" options are set to "Yes" in System Settings -> Server Templates -> Default -> Apache Website.

To add in additional directives, you could put them in "Directives and settings for new websites" on that same page.


Fri, 07/03/2009 - 18:40 (Reply to #14)

Eric, I know that about "Directives and settings for new websites" I was asking that I can input those directives but "Rewrite engine on" will be placed twice and this is not good.

Topic locked