By David - Posted on 11 September 2008

Setting up a local server environment on Windows and Mac

The video course does a great job of demonstrating how to quickly and easily set up a local web server environment on your home computer (using WAMP for Windows and MAMP for Mac OS X), which is highly -highly- recommended.

It's as simple as downloading and installing a free program, and worth its weight in gold. It's always recommended to develop your website "offline" on your local computer using these tools, instead of "live" on the real web server. A local server environment allows you to work many times faster than you can on a remote server, and gives you an opportunity to easily back up your site's files/database as quickly and easily as copying a few directories, just like you would with any other files on your computer. This makes it easy to feel free to experiment with Drupal, installing modules, etc - if you make a mistake or a module you install somehow goes horribly wrong, it's a piece of cake to restore your site to how it was before. Even after you migrate your website to a live web server after it's complete, you should still keep one or more "test" copies of Drupal installed on your local server, where you can freely install modules and updates ahead of time, ensuring that they will work before you install them on your live website and risk causing downtime if things go wrong.

Installing MAMP (on Mac OS X)

The videos in this section are chock-full of excellent and helpful information to help you get Drupal up and running on your computer. Below you'll find a few additional tips on how to get the most out of Drupal on your local installation, as well as one important tip regarding installing Drupal on Macs and other Unix systems.

Apache and MySQL ports

There are a few pros and cons to weigh regarding setting MAMP's Apache and MySQL ports either to MAMP's custom values or the "standard" default values as used on the web (80 and 3306). In any case the ports will not show up when you upload your site to your hosting provider.

The benefit of changing the ports to the "standard" values (80 and 3306) is that they do not need to be entered in your URLs when you type them in your browser. The downside is that you will need to type in your account password when you start or restart MAMP's Apache and MySQL services. This is because OS X, being a Unix-based system under the hood, actually already has its "own" copy of Apache and MySQL installed and thus reserves those ports by default; however Apple's versions are not as up to date, full-featured, and easy to configure as MAMP's, so for web development it is best to use MAMP's versions. In either case, the port numbers will have no effect on your "live" website when you publish it online. If you already use OS X features such as "Web Sharing", then changing from MAMP's custom ports can cause those features to malfunction, so in that case you might want to leave MAMP's port setting alone.

Enable Caching to speed up Drupal

This sounds scary and complex, but it's actually quite simple and worth doing since it will make Drupal run much much faster - all you have to do is switch on an option in MAMP. While configuring MAMP, go to Preferences, and choose the PHP section. Choose one of the options listed under Cache (it doesn't matter which you choose, though I personally prefer APC or eAccelerator).

In case you're curious, these three options are called PHP opcode caches... you can read about and view some Drupal-specific graphs/statistics on how an opcode cache can help Drupal perform faster, and using considerably less server resources. Most hosting providers/servers will be running one of the three listed here, but you can select whichever you prefer or find to perform best on your own system.

If you're using WAMP, it does not come with an opcode cache by default, but if you'd like to install one check Google for instructions (alternately, you can opt to use XAMPP instead of WAMP, which comes with eAccelerator).

Setting the Document Root for MAMP

In the video it is recommended that you set MAMP's Document Root to /Users/yourname/Sites/drupal. To keep it simple to follow along with the videos, go ahead and set it this way as recommended.

However, in the future you may want/need to change this if you plan to have any more than one website (which even if you don't have more than one "website" you may still want to have extra copies of Drupal to test with, other CMSes to try out, etc). MAMP's Document Root is a place where "multiple" websites can exist, not just one (each folder within the Document Root can be a separate website). So later after you finish the video course and begin working on "your own" website, I suggest changing MAMP's Document Root to be only /Users/yourname/Sites. In the Sites folder you will still have a sub-folder called drupal (where the video course's Drupal installation is located), but you can also add as many other websites as you wish as well. You'll be able to access any local website with an address like this: http://localhost/drupal or http://localhost/another-site.

Setting up the database on a Mac

If you're installing Drupal on MAMP, then the default MySQL user is root and the password is root as well.

Downloading and installing Drupal on a Mac

Important note about installing Drupal on a Mac (or any Unix-based/Linux system)

On a Mac/Unix-based system, you should not drag and drop Drupal's files into another folder in the way shown in the video. There is a hidden .htaccess file included in Drupal's root directory when you extract it, which gets left out if you copy the contents of the folder this way. On Unix systems (including OS X) files that start with a period are hidden by default (on Windows however, the .htaccess file will show up like a normal file and not be hidden, as that is not how Windows hides files). In the video, the files/folders are manually dragged and dropped out of the extracted drupal-6.3 directory on the Desktop and into another "drupal" folder that was prepared in MAMP's Document Root. Unfortunately, the hidden .htaccess file does "not" get copied along with everything else, since it's not visible to be selected.

