shootify's picture

hello, id like to know how to add a subdomain on a concrete5 or silverstripe cms, 

the situation is this:

I have a static public ip that is working with my cms (, however i also like to install a little application on the same server but with a subdomain (, however i dont find the tools on the webmin adminstation page to achieve this. would you please guide me .thanks

Jeremy Davis's picture

For sure! That's easy! :)

Having said that there are lots of options on exactly how it behaves. What I'll try to provide is a fairly basic but functional setup that should broadly provide what you've asked for. If you need more advice or have specific requirements, please feel free to ask.

So what you are trying to achieve is called Name-based Virtual Hosting. The Apache docs are pretty good IMO, but I'll spell it out for you.

I'll assume that you want just basic Apache config to serve static HTML. If you have broader requirements, this will almost certainly require tweaks. This assumes that your new site will be and hosted from /var/www/subdomain, so you'll need to adjust that to your specifics.

Firstly, let's create the directory and a simple html test index file.

mkdir -p /var/www/subdomain
cat > /var/www/subdomain/index.html <<EOF
<!doctype html>
    <title>Test subdomain Title</title>
    <p>If you are reading this when browsing to your new subdomain, then the subdomain is working as intended. Yay! :)<p>

We'll also ensure that the webserver has access to it. FWIW I'm just granting full ownership to the webserver:

chown -R www-data:www-data /var/www/subdomain

Now, we'll create a new fairly basic virtual host site config file. My example below supports HSTS and includes a redirect from http to https:

cat > /etc/apache2/sites-available/subdomain.conf <<EOF
<VirtualHost *:80>
    UseCanonicalName On
    RewriteEngine On
    RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

<VirtualHost *:443>
    SSLEngine on
    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/subdomain/
    <IfModule mod_headers.c>
      Header always set Strict-Transport-Security "max-age=15552000; includeSubDomains"

<Directory /var/www/subdomain/>
    Options +FollowSymLinks
    AllowOverride All
    Require all granted

Now we'll enable the new site and restart Apache:

a2ensite subdomain
systemctl restart apache2

If you haven't already set up DNS for your subdomain you will need to set up a CNAME record (or an A record if you rather) to point to your server. FYI generally you would only have one A record per server, then additional subdomains would be CNAME records - however if you plan to move this to a different server, then an A record might be better). If you've only just done that, you'll need to wait for the change to propagate. How long that takes will depend on your DNS registrar, the TTL (Time To Live) that any existing records have and whether or not your local DNS provider honours TTLs. Best case scenario it will be instant, worst case it shouldn't take any more than 48 hours.

If you wish to test your new subdomain before DNS has propagated, you can test by adding an entry to your Desktop's hosts file (how that is done will depend on your OS).

E.g. here's the host entries I added to test this (my test server has an IP of

Strictly speaking it shouldn't be necessary, but I generally recommend adding any domains/subdomains to the server's (localhost) entry in it's hosts file. That way if/when the server resolves it's own domain/subdomain it will be much faster (it can skip an external DNS lookup). Here's the first line of my test server's hosts (/etc/hosts) file: localhost

Hopefully that get's you going. If you have any issues, please post back.

shootify's picture

i have set this up thanks to you.

however i ran on another issues, i have an web application running and seems to works fine, however when i am trying to set up smtp and sending an email test, it returns an error. 

should i just run : 

apt-get install php-pear
pear install MAIL Net_SMTP
pear list # verify Net_SMTP OK.

wanna make sure. thanks

Jeremy Davis's picture

You could certainly do that and I'm sure it will work.

However, personally, I'd be inclined to just install the Debian package php-net-smtp. I.e.:

apt install -y php-net-smtp

The result should essentially be the same, but in a Debian package.

The other alternative, is to just configure the whole server to use your SMTP relay. By default all TurnKey apps are pre-configured to send emails directly via postfix. But that can be pretty hit and miss (mostly miss these days). So we try to make it as easy as possible to configure postfix to use a 3rd party SMTP relay. Confconsole ships with a Mail Relay plugin that supports use of a third party SMTP relay. It should support any SMTP relay that supports SASL authentication.

If you are trying to configure this for your third party app (rather than the pre-configured TurnKey one), then there should (hopefully) be an option to use local postfix/sendmail? If you can't find it or aren't sure, please feel free to share the name of the app you're running and I'll have a poke around.

Obviously if you want to send mail via 2 different SMTP relays (for your 2 different web apps on your server) then using system settings won't support that. Although personally, I still think it's worth setting up the system wide SMTP forwarding anyway, so then you will get system emails.

shootify's picture

thanks so much. 

Add new comment