I want /sites/mysite directory to handle mysite.local, mysite.com and mysite.org

Events happening in the community are now at Drupal community events on www.drupal.org.
pendashteh's picture

hey.

the question is obvious:

I want all domains about mysite like mysite.local, mysite.com and mysite.org be handled via /sites/mysite/settings.php

drupal splits the subdomain.domain.com/path into com
i think it should be splitted into domain not com

I prefer suggestions for the path blogs.myname.com/friends be order like this:
- blogs.myname.com.friends
- blogs.myname.com
- myname.com
- blogs.myname
- blogs
- myname

if it could be possible then domain.com, domain.org and most important domain.local would be accessible via the /sites/domain directory.

anyone have idea or any hack to code to implement in this way?

Comments

I often say with regards to

Garrett Albright's picture

I often say with regards to multisite Drupal installations, "If your solution to a problem is to make a symbolic link, you're probably doing something wrong." But this is an exception.

First off, I suggest you name the site directory after the "normal" domain name for the site, whatever that may be. Let's say that's example.com. But you want to use the same site directory for example.org or example.local. So simply create symbolic links with those two names which link to the example.com directory. Piece of cake.

If you're not familiar with symbolic links, think of them as aliases in Mac OS parlance, or shortcuts for Windows - file system entities which simply point to some other file system entity. To create a symbolic link to example.com with the name example.org, type this at the command line:

ln -s /path/to/example.com /path/to/example.org

If you're using Windows, I think you can simply create a shortcut inside Windows Explorer to achieve the same effect. However, if you're on Mac OS X, creating an alias via the Finder will not work - you will have to open up the Terminal and do it that way.

Note that this can cause issues with attached files, and you need to be mindful of paths in content too (Pathologic may help in that regard). Namely, attached files are stored in the {files} table of the database using the path of the site in use as the file was uploaded. For example, if you upload a file while accessing the site at http://example.local, the file probably won't display correctly when you look at the site from http://example.com. A fairly simple SQL UPDATE/REPLACE command can fix this, but it can be a pain to do often.

Symbolic link wrong?

tomsherlock's picture

This is the first time I've heard the use of symbolic link as something to avoid for a multisite Drupal installation. As far as I know, with my webhost, symbolic link is the only way to successfully create a multisite installation.

What I usually do is place the command line code in a php file, place it in my public_html and run it once.
And then of course create a subfolder under sites.

I meant to add: why do you avoid use of a symbolic link?

Well, there's many ways that

Garrett Albright's picture

Well, there's many ways that symbolic links can be used unnecessarily or incorrectly when building a Drupal site. I won't even try listing them all, because I'm sure there's many that I haven't even imagined yet but which people are still doing. But one multisite-related goof which might possibly be the one you're committing is to have a separate web root directory for each domain name, but have each of those directories except for one actually be symbolic links to the one normal directory, into which Drupal is installed. Instead, it's much simpler and more manageable to simply use that one directory as the web root for all of your domain names.

OK, I give up. How do you

tomsherlock's picture

OK, I give up. How do you have a multisite without symbolic links?

I've just re-established my webserver environment on my Mac OS 10.5.8 with Drupal 6.16, PHP 5.2.9, Apache 2.2.14 MySQL 5.1.35. I am NOT using MAMP.

I've got two VirtualHosts set up. Their both pointing to the same DocumentRoot: '/Users/username/Sites/drupal'.
They have separate Servernames: mysite1.dev, mysite2.dev.
They have separate subdirectories for multisite: '/Users/username/Sites/drupal/site/mysite1.dev',''/Users/username/Sites/drupal/site/mysite2.dev''
And separate settings.php files. I can only get a single site up through the default settings.php.

I could set up multiple sites with multiple VirtualHosts and multiple DocumentRoots: 'Users/username/Sites/mysite1.dev', 'Users/username/Sites/mysite2.dev'. But then I would have separate copies of Drupal running.

I've been around the web a few times. All solutions point to MAMP.
Drupal.org has http://drupal.org/node/238805. But when I follow that recipe, I end up with a white page.

A big problem of symbolic links

pendashteh's picture

Hi,

the most major problem of using symbolic links arose when you want to move database from local to server. then all file paths and themes break. and you should do a boring process of clearing cache and re-enabling themes and probably some modules.
this problem also exists when using http://drupal.org/node/238805.

I, by myself have solved the problem like this:

if i have a myblog.com website then i do like this:

// what i have:
- Local:
Domain:             http://local.myblog.com
    DocumentRoot:       /path/to/drupal
    Sites Directory:    /sites/myblog.com

- Server:
   Domain:             http://myblog.com
  DocumentRoot:       /path/to/drupal
    Sites Directory:    /sites/myblog.com

so i can move files and database to server without any problem.

but what i really want is a way to have something like this:

// what i want:
- Local:
Domain:             http://myblog.local
    DocumentRoot:       /path/to/drupal
    Sites Directory:    /sites/myblog

- Server:
   Domain:             http://myblog.com, http://myblog.org
   DocumentRoot:       /path/to/drupal
    Sites Directory:    /sites/myblog

even if it is a function or hook or something that i could match domain name to settings directory programatically

Tom, it sounds like you're

Garrett Albright's picture

Tom, it sounds like you're heading in the right direction.

I assume you also modified your hosts file accordingly?

Are your subsite directories and settings.php files readable by the web server?

Right. I forgot to mention

tomsherlock's picture