This won't affect you if you're working with Windows to develop your Drupal site, however it is still a very important concept to understand, since when you upload Drupal to your hosting service online, it will in all likelihood be on a Unix-based server, and the .htaccess file will disappear as soon as you upload it. It's still there however and is crucially important to Drupal. Many FTP and SFTP programs have a feature available to "show hidden files", which I strongly suggest you turn on. This is important to understand in general, regarding all web development on Unix-based servers, including all CMSes not just Drupal.

So, if you are installing Drupal on a Mac or any Unix system, then the best way to ensure that the .htaccess file does not get lost during installation is to place Drupal's tar.gz archive file which you downloaded into the parent directory of where you want Drupal to be installed, and then double click to extract the archive right there and do not move or copy the folder's contents. You can also move the whole folder to any other location, but do not move only the "contents" of the folder, or the hidden .htaccess file will not come along for the ride. When Drupal's folder is extracted, feel free to rename it however you prefer (e.g. from drupal-6.3 to drupal, YourSiteName, or whatever you like). You can most easily check to ensure that the .htacccess file is present by using a code editor that supports viewing hidden files, such as the amazing, cross platform, (and free) Komodo Edit.

How to fix your .htaccess file if you already dragged and dropped files to install Drupal:
If you did drag and drop the files and folders while installing Drupal on OS X (or another Unix-based system), and have found your .htaccess file to be missing, the easiest way to replace it is to extract another temporary copy of Drupal, open its directory in Komodo Edit (or similar), open the .htaccess file you see, copy and paste its contents into a new blank file, and then save that file with the name .htaccess in the root of your Drupal website.

Copying default.settings.php

(Need to double-check) The video mentions that you can simply rename default.settings.php instead of making a copy and naming it settings.php. My experience has been that default.settings.php has to remain, so making a copy and renaming that is advised.

PHP memory limit

While setting a memory limit in php.ini, I recommend that you set this to a higher value, so long as your hosting provider supports a higher value; some more memory-intensive modules you may want to use might tip you past 16M, so if possible, set this higher to something like 24M or 32M. Don't set the value in your local server higher than your hosting provider supports, or you may find your Drupal site will not run when you move it online (when Drupal exceeds the memory limit, this is often jokingly referred to as the "white screen of death"). To find out the memory limit that your hosting provider supports, create a new called phpinfo.php and add the following line into it: <?php phpinfo(); ?>. Upload the file anywhere on your online web server, and when you visit that address you'll be presented with your host's PHP configuration settings. Search for "memory" and you should be able to find out the top limit they have set. If it is too low, you might want to consider contacting your host to see if it can be raised, or else consider seeking out a new hosting provider. Be sure to delete the phpinfo.php file from your server right away, as it is insecure to leave it lying around.

Note: If you're a Windows user, do watch the Mac videos

Both the Windows and Mac videos cover how to install Drupal under each respective operating system. If you're a Windows user, I'd still encourage you to watch the Mac videos, as they offer a bit more detail in various steps compared to the single Windows/WAMP video. If you skip the Mac videos you may miss some important and helpful tips. Overall these videos answer a great majority of the questions Drupal newbies often run into while installing Drupal.

Automating updates with cron

While I recommend watching the video about Cron to get a more advanced look at how Cron works, don't sweat it if Cron leaves your head spinning.

First, you should decide whether you actually "want" to run automated Cron jobs on your local server (you definitely want to run them on your online server, but you can decide with your local server). For one, they will only work while the local server program is running (MAMP, WAMP, etc), which may not be all the time. Also, some tasks Cron can perform in Drupal can potentially be CPU-intensive depending on the modules you have installed in Drupal (such as converting videos, etc), which could cause a slowdown for your system at an inopportune time. Instead you might prefer to run Cron manually on an as-needed basis while you're working on your site, instead of having it suddenly run at other times while you're not working on your site. If you'd rather just run Cron manually on your local server, you can do so at Administer > Reports > Status report, and clicking on the "run cron manually" link.

If you decide that you "do" want to set up Cron to run automatically on your local server, there are some programs available that make it easier to configure than by dealing with the command line:

  • If you use a Mac, I recommend that you download Lingon (OS X Leopard only... if you're using Tiger you can use Lingon as well, but need to use version 1.2.1), or if you're using versions "below" Tiger (Panther, etc) then use CronniX.
  • If you're using Windows, here's info on how to setup Windows Scheduler to run your cron.php file for Drupal. See the comments as well at the bottom of that page if you'd like alternatives to Windows Scheduler.

When it comes time to publish your Drupal site online to your hosting provider's server, there's a good chance that your web host offers a simple tool within your hosting control panel (such as with cPanel) to allow you to specify the command to run, and then choose the time(s) to run it using a more friendly interface. In more rare instances you may have to configure Cron using the command line, and if so, then this video should prove very helpful.