Linux

How to Install Ruby on Rails using MySQL 5 for Apache 2 on Fedora Core 6

Be ready to hate Ruby on Rails. I’m learning the hard way so you don’t have to. Hopefully this page will help you. This how-to assumes you know how to use a root account, how to configure and install applications, and how to configure Apache. Use the root account for the following or prefix every command with sudo.

  1. Get some packages using Yum


    yum install ruby ruby-devel ruby-rdoc ruby-irb ruby-ri httpd-devel sqlite2-devel mysql-devel

  2. Download, compile, and install FastCGI and its Apache module

    FastCGI: http://www.fastcgi.com/dist/fcgi-2.4.0.tar.gz
    Module for Apache 2: http://www.fastcgi.com/dist/mod_fastcgi-2.4.6.tar.gz
    Decompress them and do the usual “configure, make, make install” procedure.

  3. Get some packages using Gem


    gem install rails fcgi sqlite

    Don’t forget the binding for MySQL:

    gem install mysql -- --with-mysql-lib=/usr/lib/mysql

  4. Update and reload configuration of Apache

    Create a new file in /usr/httpd/conf.d called fastcgi.conf with the following content:

    LoadModule fastcgi_module modules/mod_fastcgi.so

    FastCgiIpcDir /tmp/fcgi_ipc/
    AddHandler fastcgi-script .fcgi


    Create above-mentioned directory and set its permissions:

    mkdir /tmp/fcgi_ipc
    chmod -R 777 /tmp/fcgi_ipc

    When you’re done, reload the configuration:

    service httpd reload

  5. Create and configure a Ruby application directory

    Create an application directory. In this example, we’ll call it rubyapp:

    ruby /path/to/rubyapp
    cd /path/to/rubyapp

    Modify the public/.htaccess file and remove or comment out the following line:

    #RewriteRule ^(.*)$ dispatch.cgi [QSA,L]

    And add the following:

    RewriteRule ^(.*)$ dispatch.fcgi [QSA,L]

    In the config/environment.fb file, uncomment the following line:

    ENV['RAILS_ENV'] ||= 'production'

  6. View your Ruby application with a browser

    Make sure the public directory is served by Apache. This should be the only directory viewable in a Web browser. For example, let’s assume http://localhost/rubyapp/ points to /path/to/rubyapp/public. By going to that address, you should read a “Welcome aboard!” page. Read the instructions on that page to finish the set-up.

  7. Let the Ruby application use MySQL instead of SQLite

    Modify config/database.yml. Replace the production section with the following:

    production:
    adapter: mysql
    database: [databasename]
    username: [username]
    password: [password]
    timeout: 5000

One page that helped me:

Linux: 100% CPU when reading a large FAT parition

in

My boss purchased a new 500GB external hard drive. When I plugged it via USB in our of our Linux servers, and mounted its FAT partition, doing anything on it was taking forever, with 100% CPU.

After searching on Google, I found the following:
http://www.mail-archive.com/linux-usb-devel@lists.sourceforge.net/msg56503.html

Apparently, simply adding “usefree” to the mount options will prevent this from happening.

Locked outside of MySQL and lost root password

That happened to me today. I was updating the privileges for root and I ended up locking myself out of the database. Bravo! Luckily, I found a solution from the MySQL Web site. As the system’s (not MySQL server’s) root, in the terminal, do the following:


# service mysqld stop
# mysqld_safe --skip-grant-tables &
# mysql -u root mysql

The above restarts MySQL without loading the privileges table. Once in the MySQL prompt, type in the following:


> UPDATE user SET password=PASSWORD("newpassword") WHERE user="root";
> FLUSH PRIVILEGES;
> exit

This should change the server’s password. The change will be taken into effect, which you can test, the next time the server is restarted by issuing the following commands:


# service mysqld restart
# mysql -u root -pnewpassword

Compiling MSSQL extension for PHP 4.4.6 on Linux

I had to compile from source the MSSQL extension for PHP 4.4.6. Funny enough, the only way this could work is if I compile the Sybase extension with it. (Otherwise, PHP thinks the MSSQL module is not valid.) The Linux server runs a distribution managed by cPanel.

From the PHP source code directory:


./configure --with-mssql=shared --with-sybase=shared --without-mysql
make build-modules
make install-modules

That should do the trick. Make sure the modules gets copied in the same directory than the extension directory specified in the php.ini file. You can also obtain that directory by typing php-config —extension-dir.

