I'm putting together a multi-site MAMP installation of Drupal 7.
I created a folder to hold Drupal, and put the Drupal files in there. Moving them out of the downloaded Drupal folder into my "websites" folder (including 2 invisible files)

With the MAMP application, I reset apache to look at this "websites" folder instead of the htdocs folder inside of the MAMP application folder.

In the "sites" folder (drupal files), I put 3 folders, each with the name of the 3 sites I want to build.

In Default folder I duplicated the default.settings.php file and named it settings.php, so both those files are in the same folder. (or was I supposed to put a copy of the settings.php inside each of my 3 site's folders. I don't know if I only need one settings file or 3.

In the ALL folder there is already a themes and modules folder. Once I also used a Libraries folder to hold CKeditor, do I still need to do that with Drupal 7?

Now, all I need to do is create 3 databases somehow with the exact same names as my 3 site's folders.
Am I right?

And I create the 3 databases by opening the start page in the MAMP application and going to the PHP Admin application there to create the3 databases.
Correct?
I'm using PHP 5.3.2, is that OK?

Is there any thing else I need to do before I open the index file inside the main folder that has all the Drupal files (which is named "websites" ) to start the application. Will just double clicking that index.php file kick everything off?

Thanks for any help.

Comments

jaypan’s picture

Subscribing.

Contact me to contract me for D7 -> D10/11 migrations.

Doren Berge’s picture

You seem to be on the right track. But you are missing several important steps. Specifically you need to edit your hosts file and your sites.php file.

For the benefit of others I will start at the beginning and carefully go through all of the steps that I took to run a Drupal Multi-Site local install with MAMP.

I have several client sites that I develop for. Running local versions of these sites can be messy if they are all running discrete instances of Drupal. Developing all of my sites from one installation makes it much easier to manage Core and module upgrades. It takes up less space and helps keep things tidy. Drupal 7 makes this process a bit easier to do with the "sites.php" file. I suggest reading the comments of this file at the appropriate step.

This is the procedure for running local Drupal 7 Multi-site on MAMP 1.9.x for OS X 10.5.x and up. This assumes you have Administrator access to your system. Were going to make MAMP become the default Web Server for localhost and also define localhost as "dev." We will set up 3 client sites running from one local Drupal Installation. I will name these sites "client1.dev, client2.dev, client3.dev" as examples. Replace these names with your own site names where appropriate.

Let's begin with MAMP.

  1. Download and Install MAMP in your Applications Directory.
  2. By default MAMP uses it's own "htdocs" directory as the root level of it's Web Server. We're going to adjust that in a moment. But "out of the box" this is the folder that MAMP expects you will serve your Web pages from.
    [Applications/MAMP/htdocs]
  3. If you have not done so yet, Download the most recent release of Drupal and extract it in the htdocs folder
    [Applications/MAMP/htdocs/Drupal-7]. At this time you might change the name of your Drupal 7 Folder. I named mine D7
  4. We want MAMP's Apache to use port 80 so that we will not have to append port numbers to our local URLS when browsing. In Mac System Prefs turn off Web Sharing. This will disable your "Sites" folder as a Web server and will allow MAMP's Apache to become your localhost server. There may be reasons not to do this [if you are running other site platforms in your sites directory for instance using Apache from OS X] If that's the case you can skip this step and the next step.
  5. Launch MAMP and open MAMP Preferences from the MAMP Control Panel. Then change the Apache port to port "80." Again, this step is optional.
  6. In MAMP preferences select Apache tab and set your document root to be your primary Drupal Instalation mentioned above. In my instance I created a clean Drupal 7 Install inside of MAMP's htdocs and named the directory "D7." [/Applications/MAMP/htdocs/D7]
  7. Restart your MAMP servers.
  8. Next we need to edit the hosts file. This is an "invisible file" and will require using Terminal. If you are not familiar, no worries. It's easy. Just step carefully. Open Terminal Utility [Applications > Utilities > Terminal] and enter the command:
    sudo nano /etc/hosts
    Enter your admin password at prompt. This will open the hosts file in the Nano Text Editor inside of Terminal.
  9. We want the default localhost address to recognize all of your Drupal Site addresses. We also want to recognize ".dev" as a localhost server.

    We're going to add each of your Drupal sites to the Host Database. Edit the file to read:

    # Host Database
    #
    # localhost is used to configure the loopback interface
    # when the system is booting.  Do not change this entry.
    ##
    127.0.0.1       localhost
    127.0.0.1       dev
    127.0.0.1       client1.dev
    127.0.0.1       client2.dev
    127.0.0.1       client3.dev
    255.255.255.255 broadcasthost
    ::1             localhost
    fe80::1%lo0     localhost
    
  10. Save and exit nano by typing control-x. y=yes at prompt. return
  11. If you are not familliar with Terminal or the Command Line, now would be a very good time to quit the Terminal Application.
  12. Now we are on to Drupal. In the Drupal Sites folder create a Directory for each of your Client sites.

    client1.dev
    client2.dev
    client3.dev

  13. Place a copy of "default.settings.php" in each client directory.
  14. In each directory copy "default.settings.php" and rename it to "settings.php." Do this in every client directory so that each directory contains "default.settings.php" and "settings.php"
  15. In the Drupal Sites fodler there is a file called "example.sites.php." Copy this file and rename it "sites.php" and keep it in the Sites folder along with "example.sites.php."
  16. Open the "sites.php" file and read the comments. This information may help you understand what Drupal is up to when it receives a URL request from localhost.
  17. At the bottom of the "sites.php" create the aliasing as follows and save.
      $sites['client1.dev'] = 'client1.dev'; 
      $sites['client2.dev'] = 'client2.dev';   
      $sites['client3.dev'] = 'client3.dev';      
    
  18. Were almost there. Now it's time to create Databases. Open The Start Page from the MAMP control panel, access phpMyAdmin page. MAMP sets both your MySQL admin name and password as "root" by default. Obviously this is not secure and you would be advised to change it. Whatever you choose, you will need your MySQL admin name and password for the drupal install of each site.
  19. To change your MySQL Password, or create other Users, Access the "Privileges" tab from phpMyAdmin. If you intend to change your ID and Password do this before you create Drupal Databases.
  20. From the phpMyAdmin primary screen [the localhost link at the top of the page] you can create a new database for each of your client sites. Just select a name and enter. You will need to remember this for the next step.
  21. If all is well you should be able to open a browser and enter the address "client1.dev" or "client2.dev" or "client3.dev" and you will see the installation screen for a new drupal site. [If you skipped steps 4 and 5 you will need to append port:8888 to each URL. ie: "client2.dev:8888"]. Enter the corresponding database names and your admin login and MySQL password. Run the install script for each site and you should be all set. You can now enter any of your client.dev URLS and you will be directed to the local site. You are now running discrete Drupal sites from one Drupal Core!

    Stating the obvious; When you add sites in the future you will need to edit your host file and your sites.php file. You will need new Sites folders as well.

I hope this was helpful.

Have fun!

Doren

espirates’s picture

I'm curious, what's the point of having sites.php, what is it suppose to do ? The other steps are similar to D6, I don't understand the need for sites.php.

Doren Berge’s picture

I believe it is so you no longer have to create Virtual Hosts in your Apache httpd.config.
Don't quote me on that, but I did not create Virtual Hosts in my local setup and it works fine.
I'm pretty sure that's the reason. If I'm wrong someone will correct me.

If true this would also make it a LOT easier to manage a multi-site on a hosted service.
I went through this a couple of years ago with a client. A multi-site service based on sub-domain.
I recall a lot of friction with the host provider over managing Virtual Hosts and the Apace Config.
This would have saved me a lot of headaches.

vvane’s picture

i don't know why... it dosen't work ..

dotman’s picture

I could really use some help here as well. If I set it up this way, will i only be able to create sites in drupal? And could you expand on your tutorial and include steps for moving those local sites to the live server for us that are new to this?

thanks.

Doren Berge’s picture

Hi Doug – don't be discouraged. I'm a designer, not a developer or IT guy. It's confusing at first. But If I can figure it out you can.

Short answer to your first question is "yes and no." It depends on the document root in your MAMP Preferences. [ MAMP > Preferences > Apache > Document Root ]. If you set the root to be your D7 directory, then all browser requests for "localhost" will serve only your Drupal sites.
Referring to my example above the URL "http://localhost" will only serve Drupal.

However, if you set the root directory to be "MAMP/htdocs" (in my setup it's "/Applications/MAMP/htdocs/"), then "localhost will allow you to serve all of your MAMP projects by pointng your browser to the proper directory. "http://localhost/D7/ or http://localhost/wordpress/.. or whatever." The Drupal multi-site will still work. You just need to append the Drupal Directory to the localhost URL when you enter it in your browser. So if you are managing a variety of CMS projects this is a better settup.

Regarding your other question (migrating local site to live server). It may seem confusing but it's fairly simple. Any complications will depend on your hosting provider. I can't help you with a difficult host. But most providers are accommodating if you have simple and specific requests. You can do this in a variety of ways. And there is a good deal of information on the Drupal.org site. You may need to dig a little.

Here's how I do it: Assuming your host meets the proper requirements (D7 requires MySQL 5.0.15 or Higher. PHP 5.3) it's pretty straight forward. Before you start, make sure that your Local Drupal core and all modules are up to date.

I like to do a clean Drupal install on the hosted server. Just FTP and unpack the TAR file in the directory of your choice (root or subdirectory). Create an empty database (usually via the host control panel or phpMyAdmin) Then run the installation script. The benefit of clean installation is that the script will return any errors or server conflicts. If the server config needs to be modified (usually "registered_globals" or something) it's easy to make a simple request of your host provider with specific information. Once your clean Drupal site is up and running then you migrate your themes and install all of the required modules via FTP.

The next step is to move your local content database... From your local MAMP launch your MAMP start page and open phpMyAdmin. Select the database for your Drupal site (left menu) and export (top tab) And save a copy of the database file to a local directory (Desktop for instance).

Then you need to access your Hosted database (usually via phpMyAdmin or via host control panel) and replace it with your local database file.
Start by opening the database in phpMyAdmin. (most host control panels provide a link that will launch phpMyAdmin in a browser window). Then "Drop" the whole thing. This will empty all data in the DB (your new, hosted drupal site will be dead. Temporarily). Then – via phpMyAdmin– "import" the database file (the one you saved locally) into your (empty) hosted Drupal database. This will include all of your content, module settings, etc.

Once you've imported your Database the hosted site should be running fine. Just be sure all of your media files are in the correct place. Any errors you might discover are usually related to file references (images, etc) or Directory permission settings. If these pop up it's usually easy to track down and fix. If you run into a snag, chances are someone else has had the same issue and you can find answers by searching the Drupal Forums.

I hope this is helpful. I know it can be confusing (maddening) if you are new to this. But once you've done it you realize how simple it is.

Good Luck!

-db

jaypan’s picture

Nice breakdown on migrating sites. I thought I'd let you know of a module that makes migrating sites easy as pie - the Backup and Migrate module. You first install the backup and migrate module, and take a backup of your database through the admin interface. Then copy the local filesystem to the remote filesystem. Delete settings.php, copy default.settings.php to settings.php, and install the remote Drupal installation as always. Then enable the Backup and Migrate module, and use it to import the database dump taken earlier.

It's ridiculously smooth. As an added bonus, you can set the module to take regular backups, and save them on the server or email them or whatever. There are a lot of different configuration options. It's a great module.

Contact me to contract me for D7 -> D10/11 migrations.

Doren Berge’s picture

vvane - I'm happy to help if I can. I've checked and re-tested the steps above. And it works fine for me. If you can provide any other information I will try my best to respond.

-db

yongdrel’s picture

Hi

I followed your instructions and everything worked.
Very detailed.

But as I start to configure the sites... I can not get Clear URLs to work.
It keeps failing the test.

Any hints as to how to fix??
I am running Drupal 7 Multi-site on MAMP 1.9.5 for OS X 10.6.8

Thanks

brandy.brown’s picture

perfect instructions, but one question: what if you want your two sites to share a database? I have it calling the correct database in settings.php, but I just keep getting empty table errors (and I think it's calling the wrong db) when trying to install.

Thanks.

jaypan’s picture

Contact me to contract me for D7 -> D10/11 migrations.

brandy.brown’s picture

Thanks.

brandy.brown’s picture

It's very important to note that in order for this process to work, you must copy the settings and sites files from a fresh drupal folder. I tried to just copy already configured settings file and it screwed everything up. Just wanted to reiterate.

ditcheva’s picture

Awesome breakdown of the steps for a MAMP setup. Very detailed and helpful. Thank you!!

jweedman’s picture

Doren Berge - you are a saint! Seriously - you are the reason Drupal (and open source projects) in general are the way of the future.

This is EXACTLY what I needed, and I would not have figured that out on my own. I know it took a good chunk of time to write this out step-by-step, so I really do appreciate your effort. It helped this guy more than you know!

- jweedman

danny englander’s picture

Thanks Doren, this is a brilliant tutorial, exactly what I needed. I have MAMP Pro so I was able to skip a few steps but it worked great.

gottaknow’s picture

I too have Mamp pro and have everything setup just like the post. However I can only get the localhost to work all the other sites get a 403 forbidden error. The error logs shows
[Thu Jan 15 19:32:16 2015] [error] [client 127.0.0.1] Directory index forbidden by Options directive: /Users/me/Sites/d7-localhost/sites/anothersite.dev/
Also confirms permissions problem. I have permissions set to 666 on sites and settings.php file but still I can't get passed this error.
Any suggestions, I am really stuck here and would like to hear from someone who has got mamp pro working for himself.
much appreciated.

surreal8’s picture

Great, easy to follow step by step - Thank you for taking the time to post this!

Technikal’s picture

worked for me like a charm, 2moro will try it on a rackspace ubuntu server