Right. I forgot to mention the hosts file. Yes I modified the hosts file as such:
127.0.0.1 localhost
127.0.0.1 mysite0.dev
127.0.0.1 mysite1.dev
127.0.0.1 mysite2.dev

All subsite directories and settings.php files are readable by the web server.

Nevertheless the only url that works is http://localhost.
Also http://localhost/test.php and http://localhost/phpmyadmin work.

The urls give me a white screen and no logging information for mysite0.dev, etc.

So it sounds like apache is working (as is mysql and php). Seems to be a disconnect with Drupal.
Can't imagine what I'm missing.

Thanks for the encouragement, Garrett.

Did you modify Apache's

Sunshiney's picture

Did you modify Apache's httpd.conf file?

Yes. I've made several

tomsherlock's picture

Yes. I've made several changes, including:
ServerAdmin webmaster@mysite0.dev
ServerName mysite0.dev
DocumentRoot "/Users/username/Sites/drupal"
Added a section for my DocumentRoot with the following settings:
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Allow from all

However, I left the ServerRoot alone: "/usr"
And am listing at port 80.

I'm adding the virtual hosts through an Include: Include /private/etc/apache2/extra/httpd-vhosts.conf
I have an Include for User Home Directories: Include /private/etc/apache2/extra/httpd-userdir.conf
However, I've only set the UserDir to Sites.

I set DirectoryIndex to index.html index.php

php settings are in a separate file: Include /private/etc/apache2/extra/httpd-php5297.conf

Not sure if there is an optimum configuration for Drupal multisite.
Also, had to use .htaccess for clean URL's. Couldn't get it to work through serverside alone.

Did you turn on

Sunshiney's picture

Did you turn on virtual/name-based hosting in the httpd.conf file by uncommenting:

#
# Use name-based virtual hosting.
#
NameVirtualHost *:80

Server Root:

# ServerRoot: The top of the directory tree under which the server's
# configuration, error, and log files are kept.   (Note: If the filenames do not begin
# with "/", the value of ServerRoot is prepended -- so "logs/foo.log"
# with ServerRoot set to "C:/xxx" will be interpreted by the
# server as "C:/xxx/logs/foo.log".

My httpd.conf file server root is: "C:/apache2triad"

My file paths are:
C:/apache2triad
C:/apache2triad/htdocs
C:/apache2triad/htdocs/drupal
C:/apache2triad/htdocs/drupal/sites

Hope this helps.

Yup. Did that too.

tomsherlock's picture

Yup. Did that too.

Can you access a non-PHP file

Garrett Albright's picture

Can you access a non-PHP file via one of the domains - such as http://mysite1.dev/README.txt ?

No. Nothing. It is as if I

tomsherlock's picture

No. Nothing.

It is as if I have a setting in the httpd.conf file that is blocking access to the directory.

Success!

tomsherlock's picture

It turned out to be a setting in the httpd.conf file, and just one line: 'Order allow,deny' in the DocumentRoot's .
I now have multisite without symbolic links and without MAMP.

Thank you Garrett, aliasghar, nwwoman, redndahead and criznach for helping me to think this through.

Excellent!

Sunshiney's picture

I was just getting set to type that setting as the next thing to check and poof, saw your message. Super!! Bet you feel a great sense of relief that the problem has, finally, been resolved.

If you are using Drupal 6x and this is a localhost set-up, note that redndahead helped me with a 6x patch that makes files transfer betwn local and live site easy. After the patch, you do not need to go into the database and do path changes on such things as image files. Let us know if you need that. The patch is to core but D7 has it as part of core.

The local to live file

tomsherlock's picture

The local to live file transfer patch would definitely be useful. Although I'm not there yet. Is this patch in another thread? I wonder if aliasghar would find this useful?

Here's the url to the

Sunshiney's picture

Here's the url to the Drupal.org page I published re this patch: http://drupal.org/node/642712

Patch would help

pendashteh's picture

as @TomSherlock guessed the patch you told, would solve my common problem and then i would be able to use symbolic links easily.
i think the patch you share would help many ones.
thanks

so your sites folder looks

redndahead's picture

so your sites folder looks like

all
default
mysite1.dev
mysite2.dev

Does either mysite1.dev or mysite2.dev work? If you remove mysite1.dev and mysite2.dev folders do they pickup the default settings?

Check the watchdog on

criznach's picture

Check the watchdog on localhost for errors caused by the white screen on the other two domains. I had a problem just last night where I moved a site and APC was caching include files with incorrect paths. I didn't have error reporting on, so I got a white screen, but Drupal was still logging errors.

old thread but new solution

eporama's picture

In case anyone else finds this thread searching or otherwise, the original post was about serving up multiple sites from a single multisite directory and the troubles when the multiple sites don't match Drupal's expected discovery path.

The best solution was solved in core for D7 by using the sites.php file which was introduced in http://drupal.org/node/231298.

This lets you use sites/sites.php to directly specify which directories you want to use.

<?php
$sites
['mysite.local'] = 'mysite.com';
?>

which would allow http://mysite.local to use the settings and files in sites/mysite.com without affecting any sites already using that directory, plus unlike the symlinks, all information will be stored in the database as sites/mysite.com so that file paths and module paths will be where you want them to be.

There is also a valid patch for D6 in that issue and it is well excepted that it works, but D6 isn't accepting new "features" so it won't be included.

That's final solution

pendashteh's picture

Thanks for your well-explained answer.

Multisite

Group organizers

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds: