Easy webhosting on Opensuse…

I got this question from reader Ren:  “…I am looking for an article that assumes you have a web server running already on opensuse 11.3, and a friend asks you to host his web site for him as well and that he already has his own domain name registered.  I would like the step by step guide to add the virtual hosting to my Opensuse 11.3 server to do that for him…

Thanks for the question Ren; this one is a natural for me since I do it all the time!  There might be a million better ways to do it, but here’s how I do it:


First, you have to set up the DNS.  If your buddy has decided to service the domain names from the registrar or some other provider, just have him point the record for the site to your server.  Typically, for a simple buddy-type web hosting deal, I just have him set up an “A” record for the domain record itself, and a “CNAME” to point “www” to that “A” record.

If you are going to host the DNS records for your buddy, just do the same as above in your DNS server, but have your buddy point the DNS server pointer(s) to your server(s).


Since this is a Suse box, I have to mention this.  We’re about to do something custom, so make sure that you’ve either built a custom set of profiles for AppArmor, or that you’ve disabled it.  Guess which I prefer for testing.  Now guess what I prefer for production.  I’m not saying.


Now,you need to set up the apache2 listener.  Of course I have some custom stuff in my main apache config files, but your question was all about easy add-on hosting.

Note that the main apache config file httpd.conf has a statement to “Include” everything in the folder /etc/apache2/vhosts.d/ folder with a *.conf extension.  So, whether you have all your virtual hosts in a single file or you have a separate file for each one, you simply need to add some lines in the correct *.conf file, somewhat like this:

<VirtualHost hostname:80>
ServerName yourlinuxguy.com
ServerAlias *yourlinuxguy.com
DocumentRoot /srv/www/htdocs/yourlinuxguy.com
ServerAdmin yourlinuxguy@yourlinuxguy.com
ErrorLog /var/log/httpd/yourlinuxguy.com-error_log
CustomLog /var/log/httpd/yourlinuxguy.com-access_log combined

…where “hostname” matches a locally-resolvable host name ( meaning /etc/hosts); “Servername” reflects your instance that matches the DNS domain configuration; “Serveralias” allows any goofed-up host name that people enter to still work (especially if you put a DNS wildcard in place); “Documentroot” in my case as shown points to the standard Suse-style apache docs repository; and some other ancillary configs.  I should confess that I actually have a couple more lines in my instance directive for security, but I don’t want to reveal them here… sorry…

For content, just create a folder called:


…that has an index.html file that says something like “Hello World” in it or something.  Of course, you already have permissions set on the folder structure, so that’s not a concern here now.


Don’t forget to rotate the logs!  Note that from the apache config section above, you can see that I keep my logs in a separate folder.  I prefer this method over just using the built-in apache logrotate directives, because this way I have one main logrotate directive handling every log in the folder, and I can easily control the filenames with a wildcard (multiple sites on this host, remember).  Here’s an example of my homemade /etc/logrotate.d/httpd file:

/var/log/httpd/*log {
maxage 31
rotate 4
create 644 root root
/etc/init.d/apache2 reload

Now, all you have to do is to restart apache with the command rcapache2 restart.
And once you point your browser at it, you should see your happy “Hello World” message, and your buddy will be happy.


Leave a Comment

Your email address will not be published. Required fields are marked *