Showing posts with label Ruby on Rails. Show all posts
Showing posts with label Ruby on Rails. Show all posts

3.14.2010

Installing RoR on Snow Leopard

The short of it: if you're on Mac OS X (Snow Leopard, in my case), the smoothest way to install RoR is through MacPorts. (Read the excellent instructions by Paul Sturgess).

* * *

Having lots of time to waste , I decided to continue studying RoR. Things have changed since I got my hands dirty with RoR. I'm now running Snow Leopard. RoR has kept maturing in the one-plus year that I stopped tinkering with RoR (had to do C# -- don't ask).

Anyway, I reasoned that the installation problems I encountered in Tiger were a result of Apple's outdated installation of MySQL and Apache. This time, I felt that the Snow Leopard team may have been thoughtful enough to resolve the old issues from Tiger days.

So I happily followed the steps outlined in http://rubyonrails.org/. Things worked well. I was able to create a web app in no time (applause) using SQLLite for my database and doing the blog exercise on the the rubyonrails.org website. However, as soon as I tried to shift to MySQL, my headaches started.

I downloaded the latest dmg file of MySQL. I got different errors when I tried to run rake db:create. RoR refused to create the database on MySQL as promised (it worked fine with SQLLite, the database that comes pre-packaged in RoR). The error messages alternated between the inability to create the database and a syntax error on the .yml file.

Googling revealed that the problem was common. Many solutions were proposed. I tried many of them too. Nothing worked. My RoR-guru-friend Kenneth kept bugging me to just use MacPorts. I told him this would be my last resort and gave myself a deadline.

That deadline has passed without any fruitful solution. So I have taken Kenneth's advice and gone on installing MySQL, Ruby, Rails and Gems on MacPorts.

* * *
Errors and solutions:

  • Can't connect to local MySQL server through socket '/opt/local/var/run/mysql5/mysqld.sock' - This probably means that MySQL is not running. Start MySQL by typing this on the command line: 

sudo /opt/local/share/mysql5/mysql/mysql.server start



    Useful links:





    (Thanks to Kenneth D. for helping me out in setting up RoR).

    12.31.2006

    Ruby on Rails - Finally Running!

    My Ruby on Rails voyage was interrupted by life. But then, finally, on New Year's Eve, I found the time to solve the bug that was stopping me from running RoR on my Mac!

    The error, which I had been encountering since Day 1, was
    “No such file or directory – /tmp/mysql.sock”.
    I thought it was a compatibility problem with the pre-installed Apache on my Mac. I tried using Xampp and Locomotive -- but the error persisted.

    It turns out this is an error unique to Mac OSX. PHP cannot connect to MySQL because it expects the socket file to be in /tmp.

    Solution: trick PHP by tweaking the configs of both Mysql (my.cnf) and PHP (php.ini). Full description of solution from the apple.com site is here: http://docs.info.apple.com/article.html?artnum=301457

    Here's a brief description of the solution:

    Step 1. Create a text file containing the following:

    [mysqld]
    socket=/tmp/mysql.sock


    Save the file into /etc/my.cnf. (for Xampp, this is in /Applications/xampp/etc)

    Step 2: Then in php.ini make the following change or add the ff entry:

    mysql.default_socket = /var/mysql/mysql.sock


    Step 3: For good measure, use the xampp control panel to restart xampp (all components)

    What stumped me at the start was this. When using the default Xampp config with PHPMyAdmin and MySQL, I encountered no problem. But when i made the changes above, PHPMyAdmin stopped working. This indicated that I needed to make changes to the PHPMyAdmin config file.

    I found the solution to the PHPMyAdmin problem by reading through the documentation and is similar to the tweak on PHP config. You just need to tell PHPMyAdmin the location of the mysql.sock file.