Multi-site Symlink Works But Causing Infinite URL Subpath and Recursive Server Folder

rCharles's picture

I've searched and searched and searched drupal.org multi-site documentation, forums, issues etc along with the web and can't find answer to my conundrum on subpath (URL path) site installs with symlinks. Sub-domains are not an issue.

While I can get subpath (URL path) site installs to work usng symlink with no .htaccess mods, the symlink creates both infinite URL subpaths and infinite server subfolders. This is driving me mad after hours and hours of trying to find something comprehensive on symlinks and specifically on about drupal multi-site. I'd like to do client betas and prototypes in a subpath but this has me stalled.

  1. Multi-site main site: No Issues
        http://site.com
    Cpanel Addon Domain set to server files folder
        /public_html/d6core
  2. Multi-site Sub-domain sites: No Issues
        http://this.site.com
    Cpanel Addon Domain set to server files folder
        /public_html/d6core
    And proper sites folder
        /public_html/d6core/sites/this.site.com
  3. Or, subdomain NOT as part of multi-site: No Issues
        http://that.site.com
    Cpanel Addon Domain set to server files folder
        /public_html/d6core-that

  4. Multi-site Sub-folder sites: Works but with concerns
    http://site.com/pathtest
    Cpanel settings not required, but did create proper sites folder
        /public_html/d6core/sites/site.com.pathtest
    then followed with SSH command via Putty to create a symlink:
        ln -s ~/public_html/d6core ~/public_html/d6core/pathtest

    Right away http://site.com/pathtest worked in the browser, install modules and all, with no need to alter .htaccess. At first, I was quite pleased, happy and thought how simple... but know here's my concern and confusion: Infinite URL path and server folders.

    • From the browser, the URL works as infinite subpath:
          http://site.com/pathtest/ 
          http://site.com/pathtest/pathtest
          http://site.com/pathtest/pathtest/pathtest
          etc, etc
    • From server file manager or Putty SSH "ls -1" folders are also infinite:
      www/d6core
         includes/
         misc/
         modules/
         pathtest@ (the symlink)
            includes/
            misc/
            modules/
            pathtest@ (the symlink)
                includes/ misc/ modules/ pathtest@ profiles/ scripts/ sites/ themes/
                    includes/ ...  pathtest@ ... themes/
                         includes/ ...  pathtest@ ... themes/
                             etc
                                etc
         ...
         profiles/
         scripts/
         sites/
         themes/
      

I've tried other iterations of above such as ln -s . pathtest from the public_html/d6core folder. Should I be using Alias command?

Thanks for any help. No doubts this would help many others too.

Comments

Folder on server

joyseeker's picture

Did you delete the folder after you created the subdomain?

The process is:

create a subdomain

delete the folder on the server

then run the symlink code

I have my multisites up without any tinkering with htaccess...

Again, not a subdomain - a URL path

rCharles's picture

Again, not a subdomain. Subdomains are not the issue.

When you create a symlink do you get infinite file folders and infinite URL path recursion?

Yes ,I have same problem in my website

shabanbi's picture

I have created symlinks for multisite subfolders
like ex :- "http://website.com/subfolder"
i have created symlinks "ln -s . subfolder"
then after i created folder website.com.subfolder in public_html/sites/ this path . My multisites working fine but it taken infinite url paths for every subfolder like

i)http://website.com/subfolder/subfolder/subfolder/subfolder1
ii)http://website.com/subfolder1/subfolder1/subfolder1/subfolder2
iii)http://website.com/subfolder2/subfolder2/subfolder2/subfolder3

Please advise me how to avoid this infinite url path recursion in drupal 7 ?

Regards,
shabanbi

.htaccess for multi-site subURLpaths (subfolders)

rCharles's picture

I've found Drupal's core/root apache .htaccess file needs additions to handle instances of subURLpath multisites.

For URL:
http://site.com/multisiteURLpath/multisiteURLpath/multisiteURLpath/etc

In Folder:: ../sites/site.com.multisiteURLpath

Try this after the #rewritebase (leave this commented) in settings.php:

RewriteCond %{REQUEST_URI} ^/multisiteURLpath/multisiteURLpath
RewriteRule ^/multisiteURLpath/index.php [L]

This does not resolve infinite folder recursion seen from FTP or Control Panel File Managers due to the symlink but I believe that is less an issue.

Multisite is easier than you

Mile23's picture

Multisite is easier than you think. The .htaccess is not wrong.

