I want to set up a multi site as per installation directions. However, it seems like I need to set up symlinks to share the coding. I do not have shell access, and I am on a linux server.

So I have the parent in www.example.com. The install directions say to put the children in the sites/ directory. So my child site would be www.example.com/sites/child/. The modules to be shared would be in sites/all/modules/.

Do I need to set up a symlink php code in settings.php, or should I put it in a txt file under the child directory, or where? I believe the php coding would be <? symlink ( target, link ) ?>.

Any help with this would be greatly appreciated. I know there are others out there who could use this information, also.

If you help me, I will place your effigy on the Mantel of Greatness!

Comments

journaltimes’s picture

I need to set up sub-directories, as opposed to sub-domains, that is why I am setting it up this way. Any other suggestions or tips would be cool, also.

cog.rusty’s picture

I assume that you have Drupal installed in your web root directory, accessible with www.example.com.

Your "child" sites will not be under "/sites/child". The "/sites" directory contains only settings which are used by Drupal internally. Your child sites will be accessed simply as www.example.com/child.

To do this...

a) Drupal settings: Under /sites, create directories with names such as:
/sites/example.com.child1
/sites/example.com.child2
Each of these directories must contain a fresh copy of the settings.php file. Using your FTP program, make those settings.php files writable by everyone (666).

b) Symlinks: Create a text file containing this script:

symlink(".", "child1");
symlink(".", "child2");
print "Done";

where child1, child2 etc are the "subdirectories" of your secondary sites. (Not really subdirectories but they will behave like subdirectories).
Save this file and rename it to makesymlinks.php

c) To create the symlinks:
- Upload the script: Using FTP, upload this file to your web root (where Drupal is installed).
- Check to make sure that there are no real subdirectories with these same names under Drupal.
- Go one step back, just outside Drupal's directory, right click on it and change its permissions to 777 (temporarily) so that the script can create the symlinks in it.
- Run the script: Using your web browser, go to www.example.com/makesymlinks.php. The script will run and you will see a "Done" message (at this point the symlinks should have been created).
- Some cleanup: Using your FTP program change the permissions of Drupal's directory back to 755. Then go inside Drupal's directory and refresh the directory listing (usually F5). If you see the symlinks then you are done and you can delete the makesymlinks.php script.

Now, when you go to www.example.com/child1 Drupal's setup program will run for the "child1" site. After you finish the setup put the settings.php file back to 644.

journaltimes’s picture

I really appreciate it.

I need to pry the permissions open from my host, in order for me to set the symlinks up.

This solution is exactly what I need.

JohnG-1’s picture

I've been trying to follow these steps but adapt them to subdirectory installation ... and now I'm very confused :)

My drupal baseURL is http://example.com/drupal5 which points to home/username/public_html/drupal5/index.php in the filesystem.
The drupal5 folder has perms 777.
I have created a subdomain called subdomain.example.com
and a drupal5/sites/subdomain.example.com folder with settings.php in it. (perms 666)

OK question 1 : in which folder do I place the makesymlinks.php file?

  • home/username/public_html/drupal5/makesymlinks.php?
  • home/username/public_html/makesymlinks.php? (from here I seem to get permission denied)

question 2 : what paths do I put in the symlink ?

  • <?php symlink("home/username/public_html/drupal5/", "home/username/public_html/drupal5/sites/subdomain.example.com"); ?>?
  • <?php symlink("drupal5/", "drupal5/subdomain.example.com"); ?>?
  • <?php symlink(".", "subdomain"); ?>?
  • <?php symlink("home/username/public_html/drupal5/", "home/username/public_html/subdomain.example.com"); ?>?

I am really confused - if anyone can point me in the right direction I would be very grateful.

cog.rusty’s picture

First, the /sites/subdomain.example.com directory is only for internal use by Drupal. It is a settings directory, so don't concern yourself with that any more.

To answer your question,
http://example.com/drupal5 points to home/username/public_html/drupal5
http://subdomain.example.com points to where???

- If the subdomain points also to home/username/public_html/drupal5 then you don't need a symlink.
- If the subdomain points to a home/username/public_html/drupal5/subdomain directory, then you will see a "subdomain" directory there, and you will need to delete that "subdomain" directory and replace it with a symlink pointing back to drupal5.

In the latter case, if you upload makesymlinks.php to your drupal5 directory, your two last examples should work (with the correct directory name to which the subdomain points).

JohnG-1’s picture

Thank you CogRusty for such a patient and lucid explaination :) It turns out I was 'denied permission' (by hostserver) to add symlinks to the root directory - so I couldn't get anything to work! I ended up (on advice from hostserver support) using Putty to set up the symlinks via SSH. They were very nice and gave me idiot-proof instructions. I don't know if this will work for everyone's hostserver configuration, but I'll share in case it helps someone:

1. Set up the subdomains (subdomain1, subdomain2) using c-panel.

2. In file manager home/username/public_html (your Root directory) you now have these interesting folders:
public_html/drupal5
public_html/subdomain1
public_html/subdomain2

3. Point Putty (or equivalent) in SSH mode at your domain eg "example.com". - and log-in:
- Username = your c-panel username
- Password = your c-panel password

