Mac OS X Installation Instructions That Don’t Suck! (Rails, Lighttpd, MySQL, Apache2, PHP5)

February 28th, 2006

I had to reinstall my computer the other day, it’s needed it for a while (mostly because I’ve installed every stupid program I could get my hands on for the last 6 months). I haven’t wanted to reinstall because I had a “working” install of Rails and I remembered how hard it was to install last time.

After reinstalling OS X 10.4.5, I started looking for some good instructions on installing Rails. A google search will quickly find about 15 different “suggestions”. Many people suggest using Fink or Darwinports … others have different ways of doing.

Then, I found somewhere on the Rails site, a link to these instructions by Dan Benjamin. Finally, instructions for installing Rails on OS X that don’t suck! Sure, you have to compile most of the apps yourself, but in the end, you get a solid Rails, Lighttpd, MySQL install that should be safe from OS upgrades and the likes. Besides that, you get to learn something along the way.

Following Dan’s suggestion, I also wanted to find a way to install Apache 2 and PHP 5 into /usr/local/. I searched around a bit and found a tutorial by James Pelow over at phpmac.com. I used his instructions as a base for installing Apache 2 and PHP 5. I made sure to download the newest versions of software (the ones he listed are a bit old) and also make sure to install everything in /usr/local/ — works like a charm!

So, now I have a working Apache2/PHP5/MySQL/SQLite setup and also a working Rails/Lighttpd/MySQL setup on the same mac (mini) … and for once, I actually have the feeling that I understand what I’ve done and why it works.

Share and Enjoy:
  • Facebook
  • Twitter
  • Digg
  • del.icio.us
  • Google Bookmarks
  • StumbleUpon
  • Reddit

 

14 Responses to “Mac OS X Installation Instructions That Don’t Suck! (Rails, Lighttpd, MySQL, Apache2, PHP5)”

  1. Chad Says:

    Maybe you can help me. I have a new iMac, and built Rails according tot he Hivelogic article, and that’s all good. But I want to install PHP and can’t figure out how to make it work with LightTPD. So I have been thinking about this for awhile, and have now come to this conclusion:

    I don’t need PHP. Right? I am an ASP developer by trade, trying to get back to the cutting edge, so i was going to learn PHP and RoR…but Ruby can do everything I need to do to build websites right? Since I don’t know PHP, why learn it when I can just learn Ruby and RoR, right? Is there any reason to learn PHP in this case, other than just knowing it? Thanks.

  2. Jim Says:

    Chad,
    You’re right that you don’t “need” PHP. You could do everything in Rails. However, I’ve found it very useful to know some PHP. Many jobs I’ve run across require using PHP, and it has some very useful features built in. I think you’d find learning some basic PHP very easy (since you already know ASP). Check out the tutorials over at http://www.zend.com/php/beginners/

    I’ve never tried to make PHP work with LightTPD, but I know it’s possible. I prefer to use Apache 2 with PHP because that’s what my hosting company uses (for now).

  3. Patrick Says:

    Hey Jim,

    Wondering if you happen to have those instructions for PHP and Apache2 somewhere handy cuz PHPMac.com seems to be down…

    Thanks!

  4. Jim Says:

    PHPMac seems to be back up. Remember to change any paths in the configuration so it installs in /usr/local and not some other place. Also, get the newest versions of Apache and PHP. Good luck!

  5. bill d Says:

    Jim,
    I read a related article on “Hivelogic” about from the page you link to above. It says the following:
    “Set The Path
    By default, tell the system to look in /usr/local for files first by editing your path. On Mac OS X, either create or edit a file called .bash_login in your home folder (note the ?.?, it??s a hidden file) and add the following line to it:
    export PATH=”/usr/local/bin:/usr/local/sbin:$PATH” ”

    Problem is is that I don’t know now to view hidden files. Also, once I can “see” the file how do I open to edit it?

  6. Jim Says:

    Bill,
    Whenever you’re dealing with hidden files in OS X, it’s best to just use Terminal to view them.

    ls – a

    This will show you all files in a directory (including hidden ones).

    nano

    Nano is your best friend when editing configuration files. (ex. nano ~/.bash_login )

    Don’t ever use TextEdit to edit these files as it generally saves them as RTF files, and that’ll really mess things up!

  7. bill d Says:

    Since OS X has hidden the file structure from the “average” user, I would assume that the user/local directory is the default directory when Terminal is opened?

    Or is it another directory. Maybe I need a crash corse on OS X directory structure. And BTW: Did OS X change some of the directory structure of *nix?

  8. Jim Says:

    Bill,
    Like in all *nix systems, Terminal sessions are opened in the user’s home directory (ex, /Users/bill/). This home directory is aliased by the ~ symbol, so ~/Desktop would be the same as /Users/bill/Desktop.

    Yes, OS X does have a different directory structure than, say, FreeBSD or Linux. For example, in Ubuntu Linux the user’s home directory is at /home/username. They also added directories like Applications and Library that are not standard *nix directories. As a general rule, Apple’s custom directories are the ones that are not hidden. Most of the standard *nix directories are there, just hidden.

  9. Chris Says:

    I’m wondering where I will put my server pages if I install Apache2 in usr/local? If it’s in a “hidden” directory, how do I get to the htdocs directory?

  10. Jim Says:

    Chris,
    I usually don’t put my websites in the default Apache folder. Instead, I edit my httpd.conf file to point to a different directory. This is also helpful because it allows you to run more than one virtual site at the same time.

    To edit the file, enter this in Terminal:

    sudo nano /usr/local/apache2/conf/httpd.conf

    Then at the bottom of your configuration file, enter something like this:

    NameVirtualHost 127.0.0.1
    
    <virtualhost 127.0.0.1>
       ServerName sitename.local
       DocumentRoot /Path/To/Web/Files
       AddDefaultCharset utf-8
    </virtualhost>
    

    More info on Name-based Virtual Hosts

    For this to work, you’ll also need to edit your hosts file.

    sudo nano /etc/hosts

    Add your new, local domain name to this file near the top, like this:

    127.0.0.1       sitename.local

    Good Luck!
    Jim

  11. Bryan Says:

    Here’s a question about the ~/.bash_login file. It seems that everytime I open a new Terminal window I have to run that command to get anything to work correctly. If I don’t, its like I don’t have Rails installed. Is that common, or did I install something incorrectly?

    Bryan

  12. Michael Josh Says:

    Hi Jim,

    Another Mac user. I need to configure PHP, MySQL and MySQLi on my Mac for a class.

    So far I’ve got around to using the default Apache installation on OS X, with upgraded versions of PHP and MYSQL.

    However my professor wants to see my Apache error log (which I can’t find). Since I’m using the version of Apache that comes with the system Apache is hidden somewhere, unlike my new PHP and MYSQL installations which are now in /usr/local/.

    For more flexibility I’ve been considering upgrading to Apache 2. I’m afraid it can screw up the OS or something similar. Have you had any problems so far? What do I have to keep in mind to make sure the installation runs smoothly?

    Also how can I following the PHPMAC instructions make sure that Apache 2 gets installed into the /usr/local/ directory?

    Thanks.

  13. Marnen Laibow-Koser Says:

    Apache 2 will not screw up the OS, and you can run it and Apache 1 side by side, as long as you use different ports.

  14. bryan d Says:

    I have an up-to-date and working Rails environment as per the instructions at Hivelogic. However, when I followed the instructions for installing apache2 and php5 at PHPmac – throwing everything in my /usr/local folder – it still says PHP 4.4.7 when I type “php -v” in Terminal. Do I need to edit my path for PHP5 to be recognized? Thanks.

Leave a Reply