1) You set all domains and subdomains to use the same docroot: the main Drupal directory.

2) Then you arrange the folders with their domain names under /sites.

3) Then Drupal figures out which /sites subfolder to use based on the request.

So for example.com you'd put the site-specific stuff in /sites/default or /sites/example.com

For thingie.example.com you'd put the site-specific stuff in /sites/thingie.example.com

For thingie.example.com/some/path you'd put the site-specific stuff in /sites/thingie.example.com.some.path

Then Drupal figures out which to use based on the domain name and path present in the request.

If you're using symbolic links, you might be over-thinking it. :-)

See default.settings.php for some instruction.

Re: Multisite is easier than you

mstrelan's picture

If you're using symbolic links, you might be over-thinking it. :-)

Not if you want subdirectories as separate instances, rather than subdomains.

I have multiple domains with

dpatte's picture

I have multiple domains with unique domain names using multisite. It does NOT use symlinks.

No Symlinks Needed

Lakeside's picture

Didn't use symlinks to set up multisites on a virtual server. Heard about symlinks and thought maybe there was an advantage in using it, so tried it. Gave up on the idea because I couldn't get it working. Went back to the easy-peeze approach. There must be a reason for using symlinks, just don't know what it is.

@dpatte and @Lakeside

mstrelan's picture

Symlinks are needed for SUBDIRECTORIES as separate sites. For example www.example.com/site1 and www.example.com/site2 rather than site1.example.com. Although please correct me if I'm wrong.

If example.com is the root

Lakeside's picture

If example.com is the root site, the other domains are all in the site directory, i.e. simple.com, sample.com, whiz.com, etc.

Is that what you are talking about?

No, symlinks are NOT needed...

tsssystems's picture

for subdomains, subdirectories, or any site set up at all. Looked into symlinks myself in desperation, but then I realized they're not necessary for most applications. Probably the only time they might be is if there was some security implication, which I recall reading about in someone's blog. Didn't apply to me, so I'm not using them.

I agree with those who say you may be over-thinking it. It's easy enough to do, because most of the documentation has been written by those who know the process so well, that they either don't explain in detail or leave out some steps they don't really think about because it's so second-nature to them. I find this is true with most Linux / open-source documentation - period. Had me scratching my head for days the first time I tried to set up a multi-site as a local dev environment.

Drupal does perfectly fine NOT using symlinks. Just follow the comments in settings.php, which tell you that what you're trying to do is EXACTLY what settings.php was designed for, without needing symlinks.

I quote:

* For example, for a fictitious site installed at
* http://www.drupal.org/mysite/test/, the 'settings.php'
* is searched in the following directories:
*
* - sites/www.drupal.org.mysite.test

BINGO! Shows you that if you name your folders in the sites/ folder correctly, Drupal will find it.

If that's not a perfect example of not needing a symlink, I don't know what is. The ONLY thing I see is that you've (apparently) installed Drupal in a folder above the web root your server, NOT in the public_html directory. That's fine, I've done that too, but you need to make sure your DNS is pointing to THAT (d6core) directory.

http://site.com has to point to: public_html/d6core/, not just public_html/. That's all. If that's correct, you can make a site at any subfolder you want, symlinks not required. Your folder at:
/public_html/d6core/sites/site.com.pathtest
will be reached from the URL http://site.com/pathtest . Delete the symlinks.

tsssystems
18 separate sites on 3 code bases...

Debugging why it won't work without symlinks

mstrelan's picture

@tsssystems

I completely understand what you're saying, and I thought that it should work like you said, so I've done a few tests, perhaps you can help me make sense of them. Please note I've replaced the actual domain with "example.com" and actual subdirectory with "subdirectory". I used real values to perform these tests but did a simple find/replace on the output.

  1. Check that the symlink exists, and that there is an appropriate settings.php file.

    root@host2 [/home/mstrelan/public_html]# ls -l | grep subdirectory
    lrwxrwxrwx  1 mstrelan mstrelan     1 Feb 28 10:14 subdirectory -> ./

    root@host2 [/home/mstrelan/public_html]# ls -l sites/example.com.subdirectory/
    total 16
    drwxr-xr-x  3 mstrelan mstrelan 4096 Feb 15 10:27 ./
    drwxr-xr-x  9 mstrelan mstrelan 4096 Feb 28 10:26 ../
    drwxrwxr-x 10 mstrelan mstrelan 4096 Dec  4 15:57 files/
    -rw-r--r--  1 mstrelan mstrelan 1995 Feb 28 10:26 settings.php

  2. See if we get a HTTP/1.1 200 OK response.

    root@host2 [/home/mstrelan/public_html]# curl -I http://example.com/subdirectory/
    HTTP/1.1 200 OK
    Date: Thu, 28 Feb 2013 00:18:18 GMT
    Server: Apache/2.2.22 (Unix) mod_ssl/2.2.22 OpenSSL/1.0.0-fips mod_bwlimited/1.4
    X-Powered-By: PHP/5.2.17
    X-Drupal-Cache: HIT
    Etag: "1362010659-0"
    Content-Language: en
    X-Generator: Drupal 7 (http://drupal.org)
    Link: <http://example.com/subdirectory/>; rel="shortlink",<http://example.com/subdirectory/>; rel="canonical"
    Cache-Control: public, max-age=0
    Expires: Sun, 19 Nov 1978 05:00:00 GMT
    Vary: Cookie,Accept-Encoding
    Last-Modified: Thu, 28 Feb 2013 00:17:39 GMT
    Content-Type: text/html; charset=utf-8

  3. Remove the symlink and try again.

    root@host2 [/home/mstrelan/public_html]# rm subdirectory
    rm: remove symbolic link `subdirectory'? y

    root@host2 [/home/mstrelan/public_html]# curl -I http://example.com/subdirectory/
    HTTP/1.1 301 Moved Permanently
    Date: Thu, 28 Feb 2013 00:18:40 GMT
    Server: Apache/2.2.22 (Unix) mod_ssl/2.2.22 OpenSSL/1.0.0-fips mod_bwlimited/1.4
    X-Powered-By: PHP/5.2.17
    X-Drupal-Cache: MISS
    Expires: Sun, 19 Nov 1978 05:00:00 GMT
    Cache-Control: no-cache, must-revalidate, post-check=0, pre-check=0
    ETag: "1362010720"
    Last-Modified: Thu, 28 Feb 2013 00:18:40 GMT
    Location: http://example.com/subdirectory
    Content-Type: text/html

  4. Hmm, it's redirecting to the same URL but with the slash removed. Probably due to globalredirect "deslash" option. Check the response of the URL without the slash.

    root@host2 [/home/mstrelan/public_html]# curl -I http://example.com/subdirectory
    HTTP/1.1 404 Not Found
    Date: Thu, 28 Feb 2013 00:18:58 GMT
    Server: Apache/2.2.22 (Unix) mod_ssl/2.2.22 OpenSSL/1.0.0-fips mod_bwlimited/1.4
    X-Powered-By: PHP/5.2.17
    X-Drupal-Cache: MISS
    Etag: "1362010738-0"
    Content-Language: en
    Cache-Control: public, max-age=0
    Expires: Sun, 19 Nov 1978 05:00:00 GMT
    Vary: Cookie,Accept-Encoding
    Last-Modified: Thu, 28 Feb 2013 00:18:58 GMT
    Content-Type: text/html; charset=utf-8

HTTP/1.1 404 Not Found :(

I then disabled globalredirect and tested again, but got another 404.

tsssystems's picture

but two things struck me about this.

1) Did you clear your cache between tests? If not, it's no surprise that you got a 404 error.

2) Where is the actual DNS for "example.com" pointing to? Now it looks like you've installed drupal in the public_html directory, and that that's where you had the symlink. I know you like to keep the real url hidden, but without knowing the real directory structure on the web server and where your DNS is really pointing to it's impossible to troubleshoot. In your earlier post it appeared that you had installed Drupal one level up from your web root; here it looks like Drupal is installed at the web root. DNS won't point to both directories...

If you're not familiar with drush, you should check it out. You can do many things with it, including clear your caches from the command line. Very handy.

Not sure what gave you the

mstrelan's picture

Not sure what gave you the impression that I had Drupal installed outside of the web root. I am very familiar with drush. The reason I'm testing with cURL is because it's an easy way to paste the headers on g.d.o. I could've opened it in my browser and uploaded screenshots, but cURL seemed easier.

To make it easier to demonstrate I've replicated the situation on an fresh installation of Drupal which you can see at http://michaelstrelan.com.au. I tried to set up a multisite installation of it at http://michaelstrelan.com.au/example which you can see raises a 404 not found error.

This is how I've got my sites directory set up.

root@host3 [/home/mstrelan/public_html]# ls -l sites
total 28
drwxr-xr-x  5 mstrelan mstrelan 4096 Feb 28 14:47 ./
drwxr-xr-x 10 mstrelan mstrelan 4096 Feb 28 14:43 ../
drwxr-xr-x  4 mstrelan mstrelan 4096 Feb 28 14:37 all/
drwxr-xr-x  3 mstrelan mstrelan 4096 Feb 28 14:41 default/
-rw-r--r--  1 mstrelan mstrelan 2365 Feb 28 14:37 example.sites.php
drwxr-xr-x  2 mstrelan mstrelan 4096 Feb 28 14:47 michaelstrelan.com.au.example/
-rw-r--r--  1 mstrelan mstrelan  904 Feb 28 14:37 README.txt
root@host3 [/home/mstrelan/public_html]#

I have cleared the cache of both michaelstrelan.com.au and michaelstrelan.com.au.example

root@host3 [/home/mstrelan/public_html]# drush --uri=default cc all
'all' cache was cleared in /home/mstrelan/public_html#default              [success]
root@host3 [/home/mstrelan/public_html]# drush --uri=michaelstrelan.com.au.example cc all
'all' cache was cleared in                                                 [success]
/home/mstrelan/public_html#michaelstrelan.com.au.example

Multisite in three easy

Mile23's picture

Multisite in three easy steps:

0) Understand why you want a multisite setup. The reason you want a multisite setup is so you can have one codebase with a number of different configurations, selected by domain and path. You could also have many Drupal installation, one per domain, and not have to figure out how multisite works. :-)

1) Your http server's docroot for all multisite sites is the Drupal root. Drupal will look at the request to figure out which site to use. Make a default site that works for one domain name and then leave the server's docroot configuration alone.

2) Make /sites subfolders for any sites hosted by your Drupal code. The absolute minimum is a settings.php file in a subfolder named something like /sites/example.com/.

3) There is no fourth step.

Why not just use site.php

rwilson0429's picture

The simplest method is to use Drupal 7's site.php to implement multi-sites using the same code base. The sites.php is stored in the sites directory, if you have installed Drupal 7 you should see a file called example.sites.php. Rename example.sites.php to sites.php, then uncomment and change the $sites array as needed.

/**
* Multi-site directory aliasing:
*
* Edit the lines below to define directory aliases. Remove the leading hash
* signs to enable.
*/
$sites['example1.com'] = 'example1.com';
$sites['example1.localhost'] = 'example1.com';

Multi-site install

tsssystems's picture

1) www/d6core in your earlier post is above the web root.
2) @rwilson0429 is right; in your latest example you haven't set up sites.php. "example.sites.php" will get you no where. Is settings.php also set up correctly? Are you sharing any tables between the multi-sites? Have you followed all the instructions there regarding the database setup? Perhaps you need to uncomment the base install directory line in settings.php. Is the cookie domain set correctly?
3) Did you actually run install.php for each sub-site you want to set up? Drupal needs to build the database and set up a few paths before the site will work. If you didn't run install.php from your subdirectory then you won't have a site set up in that subdirectory.

www/d6core wasn't me

mstrelan's picture

1) www/d6core wasn't me, that was the original post, I seem to have hijacked the thread.

2) I have tried with and without sites.php. The settings.php files are default after an installation. Have not modified cookie domain or base url.

3) No, I had just cloned the database and settings.php. But now I've cleared out the database and copied default.settings.php so I could run install.php, but it doesn't get that far because /example is still 404 page not found.

Perhaps could someone set up a working example that we can all see of how it's meant to work without symlinks, I'm curious if my server is the issue.

Another approach to installing Drupal 7 multisites

Lakeside's picture

This article demonstrates one way to install a multisite. The approach works on most virtual host servers.

http://improveyourblog.com/installing-drupal-7-as-a-multisite-esp-greeng...

SUBDIRECTORIES work without SYMLINKS

Lakeside's picture

Why is it that Symlinks are not being used and the domains are all seen as separate sites?

Please demonstrate working example

mstrelan's picture

If you have subdirectories working as a separate website, sharing the same codebase, without symlinks, please show us a working example.

A NON-SYM LINK Site

Lakeside's picture

You're skeptical that you don't need to use sym links to get a Drupal mulitisite to work?

I'm happy to prove it, but how are you going to detect that it really is a domain sitting in the site folder of Drupal installed in the root folder?

There is a procedure that you do need to follow to install the subdomain; otherwise you do need to use sym links for it to work. Here are the basic steps that work on Apache virtual host servers (the site was recently moved from a Drupal multisite to WordPress):

http://improveyourblog.com/installing-drupal-7-as-a-multisite-esp-greeng...

i posted below how my

Karll's picture

i posted below how my multisite is running, I am running 14 sub sites this way with no symlinks -

No symlinks used:
Each site has its own unique database:
Drupal is the root directory in apache:

Website sub directories under /var/www/drupal/sites/

sites/default - not writable
sites/www.a.com
sites/www.b.com
sites/www.c.com
sites/www.d.com

DNS:examples
222.222.222.222 www.a.com
222.222.222.222 www.b.com
222.222.222.222 www.c.com
222.222.222.222 www.d.com

For each new multisite I create - I copy the default directory and rename it to the URL -
"sudo cp -R defaultsetup -new folder name-"
then make writable to the webservice name
"sudo chown -R www-data.www-data /var/www/drupal/sites/-NEW-SITE-FOLDER-"

I am exiting this

mstrelan's picture

I am exiting this conversation. No one seems to be paying attention to the fact that I am not referring to sub.domai.ns, I am referring to sub.direct/ories/

Right. default.settings.php

Mile23's picture

Right. default.settings.php tells you how to do that. Something like:

/sites/example.com.trailing.path/settings.php

It works the same way as the domain names. Drupal will find it. No symlinks needed.

From default.settings.php:

* For example, for a fictitious site installed at
* http://www.drupal.org/mysite/test/, the 'settings.php'
* is searched in the following directories:
*
* - sites/www.drupal.org.mysite.test
* - sites/drupal.org.mysite.test
* - sites/org.mysite.test
*
* - sites/www.drupal.org.mysite
* - sites/drupal.org.mysite
* - sites/org.mysite
*
* - sites/www.drupal.org
* - sites/drupal.org
* - sites/org
*
* - sites/default

@ mstrelan Above you asked

Karll's picture

@ mstrelan

Above you asked for a working example of using a single codebase using subdirectories working as separate websites - (a couple were provided) and several posts throughout this thread have indicated that you do not need to use symlinks for a multisite setup. (The original post was about infinite folder path recursion). I Think the common census here is that symlink is not needed and being over thought and theres not a straight clear answer in the documentation. Both subdomains as a separate website as well as unique website domain urls both function the same way if you want to use a multisite. It all depends on your level of access to DNS and the webserver.

in the Drupal installation under /sites/ folder you copy and rename the sites"default" to a new folder named what your URL will be.

all are folders:
/sites/www.mysite.com
/sites/www.thissite.net
/sites/www.yoursite.org

or if you have only one domain but need multiple sites:

/sites/bella.example.com
/sites/james.example.com
/sites/bob.example.com

DNS:
They all work the same. then in DNS you point all urls "domains" at the same ip address. For subdomains would be the same thing "all point to the same IP address.

Drupal handles the rest.!

Symlinks:
I am no expert on symlinks -
I personally have never used them. I have always understood symlinks to be used as that you have one domain name pointed at a Drupal site but have registered all the ".com .org .net"
but when you visit "www.mysite.com" your Drupal site works. If you want to visit www.mysite.net or .org Drupal does not know where they are because the folder does not match. It was my understanding that you create symlinks to point www.mysite.org and www.mysite.net at the folder www.mysite.com.

when drupal in the webroot

Karll's picture

when drupal in the webroot receives a request at the IP - it takes the url used and looks for a matching sites folder - when one is not found it rediects to 404

no symlinks multisite

Karll's picture

No symlinks used:
Each site has its own unique database:
Drupal is the root directory in apache:

Website sub directories under /var/www/drupal/sites/

subdirectories
sites/default - not writable
sites/www.a.com
sites/www.b.com
sites/www.c.com
sites/www.d.com

DNS:examples
222.222.222.222 www.a.com
222.222.222.222 www.b.com
222.222.222.222 www.c.com
222.222.222.222 www.d.com

For each new multisite I create - I copy the default directory and rename it to the URL -
"sudo cp -R defaultsetup -new folder name-"
then make writable to the webservice name
"sudo chown -R www-data.www-data /var/www/drupal/sites/-NEW-SITE-FOLDER-"

Multisite

Group organizers

Group notifications

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

Hot content this week