4. At the command line prompt, type each line then hit 'Enter':

cd ~/public_html
rm -Rf ./subdomain1
rm -Rf ./subdomain2
ln -s ./drupal5 ./subdomain1
ln -s ./drupal5 ./subdomain2
ls -la

note: " rm -Rf ./subdomain1 " deletes the folder which c-panel created ...
and : " ln -s ./drupal5 ./subdomain1 " creates the symlink in its place ...
and : " ls -la " gives you an overview of the folders and symlinks etc in the current folder (public_html)
so if you want to delete a symlink eg subdomain_error use " rm -Rf ./subdomain-error ".

It worked for me :) Hope it helps someone else.

mikelove’s picture

These instructions (cogrusty) worked for me with one small change - I kept the permissions for Drupal's directory at 755 - otherwise I couldn't run the php script.

colibri-1’s picture

Hi,
I set up a subdomain following these instructions. Everything went ok, as I was able to refer main site and subdomain to drupal install folder I did not need to set up symbolic links.
For the subdomain I set up a separate database. When I went for the first time to the subdomain I provided drupal with db connection info, then I could set up the first user. So far so good.

But: now that I go back to the subdomain I can not login anymore. I provide the username and password of the first user, click on login, and nothing happens , not even an error message, just a refresh of the first screen.
I adjusted base_url in settings.php file but this did not help.

Has anybody an idea what I'm doing wrong?

colibri-1’s picture

Somewhere else on this forum I found out it has to do something with cookies, a bug without proper solution yet. Manual removal of cookie seems the only solution so far...

divad’s picture

Hi, thanks for these excellent instructions. Everything worked precisely as you indicated.

Jeff Burnz’s picture

thanks cog.rusty, one of your legacy posts has saved my ass again, I get so confused with mulitsites, your symlink advice is just what I needed on my server with no root access, cheers.

tdzurilla’s picture

I don't have priviledges to create symlinks and I don't have a c-panel. Any ideas?

cog.rusty’s picture

What do you have? FTP? Domains? Subdomains? How do you point them to a disk directory? Or do you use just different url paths?

Perhaps you can ask your host to point all your domains or subdomains to the directory where Drupal is installed? (in which case you don't need symlinks)

If you can't create symlinks probably the webserver can, in which case you have to instruct it to do so with a script such as the one in my reply of Feb 10 above. (At least if it a Unix server.)

I can't be more specific without knowing what tools you can use and what you want to do.

tdzurilla’s picture

I can ftp to the site. I don't know how it is set up. The site is www.tierradentro.org.mx

Without the www. the browser goes to the server homepage. Any script I try on the server or the databases is denied access.

I have no idea. I'm trying to switch servers, because this is ridiculous.

cog.rusty’s picture

Hmm... Drupal is a script and it does run (and it does use your database).

If you mean that the scripts you tried can't create symlinks, this may be because the webserver has no write permission to your web root directory because it is owned by you. So, you could try to make the web root directory writable by all (777) for a minute (usually this can be done with FTP, e.g. right-clicking with Filezilla).

This is possible only if you are on a Unix server. If it is Windows, then symlinks do not exist.

You are right that the redirection without www is ridiculous. Perhaps your host has omitted an "A record" for your domain name in the DNS setup and they can fix it if you ask? If they give you no tools and they are not responsive then it may be a good idea to switch.

tdzurilla’s picture

Thanks for the heads up. In the ftp client, my root folder is greyed out. I've tried changing all the subfolders to writable for the moment and that's not working either. (Don't tell anyone)

If it's a windows server, is there anything I can do?

cog.rusty’s picture

For Windows there is a program called "junction" which does the same thing as symlinks.

http://www.microsoft.com/technet/sysinternals/FileAndDisk/Junction.mspx

So, if for example
- You have a site at http://www.example.com
- You want a second site at http://www.example.com/secondsite
- Drupal is installed in /home/user/public_html

Then, with shell access, you can use
- ln -s /home/user/public_html /home/user/public_html/secondsite (on Unix)
- junction /home/user/public_html/secondsite /home/user/public_html (on Windows)

Notice the different order of the arguments.

But there are problems
- You can't just install and run programs like junction.exe on the server. The host must have the program.
- I don't know whether php's symlink() function works with junctions. Probably not, so you can't use a script with junctions.

So, if you are on Windows the only viable option is not to use symlinks but have the host create subdomains for you and make all of them point to the same directory, Drupal's installation directory.

tdzurilla’s picture

I don't have any "public_html" folder in my home directory. Is there a way to create a folder, but then have the address www.example.com go to the folder without typing www.example.com/public_html

?

Thanks

cog.rusty’s picture

In my example, I called "public_html" your web root directory -- the one which you access by going to www.example.com.

tdzurilla’s picture

How can I change my web root? I don't have access to the permissions of the current web root and don't have an interface like cpanel to use. Is this something I need to take up with my hosting service?

Thanks,
Tim

tdzurilla’s picture

It's UNIX alright. Which means they're just giving me a hard time. I just need to send them the symnams to the host and wait a few weeks (this is Mexico after all). Thanks for your help and patience.