This thread talks about a different issue, but gave me the idea of compiling Sybase at the same time. Without it, trying to load the MSSQL extension was giving me the error below. With the Sybase loaded as well, everything is working great.


Invalid library (maybe not a PHP library) 'mssql.so'

Fix stuck Yum or RPM

Sometimes, Yum or RPM gets stuck when running. It may be caused by a corrupted RPM database. To fix it, do the following:


rm /var/lib/rpm/__db*
rpm --rebuilddb
yum clean all

More info:
http://www.linuxquestions.org/questions/showthread.php?t=512804

Java and Fedora Core 6

I hate Java, but I guess that crap got enough attention to plague the computing world just enough so everybody is forced to install it. And don’t give me the crap about “cross-platform compatibility.” Install an JRE not by Sun and running all your JAR files will go haywire. As rudimentary PHP and Perl may seem to be compared to Java, its cross-platform compatibility is way superior than Java and C#.

Fedora Project Wiki: JavaFAQ
Official Fedora page about running Java on Fedora Core 6 and in Web browsers.
JPackage
Yum and APT repositories with free and proprietary Java RPM packages.
ColdFusion MX 7 on Fedora Core 6
I wrote about my adventure of the ColdFusion MX 7 server installation on Fedora Core 6. I have a few pointers about updating the server’s JRE. Useful for updating the time zones!

ColdFusion MX 7 on Fedora Core 6

Where I work, our extranet is on an external dedicated server. Sometimes we have problems with it. Just sometimes, but enough to get all of us annoyed and let my boss decide to move our extranet on our in-house servers.

We have a Windows and a Linux box. Installation CD’s available are for ColdFusion 4.5, 6, and 7. Our external server is running ColdFusion MX 6.1 on Linux.

I first tried the setup CD for version 7 on our Windows box. The setup routine would get stuck at the Web connector installation step. The cancel button was unavailable, so I just terminated the process using the Task Manager. All the files were installed, so I ran the IIS_Connectors.bat file only to encounter the same problem.

I wanted to read about the problem directly from the server, but somehow Internet Explorer 7 stopped working. Instead of dealing with it, I simply accessed Mozilla’s FTP server via the command line, downloaded Firefox, and installed it. However, the search for information about the problem was all in vain. To make matters worst, the support and search areas of Adobe.com were down for maintenance. We then gave up on installing ColdFusion on Windows.

Time to try on Linux. The installation file on the CD was corrupted, so it was impossible to install from the CD or to copy the file to the hard drive and to run it from there.

Fine! Let’s try the version 6 CD. The installation worked. But when trying to start the ColdFusion server, the libc.so.6 is never found. After reading a page at IBM, I discovered that the CF local installation of the Java Runtime Engine was at fault.

OK… What next?

The “trial” version of software available on the Adobe Web site is actually full unmodified version of their software. If you have the serial number of your software, you can always download a recent copy of it from the Adobe Web site and install the full version using your serial number.

So, I uninstalled ColdFusion MX 6 and decided to install ColdFusion MX 7 on our Linux box. However, when trying to run the installation file, I still get an error message about libc.so.6 not being found! Obviously, with my little patience, it was starting to irritate me…

Luckily, someone by the name of Steven Erat encountered the exact same problem in the same environment. Kudos to him. With his guide, I was able to install ColdFusion successfully. I recommend you follow all of his instructions as close as you can. I promise you — it will save you a lot of time and head scratching at the end.

However, the ColdFusion HTTP server somehow got setup to listen on port 8501 instead of the default 8500. After doing a quick grep, I found out that the port number is indicated in two files in /opt/coldfusionmx7: uninstall/installvariables.properties and runtime/servers/coldfusion/SERVER-INF/jrun.xml. I just used a text editor to replace every instances of 8501 to 8500. After restarted the ColdFusion server using service coldfusionmx7 restart, the server was working fine on port 8500 as it should.

When it was time to access the ColdFusion Administrator and the configure the server, the login page wouldn’t take the password I’ve specified during the installation procedure. A bug, or maybe I just forgot what I wrote. Either way, no problem. I found instructions on how to change the password of both the server and the RDS.

