Oct 09, 2005
3:30 Sunday afternoon. Finally got my vpn working, so I can now send emails off my desktop at home. Look at my emails, decide I'm not up to it. Browse through the comments on the website. Remember Ruby on Rails. Maybe, I think, I should try working with Ruby before commenting on it.
So I search for Ruby on Rails on Google. Find the Ruby on Rails site, which has some basic info. Realize I'll probably need Ruby for Ruby on Rails to work. Nothing here on that. How about this article? Nope.
4:15. Maybe I already have Ruby. I open up the console application and try:
[stephen@localhost stephen]$ ruby bash: ruby: command not found
OK, maybe not. I try to 'locate' Ruby and find nothing.
OK, maybe on my website then. Since I have vpn working, I can access my website via ssh. Like this:
[root@localhost stephen]# ssh firstname.lastname@example.org Warning: Permanently added 'www.downes.ca,xx.xx.xx.xx' (RSA) to the list of known hosts. email@example.com's password: Last login: Mon Oct 3 22:24:22 2005 from nrc.gc.ca [downess@downes ~]$ ruby -bash: ruby: command not found
So, back to Google, this time to search for Ruby itself. Maybe to find some way of knowing whether I even have it installed, maybe to get it if I don't.
I land at the Ruby home page. Big warning: Ruby vulnerability in the safe level settings. Great, that makes me feel at ease. OK, how about some instructions? I try the documentation and find nothing useful. Scroll down. Oh, isn't that lovely:
Keep scrolling. Scoll back up. Oh wait, a tiny little link at the top, Getting Stated With Ruby.
And am swept away. Not because the book tells me whether I have Ruby or how to install it, but by the most poetic programming guide I have ever read. Time passes as I read the first three chapters. It's basic 'How to program Ruby' stuff, familiar ground, since I read a similar guide a few months back.
This is what convinces me to actually try installing it:
require 'net/http' Net::HTTP.start( 'www.ruby-lang.org', 80 ) do |http| print( http.get( '/en/LICENSE.txt' ).body ) end
What does this do? It accesses a web page (http://www.ruby-lang.org/en/LICENSE.txt), downloads it, and print it to the screen. Beautiful.
4:35. But I'm getting nowhere. I back out, go back to the Ruby Home Pgae, look around again, and see, on the right, the Download Ruby link. OK. The stable release ruby-1.8.3. OK. See that the link is an archive (you can always tell, by the .tar.gz extension). Right-click and save it to my desktop.
4:45. Back into my console again. First, I extract the archive:
[stephen@localhost stephen]$ tar -xzf ruby-1.8.3.tar.gz
This empties the archive into a director called ruby-1.8.3. So I enter the directory:
and then type 'ls' to see what's in there. I type 'more README' to look at the help, and see it's a faily standard install. That means things are pretty standard from here on in.
I have to be a superuser to install ruby, so I type 'su' and then my password. Then I run the configure command:
[root@localhost stephen]# ./configure
My monitor spews output, but everything seems OK (you know it's not OK if you see a bunch of 'Error' messages). Now the software is configured for my won computer. Then I type:
[root@localhost stephen]# make
This will compile the raw code into executibles (basically creating the Linux equivalent of .exe files). Again, much more output.
How did I know to do all this? Well, it's in the README - but more often than not, it's undocumented. Bt this is pretty much the standard way to install software on Linux. So I would probably have been able to guess.
[root@localhost stephen]# make install
This is the money shot. More text. Finally, it finishes and I try again:
[root@localhost ruby-1.8.3]# ruby
I still don't know how to use Ruby. 5:10 p.m., time to go make supper.
5:15. Well, the water's boiling. Still nothing. I type ctl/c and break out of it.
OK. Ruby is a programming language. It probably needs a program to do anything. Back to the documentation. How about Programming Ruby? I need something simple, a 'Hello World' type program. That will tell me whether ruby is running.
Oh, heay, here's a section on downloading and installing Ruby. How about that. Now why isn't this info right on the front page of the Ruby site? I ask you!
Here we go: "The easiest way to run Ruby interactively is simply to type 'ruby' at the shell prompt." That's what I did. But there's more:
% ruby puts "Hello, world!" ^D Hello, world!
OK, let's try that.
OK, took a couple of tries. Note well: "Here we typed in the single puts expression and an end of file character (which is control-D on our system)." I had just thought the ^D was some sort of copying error. But once I figured out that, I was away to the races.
Now: "In the sample directory in the Ruby distribution you'll find a script named 'eval.rb'." OK... but now, ever better, here's the script for a basic Ruby program:
#!/usr/local/bin/ruby -w puts "Hello, World!"
Excellent. I open up kwrite (the Linux equivalent to Notepad), enter the text, and then save it as 'test.rb'. Then I give it permission to execute (on Linux, you aleays have to give programs permission to execute):
[stephen@localhost ruby-1.8.3]$ chmod 775 test.rb
OK, now I'll try running it.
[stephen@localhost ruby-1.8.3]$ ./test.rb Hello, World!
Perfect! It's 5:30 and Ruby is officially installed on my desktop. Now to put it on my web server. This time, I'll try the instructions from Programming Ruby.
[downess@downes ~]$ su [root@downes downess]# cvs -d :pserver:firstname.lastname@example.org:/home/cvs bash: cvs: command not found
This is the thing with Linux. Nothing ever works the way it's documented. Probably, if I want this to work, I'm going to have to install some other package (specifically, cvs) which will let me do this.
I have a better idea. I'll simply open FTP and upload the archive of Ruby I already have on my desktop up to my web server. Just a moment then...
While the file was uploading I put the pasta (ravioli) into the boiling water and stirred it (always using a wooden spoon) while the sauce warmed up in the frying pan. Now I have a bowlful of steaming ravioli and am ready to install Ruby on my web server. It's 5:45.
OK, following the same steps as above, Ruby is now installed on my server. I still have half a bowl of ravioli. It's 5:52. I would have been faster, but I had to follow up an email from Doug kaye.
Now what? Well, let's see if my web server can run Ruby files. I'll make one just like I did before, but with one extra line:
#!/usr/local/bin/ruby -w puts "Content-type: text/html\n\n"; puts "Hello, World!"
The 'Content-type' line has to go at the top of any output from scripts on your webserver. Readers never see it, but the server and browser need to know you intend the output to be a web page. Anyhow, I change the name to testrb.cgi (because my server won't recognize a .rb file as something it has to execute - to fix that, I would have to change my server configuration - easier just to rename the file). I upload it to the cgi-bin directory on my server, chmod it as before, and...
It works! 6:00 p.m.
Ruby On Rails
Now I'm ready to try Ruby on Rails.
I go back to the Ruby on Rails site and click on the Download page. It says: "Rails is primarily distributed through RubyGems â€” the soon-to-be official packaging format for Ruby libs/apps" What the...?!?
See, what Ruby on Rails is, basically, is a framework. What that means is that it's a whole bunch of Ruby code that has already been written. You install the code, then you can write applications on top of it. That way, you don't have to worry about things like connecting to the database, accessing the web, and the like.
Well - once you've installed Ruby on Rails you don't have to worry about it.
OK, so here are the instructions:
- Get hold of RubyGems 0.8.10 (or higher)
- gem install rails --include-dependencies
- rails /complete/path/to/new/railsapp
By 'get hold of' I assume they mean 'download and install' (which makes me wonder, why didn't they say 'download and install'? Oh well. I click on the link (and have a second bowl of ravioli.
A whole list of files. OK, pick the top ones - they seem to be the most recent. .zip is probably a Windows archive.tgz must be Linux (not sure exactly what .tgz is but it's probably like .tar.gz). What the heck is .tgz though?
[stephen@localhost stephen]$ tar -xvf rubygems-0.8.11.tgz tar: This does not look like a tar archive tar: Skipping to next header tar: Archive contains obsolescent base-64 headers tar: Error exit delayed from previous errors
Nope. How about:
[stephen@localhost stephen]$ gunzip rubygems-0.8.11.tgz [stephen@localhost stephen]$
That appears to have done nothing, but I type 'ls' to view my directory and see that the file is now called 'rubygems-0.8.11.tar'. Excellent. Now I simply type:
[stephen@localhost stephen]$ tar -xvf rubygems-0.8.11.tar
and I see the whole thing decompressing (and I realize I should have tried tar -xzf before... oh well).
6:28 and I can now 'cd rubygems-0.8.11' to enter the directory. Typical Linux. Takes 5 minutes to install a program, but half an hour to get to that point.
According to the README, I need now to run:
[stephen@localhost rubygems-0.8.11]$ ruby setup.rb
which I do. Permission denied. oops. I need to be root. OK, type 'su' then the password and try again. "Successfully built RubyGem." Excellent. Now to upload this to the server and do it again. Exactly the same process, and it works fine. 6:32.
OK, the next step:
[root@localhost rubygems-0.8.11]# gem install rails --include-dependencies
Should I have been in root? I don't know. Oh well, too late now. It takes some time to run - "Attempting local installation of 'rails'." Waiting. The word 'successfully' a half dozen times, 'Installing'...
6:45. That worked perfectly. So now to do it on the website.
Now for the third step:
What the !?#@? This isn't an instruction. It's not... anything!
I go back to the documentation and find the Rolling With Ruby on Rails article again, skip over all the crap for Windows to the bottom of the page. It talks about installing MySQL - happily, I have MySQL installed already. Good thing - I can never remember how to restart it.
Next page. It says, "Open a command window and navigate to where you want to create this cookbook web application. I used c:\rails." More Windows crap.
OK. I'll try this directly on the web server, since I don't have MySQL running on my desktop. I'll create a directory called /rails in my web server root and go there. then I'll type the command and see what happens.
[downess@downes opt-httpd-prefork-htdocs]$ cd rails [downess@downes rails]$ rails cookbook /usr/local/lib/ruby/gems/1.8/gems/activesupport-1.1.1/lib/active_support/clean_logger.rb:13:in `remove_const': constant Logger::Format not defined (NameError)
and then a bunch of stuff after that. So what happened? Did it work? The text says "This will create a cookbook subdirectory containing a complete directory tree of folders and files for an empty Rails application."
So I look:
[downess@downes rails]$ ls [downess@downes rails]$
I guess I'm supposed to download the cookbook application. The article has it as a .zip file - I wonder whether I can extract it on Linux.
[root@localhost stephen]# unzip cookbook_part1_0.13.1.zip Archive: cookbook_part1_0.13.1.zip
Yes. Good. I'll upload it to the web server, then, into the rails directory. Then I'll try the rails command again:
[downess@downes rails]$ rails cookbook /usr/local/lib/ruby/gems/1.8/gems/activesupport-1.1.1/lib/active_support/clean_logger.rb:13:in `remove_const': constant Logger::Format not defined (NameError)
Well, that didn't work at all.
I'll try another guide. Let's try Four Days With Rails (and to think - I got a snarky comment when i suggested it might take more than a day). PDF, bleah. I open it up and read: "This example is on my MS-Windows PC. My web stuff is at c:\www\webroot, which I label as drive w: to cut down on typing."
Don't these people realize that most web servers out there run on Linux? Sheesh...
There's that same 'rails' command again. 'Rails ToDo'. It works about as well as 'rails cookbook', which is to say, not at all. Also, there's a bunch of stuff about configuing Apache for Rails. Hm. I try another guide. This one tells me to try 'rails AddressBook'. I get the idea. It still doesn't work.
But I'm not going anywhere until I get past this error.
I try a search in Google. Zero results. I mess around with the search parameters and finally land on this page. It says, "So it looks like Ruby 1.8.3 doesn't play well with Rails (trunk) giving the following error: ./script/../config/../vendor/rails/activesupport/lib/active_support/clean_logger.rb:13:in `remove_const': constant Logger::Format not defined (NameError?)"
Well, that's my error, all right. Now what? I look at the changelog...
# severity changed from normal to critical # priority changed from normal to highest
Sounds about right... I mean, it doesn't run otherwise. But what's this?
* resolution set to fixed * status changed from new to closed
Great. Now what? There is a 'patch' but it consists of about five lines of code to be inserted in some (undesignated) place (obviously the designers know where it goes, but I'm just some schmo trying to install Rails). Why the heck didn't they put the patch in the download? Sheesh.
Back to Google, and I find Ticket #2263 (reopened). Heh. I read:
"Unfortunately, the solution checked into Subversion doesn't work if you're running Ubuntu 5.10 (and I'm guessing Debian sarge) because they have a heavily patched 1.8.2 version of ruby (from CVS) that reports itself as 'ruby 1.8.3 (2005-06-23) [i486-linux]' but has the logger.rb from 1.8.2. Using Rails head, I get empty log lines now with Ubuntu 5.10. While I realize that it may not be really the job of RoR to deal with these patched version of Ruby..."
Well, it looks like it's a wider issue. Here's the proposed solution:
cd ../ruby-1.8.2 ./configure && make && make install
Sweet... if you have Ruby 1.8.2...
So it's back to the top. I'm going to have to install Rails 1.8.2 to make this work. It's now 7:25 p.m. and I'm back where I started.
So I go back to the Ruby directory I installed and type 'make clean'. This removes all the junk from the install (I probably should have done it earlier, but I forgot) but doesn't uninstall Ruby.
Download it, upload it to the web server (I skip doing this on the desktop for now). I delete some spam from my email while I wait. Configure. make. Make Install. make clean. It's a lot faster this time; I know what I'm doing. OK, all installed - do I need to reinstall gems and rails? Probably not... I go back to the Rails directory and try again:
Success! Some days I feel like a genius.
Ruby on Rails (Again)
OK, looking at the fastTrack guide I see that it says "The first thing you need to do for any application is create a database for its data to live in. Technically, this step need not occur first, but it needs to occur early; it should be obvious that you should create the database before any application code, even automatically generated code. So let's create a database in MySQL and craft a first table within this database."
So I do have an instance of MySQL running on my website, so I'll just swipe the FastTrack code and create the database. I copy the code below, open phpMyAdmin, create AddressBook as a new database, then run the following as SQL:
CREATE TABLE IF NOT EXISTS contacts ( id smallint(5) unsigned NOT NULL auto_increment, name varchar(30) NOT NULL default '', created_on timestamp(14) NOT NULL, updated_on timestamp(14) NOT NULL, PRIMARY KEY (id), UNIQUE KEY name_key (name) ) TYPE=MyISAM COMMENT='List of Contacts';
And I note in the commentary: "Of central importance is that every table must have an id column with exactly that name. Rails uses the primary key column id for various recordkeeping and referencing tasks. The fields created_on and updated_on are not required, but if you do include them, Rails maintains them automatically "behind the scenes"; in most cases there is no harm in using these timestamps. So the only "real" data you have yet added is a name for your address book contacts." Also, "Table names should use the plural form."
See, the way a framework works is that things like the database are standardized. That way, the same function can be used on every table of every database.
OK, what next? I need to allow Rails to access my database. This step is pretty murky. here's what I read:
[~/Sites]$ cd AddressBook [~/Sites/AddressBook]$ head -6 config/database.yml # after editing development: adapter: mysql database: AddressBook host: localhost username: some_user password: password_if_needed
That simply generated a bunch of errors. So I tried the first line:
[root@downes rails]# head -6 config/database.yml
That played back all the text above. OK, what I must need to do is to edit some file to my own database settings, then run the head command. I guess? I use vi and make the changes (you could use any text editor). Then I run the head command and see my changes.
Now I need to start the Rails server. Basically, Rails acts as its own web server, bypassing Apache. Apparently it's faster. But I'm a bit nervous: it appears to use port 3000. I'm in a stupidly secure environment. Will port 3000 even work.
Well, I kickstart it:
[root@downes AddressBook]# script/server -d => Rails application started on http://0.0.0.0:3000 [2005-10-09 19:57:17] INFO WEBrick 1.3.1 [2005-10-09 19:57:17] INFO ruby 1.8.2 (2004-12-25) [i686-linux]
OK, that looks good. It's now 8:00. A short break, at at 8:05 I try out my site. http://www.downes.ca:3000/ is where it should be. I enter the address... and... "Congratulations, you've put Ruby on Rails!" Joy, oh joy!
The welcome page has some instructions for me, so I check them. chmod some directories. Fine. Check the header in the dispatch files. Fine. Now a tricky one - edit the httpd.conf file to run some modules needed by Rails. Good thing i have access - users usually don't have access to the Apache configuration file. Nerously use vi and open the file, check to see whether what I need is there (one line is there) and add the other two. For this to work I'll probably have to restart the server, but I always forget how, so I'll reboot the system, which will restart the server.
8:45 - well, the server didn't restart. So I removed the lines I added to the httpd.conf file and rebooted again. This time it started. So obviously the lines that the Ruby on Rails intro page says I need to add are not quite right.
What would make them right? I try to go back to the Rails page on my server (downes.ca:3000) but it doesn't load. Right, I need to restart the Rails server. So I do that, and now I have an error message:
Rails Error: Unable to access log file. Please ensure that log/development.log exists and is chmod 0666. The log level has been raised to WARN and the output directed to STDERR until the problem is fixed. => Rails application started on http://0.0.0.0:3000
Sheesh - I am beginning to think I should have simply ignored the instructions on the Rails start page.
Oh well. Into the directory, and change the permissions:
[downess@downes AddressBook]$ cd log [downess@downes log]$ ls development.log production.log server.log test.log [downess@downes log]$ chmod 0666 * chmod: changing permissions of `development.log': Operation not permitted ... [downess@downes log]$ su [root@downes log]# chmod 0666 *
Sheesh, nothing is ever simple, is it?
Try to start up the Rails page again. It's still not loading. I think I'll back out and start again. I think I'll erase everything in the AddressBook directory and run the 'rails' command again (using the dreaded rm -r command - be vewy vewy careful).
Nothing happens. Everything is frozen. I can't seem to type anything into the console. My home page isn't loading. What? Oh no! Wait a second... I try another web page. It doesn't load either. Ah! It's simply that my internet connection has dropped. So I have an enforced break while i wait for a bit for Rogers Cable to get its act together. It's 8:55. But wait. Why is the laptop still working. Huh?
OK, I'm back. I rebooted my desktop. No idea what happened. Tried downes.ca:3000 again, and that's still not loading - but at least everything else is. OK then. Maybe I'll try starting the Rails server again.
[downess@downes AddressBook]$ script/server -d => Rails application started on http://0.0.0.0:3000 [2005-10-09 21:01:20] INFO WEBrick 1.3.1 [2005-10-09 21:01:20] INFO ruby 1.8.2 (2004-12-25) [i686-linux] [2005-10-09 21:01:20] WARN TCPServer Error: Address already in use - bind(2)
OK then. Now what? How do I shut down the server? I 'cd' into the 'script' directory and type 'server', hoping for some help. I am rewarded.
[downess@downes script]$ ./server => Rails application started on http://0.0.0.0:3000 => Ctrl-C to shutdown server; call with --help for options
I type Ctl-C. Nothing. Looks like the server is still running. Why would such blatantly false instructions be in the help? Now what? I type 'ps -A' to see what's running. There's an application called 'server' running. Come to think of it, 'server' isn't such a bright name for an application. Still, I type 'kill 3453 to shut down the server application. The process is gone. Was it the right one? I try to restart the server.
[downess@downes AddressBook]$ script/server -d => Rails application started on http://0.0.0.0:3000 [2005-10-09 21:11:46] INFO WEBrick 1.3.1 [2005-10-09 21:11:46] INFO ruby 1.8.2 (2004-12-25) [i686-linux]
OK, that's good. It's running again - and it started error-free this time. Maybe I won't have to wipe things out. Let's try downes.ca:3000 again and see.
No joy. It simply won't load the page. I really should have ignored those instructions. OK then, I'll kill the server, then wipe out the directory, then start over.
So I do that (using - very carefully - 'rm -r AddressBook'. Then I run 'rails AddressBook' again, redo the configuration file, then start up the Rails server one more time. And test downes.ca:3000/
Nothing. It's 9:35 and I have utterly nothing to show for 6 hours work.
That is why I make snarky remarks in my newsletter.
8:30 a.m. Monday morning. It's a holiday, so I can delay filling out forms for another day. I decide to look at Rails again.
Thinking about it, I've decided that the error probably occurred here:
Rails Error: Unable to access log file. Please ensure that log/development.log exists and is chmod 0666. The log level has been raised to WARN and the output directed to STDERR until the problem is fixed.
Why? Well, it can't be httpd.conf because that's back to exactly what it was when I started. I didn't change the dispatch files at all. And Rails feels like it's routing output somewhere else - my attempts to log on to downes.ca:3000 are not being met with a 'connection refused', they're simply not generating any response.
So, what to do? I figure I'll go back and install Rails again. So I log back into my server and
[downess@downes ~]$ su [root@downes downess]# cd rubygems-0.8.11 [root@downes rubygems-0.8.11]# gem install rails --include-dependencies Attempting local installation of 'rails' Local gem file not found: rails*.gem Attempting remote installation of 'rails' Updating Gem source index for: http://gems.rubyforge.org Successfully installed rails-0.13.1
Just like before. Now I'll go clear out the AddressBook directory and try again. That done, I reinitialize AddressBook, chnage database.yml, and startup the server. Oops, it has been running since last night. Kill it, start again. Try to open downes.ca:3000. No luck. Maybe another port? I try
[root@downes AddressBook]# script/server -d -p 2999
to try to start it on port 2999. Any luck? No. 8:45 a.m.
It then occurs to me that I saw something about a test utility called 'rake' in some documentation. I try a Google search, and end up on this help page for Rake. The safest thing to try is 'rake --tasks' so I type that in and get a list of tasks. Good. Rake is working. I look at the task list, and of course, I have to guess at what to try next:
[root@downes log]# rake default (in /home/downess/opt-httpd-prefork-htdocs/rails/AddressBook) rake aborted! 'Packets out of order' error was received from the database. Please update your mysql bindings (gem update mysql) and read http://dev.mysql.com/doc/mysql/en/password-hashing.html for more information. ./Rakefile:151
Hm. So I look at the help page as suggested, and it turns out to be a page of gibberish on the MySQL site. Maybe I'll try to update my mysql bindings.
[root@downes log]# gem update mysql Upgrading installed gems... Attempting remote upgrade of mysql Attempting remote installation of 'mysql' Building native extensions. This could take a while... ERROR: While executing gem ... (RuntimeError) ERROR: Failed to build gem native extension. Gem files will remain installed in /usr/local/lib/ruby/gems/1.8/gems/mysql-2.6 for inspection. ruby extconf.rb update mysql\nchecking for mysql_query() in -lmysqlclient... no checking for main() in -lm... yes checking for mysql_query() in -lmysqlclient... no checking for main() in -lz... yes checking for mysql_query() in -lmysqlclient... no checking for main() in -lsocket... no checking for mysql_query() in -lmysqlclient... no checking for main() in -lnsl... yes checking for mysql_query() in -lmysqlclient... no Results logged to /usr/local/lib/ruby/gems/1.8/gems/mysql-2.6/gem_make.out
svn update vendor/rails ruby script/server - first db access works. any subsequent db accesses get "packets out of order" error. cd vendor/rails svn update -r 1790 everything works again.
Well, that looks like my problem. Let's try the fix:
[root@downes AddressBook]# cd vendor/rails bash: cd: vendor/rails: No such file or directory [root@downes AddressBook]# cd vendor [root@downes vendor]# ls [root@downes vendor]# cd .. [root@downes AddressBook]# cd .. [root@downes rails]# svn update -r 1790 bash: svn: command not found
So. The directory doesn't exist, and the command doesn't function. OK, back to the page I found. Scrolling down, I see this was a common problem. At the bottom of the page is a link to this discussion. Yes, there's my error, with a lot of discussion around it. Something to do with old/new MySQL logins. As one commentator writes, "Long story short, the version of mysql-ruby that is getting shipped with RubyGems is two bugfix releases behind, so just install the latest version from source." Sheesh. And what a weird error - works once, never works again! That's the sort of error that just sucks the life out of you. 9:15 a.m.
I read through the commentary. A dozen different solutions are proposed. Some work, some don't. Which to choose? I try the one that looks the most straightforward:
However, using my old user/password and commenting the line require â€˜active_record/vendor/mysql411â€™ from mysql_adapter.rb worked for me.
So I search for the file in question, open it up using vi, and comment out the line. What is the 'comment out' character in Ruby? Not sure... I scoll down a bit. Ah - just like normal, just use the hash mark (#) in front of the line. I save the file.
[root@downes rails]# locate *mysql_adapter.rb /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.11.1/lib/active_record/connection_adapters/mysql_adapter.rb [root@downes rails]# vi /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.11.1/lib/active_record/connection_adapters/mysql_adapter.rb
Now what? There was no next step described.
Maybe try the 'gem update mysql' again. No, it fails, just like before. Just try downes.ca:3000? No, it still stalls out. I try the next solution proposed on the discussion board.
I had the same problem and tried to â€œgem install mysqlâ€?. It failed. I ran extconf.rb for mysql sources that gem wisely saved. Extconf.rb looks for mysql lib and include directories in /usr/local whereas in my case they were in /usr/local/mysql. Adding parameters to extconf.rb solved the problem:
OK, where is my mysql lib? I have no idea. Let's check /usr/local/mysql. Yes, there they are. I think. So I decide to follow what this person did.
cd /usr/lib/ruby/gems/1.8/gems/mysql-2.5.1 sudo ruby extconf.rb --with-mysql-dir=/usr/local/mysql sudo make sudo make install
I try the first command 'cd' and it reports back, directory not found. Sheesh. I use 'locate /*ruby*' to find the right directory. It turns out to be /usr/local/lib/ruby/gems/1.8/gems/mysql-2.6. OK, let's try the commands.
[root@downes mysql-2.6]# sudo ruby extconf.rb --with-mysql-dir=/usr/local/mysql checking for mysql_query() in -lmysqlclient... yes checking for mysql_ssl_set()... yes checking for mysql.h... no checking for mysql/mysql.h... yes creating Makefile [root@downes mysql-2.6]# sudo make gcc -fPIC -g -O2 -I. -I/usr/local/lib/ruby/1.8/i686-linux -I/usr/local/lib/ruby/1.8/i686-linux -I. -DHAVE_MYSQL_SSL_SET -DHAVE_MYSQL_MYSQL_H -I/usr/local/mysql/include -c mysql.c gcc -shared -L'/usr/local/mysql/lib' -Wl,-R'/usr/local/mysql/lib' -L'/usr/local/lib' -Wl,-R'/usr/local/lib' -L'/usr/local/mysql/lib/mysql' -Wl,-R'/usr/local/mysql/lib/mysql' -o mysql.so mysql.o -lmysqlclient -ldl -lcrypt -lm -lc [root@downes mysql-2.6]# sudo make install install -c -p -m 0755 mysql.so /usr/local/lib/ruby/site_ruby/1.8/i686-linux
OK. Now what. Try the 'gem update mysql' command again? Not sure. I try it.
[root@downes mysql-2.6]# gem update mysql Upgrading installed gems... Attempting remote upgrade of mysql Attempting remote installation of 'mysql' Building native extensions. This could take a while... ruby extconf.rb update mysql checking for mysql_query() in -lmysqlclient... no checking for main() in -lm... yes checking for mysql_query() in -lmysqlclient... no checking for main() in -lz... yes checking for mysql_query() in -lmysqlclient... no checking for main() in -lsocket... no checking for mysql_query() in -lmysqlclient... no checking for main() in -lnsl... yes checking for mysql_query() in -lmysqlclient... no make make: Nothing to be done for `all'. make install install -c -p -m 0755 mysql.so /usr/local/lib/ruby/gems/1.8/gems/mysql-2.6/lib Successfully installed mysql-2.6 Gems: [mysql] updated
Ah. That's much better. OK, let's kill the server, remove AddressBook, and start again from scratch. Type 'rails AddressBook' again, edit database.yml again, run the 'head' command, start the server, and try to open downes.ca:3000 and... nothing. Bleah.
I decide to try the 'rake default' command again, just in case something has changed.
[root@downes AddressBook]# rake default (in /home/downess/opt-httpd-prefork-htdocs/rails/AddressBook) rake aborted! Access denied for user 'downess'@'localhost' to database 'AddressBook' ./Rakefile:151
See, one of the things I like about Perl is that I get my error messages right on the screen. This business of just sitting there and doing nothing is really not working for me. In any case, what I see here is a different error, an access denied error. That means it might be something I can fix in MySQL - it is, after all, a brand new database, and so I may need to explicitly allow the username to access it. I go into phpMyAdmin and run the following:
REVOKE ALL PRIVILEGES ON `AddressBook` . * FROM "downess"@ "localhost"; GRANT ALL PRIVILEGES ON `AddressBook` . * TO "downess"@ "localhost" WITH GRANT OPTION ;
Now I try the 'rake default' command again. It's slightly different:
[root@downes AddressBook]# rake default (in /home/downess/opt-httpd-prefork-htdocs/rails/AddressBook) rake aborted! Access denied for user 'root'@'localhost' (using password: NO) ./Rakefile:173
OK, then. I do the same thing, except for root@localhost. And try the 'rake default' command again. And it fails, with the same error. I check root's privileges again. He pretty much has everything; I'm not sure what more I could offer. What's he trying to do? I take a look, and it looks like he's trying to empty the test database. Well, I haven't configured a test database at all; that would explain the access denied, I suppose. I open up database.yml and look at it. Yes, there it is:
test: adapter: mysql database: rails_test host: localhost username: root password:
OK, no access of that configuration is authorized. I'll edit this to make it match the other. Then run 'rake default again'.
[root@downes AddressBook]# rake default (in /home/downess/opt-httpd-prefork-htdocs/rails/AddressBook) /usr/local/bin/ruby -Ilib:test "/usr/local/lib/ruby/gems/1.8/gems/rake-0.6.2/lib/rake/rake_test_loader.rb" /usr/local/bin/ruby -Ilib:test "/usr/local/lib/ruby/gems/1.8/gems/rake-0.6.2/lib/rake/rake_test_loader.rb"
What does that mean? It appears to have worked. This is good. 10:15 a.m. Time for a break.
11:30. OK, erase AddressBook, and start it up again. Same procedure. No joy. OK, the changes I made were to gems. So perhaps if I reinstall Rails now, gems will install a version that plays nice with mysql. I wish I knew whether 'gem install rails --include-dependencies' actually replaced the previous instance of Rails - I can imagine a programmer checking the headers and deciding to skip the install if the previously installed version looks current. Oh well.
[root@downes AddressBook]# gem install rails --include-dependencies Attempting local installation of 'rails' Local gem file not found: rails*.gem Attempting remote installation of 'rails' Successfully installed rails-0.13.1
I wonder why it never finds the local gem file. Is there something I should know? Oh well. Clear out AddressBook yet again, edit database.yml, run head, kill the previous server process, restart the Rails server. And... nothing. OK, let's check the mysql error log. Where is it? I try 'locate /*mysql*log' but it shows nothing that looks like an error log. How about 'locate /*mysql*log*'? No. Maybe 'locate /*mysql*error*'? Again, nothing that looks like an error log. OK, cd '/usr/local/mysql'. Hunt around. Nothing. Try a Google search. Well, this article tells me how to set up logs, but doesn't tell me where they are. This page on the badly document mysql site tells me that the files seem to be named .err (it's hard to say for sure - one sentence says errors are routed to the console, which would be idiocy).
So I try 'locate /*mysql*err' which gives me a pile of results. The very last result, though, includes the string 'downes.ca.err', which suggests to me trying 'locate /*downes.ca.err'. That gives me a half dozen hits. I decide to try for /opt/mysql-4.0.20/data/downes.ca.err. I type 'tail downes.ca.err' after entering the directory, so I see only the end of the file. Nope, that's from last January. Let's try /var/lib/mysql/downes.ca.err. Nope, that's the same file, it looks like. OK, how about /opt/mysql-4.1.9/var/downes.ca.err? I cd into /opt/mysql-4.1.9/var/ and type 'ls' to see what's in there. What the heck?
AddressBook downes-bin.000006 downes-bin.000012 downes-bin.000018 edurss moodle urchin downes-bin.000001 downes-bin.000007 downes-bin.000013 downes-bin.index elgg mysql wikiplam downes-bin.000002 downes-bin.000008 downes-bin.000014 downes.ca.err etomite mysql.sql wordpress downes-bin.000003 downes-bin.000009 downes-bin.000015 downes.ca.pid ibdata1 scoop downes-bin.000004 downes-bin.000010 downes-bin.000016 drupal ib_logfile0 test downes-bin.000005 downes-bin.000011 downes-bin.000017 dwiki ib_logfile1 test_you_can_safely_delete
AddressBook! It's a directory, so I 'cd AddressBook' and look inside.
[root@downes var]# cd AddressBook/ [root@downes AddressBook]# ls contacts.frm contacts.MYD contacts.MYI db.opt
Hm. None of these look like an error. Back up, then, to look at the error file.
051009 21:39:43 mysqld started 051009 21:39:44 InnoDB: Started; log sequence number 0 1323437 /opt/mysql-4.1.9/libexec/mysqld: ready for connections. Version: '4.1.9-log' socket: '/tmp/mysql.sock' port: 3306 Source distribution
There's the reboot from yesterday. Mysql came back up, and sat waiting, error-free, while it handled the various requests from my website. No errors at all. What gives? Back into the AddressBook directory. The first three files contain binary data, which I can't read. The last:
[root@downes AddressBook]# more db.opt default-character-set=latin1 default-collation=latin1_swedish_ci
Swedish? Huh? But that's probably not the cause of my problem. What is? I don't know. Let's reboot the server.
Server's back up. Try to ssh back into it. Now I'm getting password error problems. Permission denied. Oops, forgot to start the vpn. Start the vpn, then try to login. Permission denied. I can't enter my own server. FTP access also fails. I've probably tripped up on of those stupid security systems by trying to login without vpn. So I'm shut out until the system either clears itself or until I can get into it physically on Tuesday. It's 12:25 pm.
1:00 p.m. Still locked out. But I've been thinking, rereading this document. When I ran 'gem install rails --include-dependencies' the first time, it gave me a whole string of stuff - a bunch of 'success' and 'installed' messages. But when I ran it later, it simply gave me the 'Rails installed' message. This means it's not reinstalling the dependencies, just Rails. And my problem - accessing MySQL - is probably in one of the dependencies. So even though I've fixed gems, it might not be installing Rails properly. Hm. But wait, if that were so, rake wouldn't have run properly. And it did. Maybe that's not it either. Hm. What I want to do is remove everything I installed and to start over, knowing what I know about the various fixes I need to make to things. But how to do that? I have no idea.
I've gone back to the Ruby on Rails site. This time I click on Community. I want someone to send this file to; maybe they can suggest something. But it doesn't look like a community at all - it looks like instructions on how to install Rails. Wha? I click on Start at the beginning and there's some diatribe about Rails and Ajax. Interesting, but definitely not the beginning. Check Getting Started on Rails. It begins, "Make sure you have Ruby 1.8.2 installed." Yeah, right, learned that the hard way. Most of the rest looks like what I've done so far (no mention of the errors, though). I note the Apache stuff, which is different. In addition to the stuff about mod_rewrite.so there's also a whole bunch of code to enable Rails to do redirects (that's when a server gets a request for one page, and sends it to a different place - it allows for simple URLs). Well, trying to load 'mod_rewrite.so' simply crashed my server before. Does Rails require Apache 2 or something? Ah, but I look at this page. I'm not at that point yet; it simply shouldn't be a factor. Accessing downes.ca:3000 should access Rails, without redirects. Like it did before.
I wonder about uninstalling Rails. It seems to me there ought to be an 'gems uninstall' to match 'gems install'. I try a Google search. Yes, there it is - naturally, a discussion list question about why it doesn't work. Still, will it work? I look at this Rubyforge page and it appears you can order it to remove the dependencies as well. Except, (from here), "The current gems software is a bit sloppy in its dependency evaluations while deleting." Still, it looks like 'gems uninstall rails --include-dependencies' would do the trick. 1:30 p.m. Still locked out of my web server.