Hi-
I am having a hard time how to best go about some drupal local installations.
I am currently working on 2 sites that are already live -- one is 6.6 and the other is 5.x.
I am on a Mac.
Additionally, I would like to be able to start developing some new 6.x sites.
So my questions are:
1. How do I go about multiple local installations on a mac?
Do this ('Create a local mamp environment') http://drupal.org/node/66187) and this ('multiple installations') http://drupal.org/node/238805) work together? Do I have to tweak any of the instructions
2. What if I want one to be for 5.x and the others for 6.x? Are there differences?
3. How do I install a live site locally? Installing a fresh system seems straightforward, but I keep hitting snags when it comes to importing the structures, databases, of live sites.
I found this: http://drupal.org/node/232460 (copying a site to a local...) -- But do I have to tweak anything if there are other installations?
4. How can I create additional (fresh) installations on the fly?
5. What are the best practices for running a local dev site for a live site? Do I just install test modules and themes locally, and then when I feel confident that they work, install them on the live site? Is there a more "magical" way of doing this?
Many, many thanks!
Comments
Multi-site setup suggestions
Hi,
The short answer is that the pages you linked to above give a pretty good guide to what you need. If you're on Mac, you can use the built-in apache and PHP of OSX, but a MAMP install is a lot easier, not to mention portable - once you have your sites installed you can move the whole MAMP folder to another Mac to work on them. So, to answer your questions in order:
1. Those installation guides will get you started. One thing to check is that you are using the same versions of apache, php and mysql on your remote sites and your MAMP installation - if you have near identical installations, your life will be much easier.
2. Anything within /Applications/MAMP/htdocs/ can be served up with apache/php. So, you can create two (or more) Drupal installs:
Then, you can edit the virtual host config for each of your sites and point them to the appropriate Drupal install.
Drupal will then look in the drupalx/sites/ folder for a folder than matches the site name, which leads on to point...
3. The database connections for your local dev site and your production site will probaby be different, so you need two settings.php files. The way I do it is to set up two Drupal sites, one for local, one for remote, but share the themes and modules with symbolic links:
That way, I make theme changes under the .com site folder, check them using the .local domain, but only worry about synchronizing the .com folder to the production server.
You'll still need to transfer your data between the local/remote databases, so you'll be doing the usual export/import sql dance - either using phpMyAdmin, or via a command line import. The main problem you'll run into is that by default, phpMyAdmin seems to limit the size of imports to 2Mb, which is a pain after your drupal site's been running for more than a couple of minutes! As long as your drupal folder structure is the same between your local and remote sites, this should be fairly painless.
4. You can add extra sites by creating a new folder in drupalx/sites/ (well, 2, one for remote, one for local), adding the new domain to your hosts file, and configuring a new vhost in your apache conf (You'll need to restart Apache for the changes to be taken into account). Add a new database, update the settings file, and you should be up and running. If you want to setup a whole new installation of Drupal (v7 if you're feeling brave!), you can create a new folder within /Applications/MAMP/htdocs/ and modify your vhost settings to point there.
5. Not sure if there is a magic way of synching remote & local - I wish there was! There are some modules which are designed to manage Drupal multi-sites and site migration, but the way you suggest - test locally, upload/import to remote - works for me. I also have the Drupal folder under version control, and database backups, so if anything goes wrong I can roll back to the previous version.
Hope that helps...
Thanks, matkeane -- that was
Thanks, matkeane -- that was a wonderfully thoughtful, prompt, and thorough reply.
I'm going to need to really digest the information - I want to get the setup right so I dont run into problems down the road.
I'm not totally clear on the setting up 2 sites - remote and local - on my computer per site, but I think if I re-read your post a few more times it will sink it. I also have to investigate this concept of 'symbolic links': are these aliases? how are they mapped?
To review, my local folder hierarchy would look something like this, yes?:
/Applications/MAMP/htdocs/drupal5/sites/drupal5site1/local
/Applications/MAMP/htdocs/drupal5/sites/drupal5site1/remote
/Applications/MAMP/htdocs/drupal6/sites/drupal6site1/local
/Applications/MAMP/htdocs/drupal6/sites/drupal6site1/remote
/Applications/MAMP/htdocs/drupal6/sites/drupal6site2/local
/Applications/MAMP/htdocs/drupal6/sites/drupal6site2/remote
or perhaps
/Applications/MAMP/htdocs/drupal6/sites/drupal6site1.local/
/Applications/MAMP/htdocs/drupal6/sites/drupal6site1.remote/
Thanks again!
Folder structure
Hi,
I've just spent the last couple of days moving a dozen sites to a new production server, so it's all fresh in my mind!
I think the drupal6site1.local/ & drupal6site1.remote/ setup might work, according to what the comments in the settings.php file say, but I use the actual domain names as site folders:
/Applications/MAMP/htdocs/drupal5/sites/example.com/ <- the remote/prod site with themes modules, etc
/Applications/MAMP/htdocs/drupal5/sites/example.local/ <- the local test site, with modified settings.php
That way, once the local folder is setup, you can basically forget it and work in the .com folder, but on your local machine.
And, yes, symbolic links are like aliases for unix, except that instead of jumping to the destination, as with a Mac finder alias, the system sees the linked folder as if it were where the link is. That sentence probably didn't make much sense! Anyway, symbolic links are special in that they fool the system into seeing files in the correct structure, even if they are actually located elsewhere, so Drupal will see a theme folder in sites/example.local/themes/ even though it really exists at sites/example.com/themes/
For example, on my production server, I've linked subfolders of /files/example into /sites/example.com/files/ so Drupal thinks files are in the normal place, but I can keep all files, themes & modules together in the site-specific folder. Not immediately obvious in the above example, this also makes file paths shorter, so you can store them at files/mvldn/ instead of /sites/my-very-long-domain-name.com/files/ and also means you don't have the domain hard-coded in the filepath, should you ever shift the site to a new domain. But I'm heading off at a tangent now...
Hey Matkeane - hoping you're
Hey Matkeane - hoping you're still following -
I've been playing with this installation for the better part of the past day and and a half. Your instructions didn't immediately map to the handbook instructions for multiple installations, so there was a lot of trial and error. I have one of the sites working readily (almost, see below), but the other isn't responding.
What I found to work was installing:
Applications/MAMP/htdocs/Example/sites/example.com
Applications/MAMP/htdocs/Example/sites/example.local
Applications/MAMP/htdocs/Sample/sites/example.com
Applications/MAMP/htdocs/Sample/sites/example.local
note: I renamed the stock "Drupal-6.6" folder to either Example or Sample. The 'sites' folder within that is the stock 'sites' folder that resides in a standard drupal installation.
Although both sites are running Drupal6, I couldn't use a common installation, because it insisted on using the same database, email and share other features.
So I installed drupal into htdocs twice - once named as Site1 ('Example') and once as Site2 ('Sample').
Within [Applications/MAMP/htdocs/Sample/sites/example.com], I stuck a 'themes' and modules' folder - as I did for all four folders listed above, using the symbolic links as you suggested.
I tried then downloading a new theme into:
Applications/MAMP/htdocs/Sample/sites/example.com/themes, but when I navigate to:
http://localhost:8888/Sample/?q=admin/build/themes/ -- that Theme is nowhere to be found!
It's only when I download the theme into /sites/all/themes that I find the newly installed theme.
I suppose this makes some sort of sense - how is Safari supposed to know which of the sites to go in the URL I used?
I'm hoping I got all the virtual hosts stuff configured correctly -- it took me several attempts because I was juggling conflicting instructions... But I'm not sure why the other site I parked parallel to the first one isn't appearing (I don't get an error when I navigate there - just the MAMP favicon, and a blank, white screen).
Not sure if there is enough information here for anyone to advise, but at least writing it out gave me some perspective and clarity on the situation. Thanks!
Still here!
Hi,
I'm a bit pushed for time at the moment, so I can't promise to answer all your questions, but here goes:
First off, I think the missing theme is linked to another problem. If you're navigating to your site at http://localhost:8888/Sample/, then Drupal will look for a site in the /sites/ folder with a name that corresponds to the URL - localhost:8888. However, if your site folders are called Sample/sites/example.com, there's no match, so it will end up using the settings from the default site instead. That's where the hosts & virtual host setup comes into play.
(To complicate matters slightly, I'm not using MAMP on this machine, but on another test machine I configured the MAMP preferences to use the default apache/mysql ports, so I don't need to add the 8888 port number.)
So, in your hosts file, you should add a line for your new site so that your OS knows to look it up locally, e.g.:
127.0.0.1 example.localNow, any requests for example.local will be transferred to your local apache server. In the httpd.conf file, add a new virtual host:
Restart apache and, when you browse to example.local, it should start serving up example.local from your Drupal install. If you add a new site folder, host entry and vhost, the same should work for example2.local. The URL is how Drupal decide in which site folder to look for the settings.php and any site-specific themes. The separate settings.php files are what allows different database settings for each site. If you've already added your database information to the settings.php file, you should see your Drupal site, otherwise you should get a message from Drupal complaining that it can't find your database.
So now, with the folder structure:
You should be able to serve 2 sites from one Drupal install - as long as you have the corresponding entries in your hosts file and vhost config. Does that make sense? I may have over-complicated things a bit with the remote/local mirroring, but it saves a lot of hassle later!
Let me know how you get on...
I've been trying to work out
I've been trying to work out as much as possible before returning to you with questions (pleads). I think I finally understand the logic of the virtual hosts, the mirrored installations, the default directory, etc., but there are niggling issues.
1. When I installed drupal (each time) I was asked to provide a name for the site, an email address from which notices would be sent (advised to use the same domain as the site), and so forth. Is this information stored in the database? It would have to be, right? -- otherwise both sites would have the same information
Also, to install Drupal I need to supply some database information for the sites/default folder. Do you suggest that the database there is just a dummy one? Or is that what you mean when you say that Drupal will complain it can't find my database.
Which leads to 2...
2. I still can't get my sites to look past the default folder. Which certainly explains why the themes don't show up, and perhaps also why the installation wants its own database.
I just tried installing both sites as a single drupal installation, but I'm not sure I understand the advantage to that, so I will undo that for now - because it seemed to be close to working until then. (And since my 2 projects are so different - one is personal and one is business - I don't mind the strict distinction).
Here are my files as they currently look. I've tried what seems like every conceivable permutation to get them to work the way you describe. Perhaps you can show me what I'm missing:
[Pizza and Firetruck are meant to be for eventual sites pizza.com and firetruck.com, for this example]
hosts (at etc/ at the root of the computer)
##
# 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 firetruck
127.0.0.1 pizza
127.0.0.1 firetruck.local
127.0.0.1 pizza.local
255.255.255.255 broadcasthost
::1 localhost
~~~~~~
httpd.conf (at Applications/MAMP/conf/apache)
[this is just the end]
NameVirtualHost *
DocumentRoot "/Applications/MAMP/htdocs"
ServerName localhost
DocumentRoot "/Applications/MAMP/htdocs/firetruck"
ServerName firetruck.local
DocumentRoot "Applications/MAMP/htdocs/pizza"
ServerName pizza.local
My folder structure is: Applications/MAMP/htdocs/pizza/sites/ all, default, pizza.com, pizza.local and
My other folder structure is: Applications/MAMP/htdocs/firetruck/sites/ all, default, firetruck.com, firetruck.local
Databases are stored within 'default' and the '.com' and '.local's
the .com sites have themes and modules folders, with symbolic links to them from their respective .local folders
I finally see the gracefulness of having a .local and .com site for syncing and URL purposes, but am not sure I understand the advantage of a common drupal installation. Is there a significant one?
Also, if I forget about the .local and .com setup (since the neither of the 2 sites i'm working on are actually live right now), how hard will it be to eventually deploy the sites to the internet? Am I really setting myself up for a headache?
To complicate things, I realize I've been working as two separate logged in users, and I think that has confused the permissions issue. Suddenly, logged in as the second user, MAMP no longer can start the mysql database. It can in the first user. Hmm.
Once again, sorry to make you spell things out - but I do think I am starting to see the light...
Multi-sites continued
Hi,
You might be right that logging in as different users is causing problems - I couldn't get MAMP to run unless I logged in as an admin user. So probably best to stick to the same user.
1. The information about your database connection that you enter during installation is stored in the settings.php file - Drupal needs to get that info from a text file before it can make the connection to the database. Other stuff, like the site email address, goes into the database. If you browsed to firetruck.local/install.php, then you should find that data in /sites/firetruck.local/settings.php - something like:
And in /sites/pizza.local/settings.php, you should see something similar, but pointing to a separate database (unless you want to share stuff between sites, but let's start things off simple!)
Personally I don't bother doing anything for sites/default - You should only ever get there if a domain is pointing to your Drupal install folder but no site folder exists for that domain. So I prefer to see an error, so I know I've messed something up, rather than a default site.
2. The main advantage to a single Drupal installation is reduced maintenance. It's not unusual to see 2 or 3 module updates each week on a large site, and Drupal core updates every few months - If you have to install them, and test them, on as many copies of Drupal as you have sites, you're going to get very bored very quickly! With one shared installation, you only have to make the changes once. Having said that, I currently have 3 drupal installs - D5 for clients, D5 for personal sites (to keep things separate) and a D6 test install - each with several sites.
Anyway, if you can browse to both sites - firetruck.local & pizza.local, then your hosts file and vhosts are OK. If you can log into 2 different Drupal sites, then your database settings are OK. If the only problem is the missing themes folders, then I'd suggest deleting the symbolic links for the moment, and testing a theme directly in the /sites/firetruck.local/themes/ folder. Maybe download a completely different theme and try it out in that folder - you should see it when you go to firetruck.local/admin/build/themes but not if you browse to pizza.local/admin/build/themes
The main advantage of the symbolic links is that, when you go live, you can just FTP the /sites/firetruck.com folder onto the remote server. If you develop your theme in the local site folder, you can't do a direct folder sync so easily (depending on your FTP software). But you can always move the themes folder later and then symlink it - it's an added complication that you can deal with later!
Don't worry about the questions - I think multi-site installs are one of the trickiest parts of setting up Drupal and, judging by the number of forum posts I see on the subject, I'm not alone! Anyway, it sounds like you're getting close...
So close, so far
So am I supposed to literally point safari to: localhost:8888/pizza.local ? When I do that, I get a 404 Not Found error
I CAN get to localhost:8888/pizza -- but that requires the settings.php to be in the default sites folder.
Similarly, I can go to localhost:8888/pizza/[any.text.here] and it redirects to the /pizza install page.
Am I correct that the files I should be modifying are
a) the etc/hosts in my computer root
b) httpd.conf in the MAMP apache folder
?
And I don't modify the httpd.conf in the computer's root folder for apache?
Errrr....
So close...
Hi,
You should be able to browse straight to the address: http://pizza.local/
In your /etc/hosts file, pizza.local points to 127.0.0.1, which tells your machine to use the local web server, rather than try and find your site on a remote server.
Since you're calling your local web server, the vhost setup in the apache config tells it which folder corresponds to the URL. The httpd.conf in the root folder only affects the Mac's version of apache, which runs if you activate 'personal web sharing' in the system preferences. Since you're using the MAMP servers, it's the MAMP httpd.conf which needs to be modified.
So, when you browse to http://pizza.local/ apache should serve up pages from the Drupal install, which will look in /sites/pizza.local/ for the settings.php file.
Are you running MAMP on the standard ports? If you're not using the Mac's built-in web sharing, you can set the MAMP preferences to use the standard ports, so that you can connect to MAMP at localhost, rather than localhost:8888, which makes the setup slightly simpler.
really almost there
So I made a huge leap when I checked my system preferences, and indeed -- personal web sharing was turned on. I turned it off, and set the MAMP ports to their defaults (80 and 3306) - and now I can go to pizza.local and firetruck.local. Hooray!
The only problem seems to remain the settings.php files (i think).
For pizza.local, I get a "Site off-line" message.
For firetruck.local, I get the Drupal installation prompt. I can't actually proceed with the installation, because it insists the settings.php go in the Default folder.
I'm not quite sure why I'm getting different results for the two sites -- they seem to be identical except in their respective settings.php files. Odd. I keep reminding myself that there has to be an explanation - computers don't have free will. But I can't seem to find any differences, and they both have me flummoxed.
Any suggestions?
really almost there
So I made a huge leap when I checked my system preferences, and indeed -- personal web sharing was turned on. I turned it off, and set the MAMP ports to their defaults (80 and 3306) - and now I can go to pizza.local and firetruck.local. Hooray!
The only problem seems to remain the settings.php files (i think).
For pizza.local, I get a "Site off-line" message.
For firetruck.local, I get the Drupal installation prompt. I can't actually proceed with the installation, because it insists the settings.php go in the Default folder.
I'm not quite sure why I'm getting different results for the two sites -- they seem to be identical except in their respective settings.php files. Odd. I keep reminding myself that there has to be an explanation - computers don't have free will. But I can't seem to find any differences, and they both have me flummoxed.
Any suggestions?
So close you can smell it
OK, have you copied the settings.php file into the two site folders and made sure they're writable by the Drupal installer? Either use the finder to make the settings.php file writable by all, or chmod it 777 until the installer has run, then back to 644.
If the "site offline" message is a Drupal message, then it implies that the site is up and running, but in maintenance mode - you should still be able to log in as user 1 (the admin user you set up directly after the initial installation) if you browse to pizza.local/user.
If all else fails, and you think the installation has gone screwy, you can always empty the database of all tables in phpMyAdmin and run the installer again.
I never came back to thank
I never came back to thank you for your help! I must have been so overjoyed to get it working... thanks!
No worries
No worries - I figured you either got it working, or beat your computer to a pulp in frustration if you were still stuck!
Backup and Migrate
The only thing I would add to matkeane's excellent advice is to check out Backup and Migrate. There's no easier way to backup a database from a live site to a test site: Create a new site in your local multisite setup, download all the files, modules and themes from the live site, enable the Backup and Migrate module, use Backup and Migrate to restore the database, and that's it.
Be careful when migrating changes from a test site to an existing live site, though. I take the conservative approach of taking the live site offline and adding and configuring new modules/themes manually. I'd love to hear of a faster way, but the manual approach usually doesn't take too long (assuming you've done all the trial-and-error work on a test site, and taken notes of any complicated configuration procedures).
On the other hand, I've found Backup and Migrate works well migrating a database from a test site to a brand new live site.
Backup and Migrate
Hell, how come I didn't know about that module?!
Although, as you say, while it might be really useful for sychronizing a test site, I'm not sure I'd want to use that method to update a live site. I don't mean to knock the module at all but, like you, I prefer to update and check things manually.