Multiple hosts layout

During these articles I will be talking about different operating systems, different web servers and different, er, stuff.

To make things easier to understand and reference between articles and systems, I will use a 'standard' layout for hosting multiple sites (virtual hosts). Let me explain the layout I use.


Differences

As you know, there are several differences between distributions and not just in libraries, package management and so on.

The default directory locations for serving domains also differs. Some default to /var/www/ and some to /srv/www/. Some organisations recommend /srv/domain.com/.

Consistency

The way I will use is not the only way, nor is it special or the 'Slicehost' way.

It is, however, one way of organising your domains in one place and will work across different operating systems and web servers.

I will also mention that if you are using a shared hosting environment on your Slice then do stick with the OS defaults. My method places the domain directories in my home directory.

I am the only user of my Slice and this is, as far as I am aware, the case with the vast majority of Slice users, so I do not have to be concerned about other users logging in and accessing my home directory (apart from the usual security measures that is).

Layout

My domains are laid in their own directories in my /home/demo/public_html folder (demo is my main user name).

In each domain, I have a standard set of folders including logs, cgi, private, public, backup and so on but feel free to add/delete directories as you see fit.

One advantage of this layout is consistency between technologies. A standard Ruby on Rails application will have many directories with the main content being served from the 'public' directory.

My layout coincides with this so my plain html and dynamic PHP content are also served from the domain.com/public directory.

I can't incorporate every technology into one layout but I think this covers most eventualities. Specific articles (such as using Capistrano) will note the differences.

Folders

Let's take a look at the folders in use throughout these articles:

Multiple Domain Layout

So in this example I have three domains - each in their own directory. I always class subdomains as separate from the 'main' domain. After all, they have different content.

Details

Let's look in detail at the domain1.com folder:

Domain Layout

The layout is quite simple once you get used to all the connections:

public: where publicly served files, images, etc are placed.

private: used for files you do not want in the public domain such as PHP mysql connection files.

cgi-bin: umm, the cgi-bin

logs: place domain logs here - it keeps them separate and easily accessible.

backup: I place daily database backups here - makes for easier slice backups.

Change

Naturally, add/delete folders as you see fit. However, this is the layout that will be used throughout the articles when it comes to domain configurations.

Also, do use the OS default if you feel more comfortable doing so. Simply adjust the paths used in the demonstrations.

PickledOnion.

Article Comments:

Andy commented Wed Jan 30 17:53:39 UTC 2008:

Hello. After reviewing this article and the DNS article, I still have a question. You put admin.domain1.com in it's own folder as a peer of the other top-level domain folders, since it has different content.

I don't completely understand what the A record admin would look like in the SliceManager. What would you put in the data field?

I'd like to (like others I'm sure) have subdomains: wiki, blog, articles etc.

Another way to answer this question might be to share how Slicehost itself is configured. Thanks! Great articles , concise and clear writing.

PickledOnion commented Wed Jan 30 18:08:46 UTC 2008:

Hi Andy,

Not sure how Slicehost is configured has anything to do with this.

When you create a subdomain you enter the name of the subdomain (such as 'www' or 'blog') and the IP address of your Slice.

That's it for the subdomain DNS record.

You would then configure a vhost in whichever webserver you used to point to the folder structure for that domain.

Hope that helps.

PickledOnion

Andy commented Wed Jan 30 19:51:43 UTC 2008:

I haven't set up a vhost before, but I was reading the Gutsy Apache configuration and it seems manageable. I don't think Slicehost uses any other TLDs so yeah, Slicehost config doesn't have much relevance for this article. Thanks for the quick response! BTW- I think it is great Slicehost doesn't put these articles behind a password-protected portion of the site.

Marvin commented Sun Feb 03 17:31:37 UTC 2008:

How does this file structure apply to rails apps ? When I start a new rails app with : rails railsapp, where in this file structure should I put the rails files ?

seth commented Tue Mar 18 22:17:34 UTC 2008:

marvin: you'd want to do one of 2 things, either rails projectname inside of the public folder that PO specified, OR you could simply do away with the public folder and just put create your rails app in the root of your domain folder.

Erik Adler commented Tue Sep 09 00:45:00 UTC 2008:

I really quite like this setup. Was wondering how I should setup the permissions for the folders.

Got any ideas for a safe vhost for SSL (phpmyadmin). I dont trust 99% of the junk I read on the net. You seem like the person to ask.

All the best Erik Adler

PickledOnion commented Tue Sep 09 01:13:16 UTC 2008:

Erik,

Have a look at this article: Slicehost Articles: Apache Virtual Hosts - permissions which should get you on the right track with general permissions.

I do plan on a PHPMyAdmin article as that seems to create a lot of questions.

No real timeframe for it at the moment, but there will be one coming.

PickledOnion

James commented Mon Oct 20 09:27:47 UTC 2008:

Another great article. You mention that this configuration is really setup for one user editing changes. Do you know of any good resource that talks about setting up a webserver that would allow multiple users access via sftp accounts? Where would you place the www directory, permissions etc.

Seanl commented Thu Feb 12 00:19:47 UTC 2009:

PickledOnion, As always a great article very insightful just one simple question, what software do you use to make the pictures of the folder layout?

PickledOnion commented Thu Feb 12 14:16:39 UTC 2009:

Heya,

I just used a simple image editing programme. To be honest, I don't actually remember which one but it was nothing 'special'.

Just used a blank canvas and added stuff :)

PickledOnion

joemar commented Fri Mar 20 04:46:36 UTC 2009:

im a bit confuse just want to ask that when evr you make a new file you have to execute a file permission same as the above setup so that it will work properly.am i correct?

Gavan Brown commented Mon May 11 17:19:31 UTC 2009:

I'm a complete noob, but i wrote a little bash function to build this layout, so that I can just type: mksite mynewsite.com

[1] sudo nano ~/.bashrc [2] insert the lines below at the end of the file, replacing "gavan" with your folder name. [3] source ~/.bashrc [4] usage: mksite mynewsite.com

function mksite (){ sudo mkdir /home/gavan/public_html/"$1" sudo mkdir /home/gavan/public_html/"$1"/backup sudo mkdir /home/gavan/public_html/"$1"/backup/sunday sudo mkdir /home/gavan/public_html/"$1"/backup/monday sudo mkdir /home/gavan/public_html/"$1"/backup/tuesday sudo mkdir /home/gavan/public_html/"$1"/backup/wednesday sudo mkdir /home/gavan/public_html/"$1"/backup/thursday sudo mkdir /home/gavan/public_html/"$1"/backup/friday sudo mkdir /home/gavan/public_html/"$1"/backup/saturday sudo mkdir /home/gavan/public_html/"$1"/cgi-bin sudo mkdir /home/gavan/public_html/"$1"/logs sudo mkdir /home/gavan/public_html/"$1"/private sudo mkdir /home/gavan/public_html/"$1"/public sudo mkdir /home/gavan/public_html/"$1"/public/images sudo mkdir /home/gavan/public_html/"$1"/public/videos }

Sam commented Mon Aug 10 08:40:42 UTC 2009:

Hi guys,

After following all this I did a quick mysql install, followed by a phpmyadmin install.

I can't access phpmyadmin via http://my.slice.ip/phpmyadmin - or via any of my other sites that i've setup as vhosts.

How would I access it, or alternatively setup access?

Want to comment?


(not made public)

(optional)

(use plain text or Markdown syntax)