The ColdFusion MX 7 server now works on Apache. I just needed to tweak the configuration a bit after having applied the Apache 2.2 hotfix for ColdFusion (as Steven described) and installed the Apache connector. By personal preference, I’ve moved the ColdFusion configuration in /etc/httpd/conf/httpd.conf to its own file in /etc/httpd/conf.d/coldfusion.conf. The Administrator was working fine, but the images were not loaded. I simply added the following line to the ColdFusion configuration in Apache and restarted the Web server:


# Below this line:

# Add the following:
Alias /CFIDE/ "/opt/coldfusionmx7/wwwroot/CFIDE/"

Apache is now working hand-in-hand with ColdFusion. The last thing to configure to work with ColdFusion was MySQL. I found a page on how to setup MySQL 4 for ColdFusion MX 7 (mirror) both on Windows and Linux. Our server has MySQL 5, but the same instructions applied.

Finally, everything works fine!

Updating time zones information

in

With the changes to the time zones starting this year, I had to update my Web server’s time zone informations to change the time accordingly at the correct moment. To do so, I’ve performed this command:


yum -y install tzdata

More information: http://andrew.triumf.ca/dst.html

Recommended Firefox extensions

Here are my favourite extensions, in alphabetical order, for Firefox which I recommend to anyone who, like me, is learning Japanese, or building Web sites, or to anyone just browsing the Web everyday!

ColorZilla
Adds a colour-picker button to the status bar of Firefox. With that, you can get the colour of any pixel on any Web page. You can also copy the colour code in different formats into the clipboard.
Firebug
The perfect helper for any Web developer. Check any errors in your pages codes and scripts. Browse through your DOM and modify any HTML tag or CSS rule on the fly. Run bits of JavaScript from the console. This extension is a great replacement to the DOM Inspector, and complements well the Web Developer Toolbar mentioned below.

The Google Toolbar not only allows you to search quickly with the famous search engine, but also has tons of buttons you can choose from to access their other services, including Gmail. You can also share bookmarks across any browsers with the extension installed. If you don’t have Firefox installed, Google offers a version of Firefox bundled with the toolbar. If you already have Firefox, you can follow the same above and just download the toolbar.
Greasemonkey
This enables you to download scripts from a wide collection of them, which can modify the behaviour of one or all the Web sites to your liking. For example, removing advertisement in Hotmail, or saves videos from YouTube and Google Video to your hard disk.
MeasureIt
Gives you a ruler you can use to measure the width and height of anything on a Web page. Useful for visual designers who wants their layout to be pixel-perfect!
Moji
Adds a Japanese-English dictionary sidebar to the browser and options in the context menu to lookup the selected word or kanji with it. Sadly, like PeraPera-kun, mentioned below, there’s no English-Japanese functionality.
PeraPera-kun
A modified version of the RikaiChan add-on with more features, it will pop-up the definition of every Japanese word your mouse hovers. A bit like the Web site PopJisyo, which you can use with any browser. Requires the RikaiChan dictionaries. (I got the name of this extension confused with the ParaPara dance.)
Web Developer Toolbar
Gives you a toolbars with a set of features to help Web developer diagnose Web sites. Including a list of files loaded, disabling CSS, outlining certain elements, display link information, or show passwords, for example. Once installed, don’t forget to click View / Toolbars / Web Developer Toolbars in the menu to see it.
XHTML Ruby Support
Some Japanese Web pages include furigana readings for the words written with kanji. The display is accomplished with special ruby tags in HTML. They’ve usually appear inline in Firefox, but they’ll be displayed correctly on top of the words in Internet Explorer. This extension is to add support for ruby tags in Firefox.
XPather
Adds an XPath field to the DOM Inspector where a path is generated for you when you click on any items in the DOM element list. You can also insert your own expression and see what it will return.

Wipping a hard drive clean

in

I bought a hard drive enclosure, because I’m planning to take hard drives on the go soon. The other purpose was to be able to wipe my old hard drives clean before selling them. I want to make sure there’s absolutely no data left on the drive.

I issued the following command to try to do so:


# dd if=/dev/zero of=/dev/sda bs=1M

The path /dev/sda leads to the external hard drive I want to wipe. The problem with that command is it only goes up to 2GB. It’s enough to make sure there’s no partition information left on the device, but there’s still data on it. That’s what I want to get rid of.

What made it work was the following command:


# shred -vz -n 0 /dev/sda

It takes a while. In fact, it may take up an entire day. I’ve specified -n 0 because by default, shred performs more than 20 swipes. If just one swipe of zeroes takes a day, you can imagine with 20…

Background image