Topic: Rails, Apache2, Passenger, and MySQL on Fedora Core

Hi Everyone,

So I did a tutorial about getting a Rails based Ubuntu web server going before. And since I've been asked directly or indirectly how to do it on a Red Hat based system, mostly Fedora Core, I thought I'd put one together for FC. So here it is! big_smile

I had to do a little digging, but wasn't too bad.

Ok, so same rules apply anything inside code brackets you type

Type this stuff

I am on Fedora Core 12 at the moment, the most recent version of the distro. I would imagine this should work on FC10+, but I'm not sure. This is the first time I've used Fedora since FC3...

As always, let's make sure our system is up to date.

su root
<type root password>
yum update

Before we do anything else, let's install all the necessary binaries to make it work.

yum install mysql-devel httpd-devel apr-devel -y

Next let's make sure Ruby is installed.

ruby -v

If not, let's install it.

yum install ruby -y

If it is, move on. Next we want to download the most current RubyGems and install it. As of now, the most current is 1.3.5.

wget http://rubyforge.org/frs/download.php/60718/rubygems-1.3.5.tgz

Next, let's extract the tarball.

tar -xvf rubygems-1.3.5.tgz

Now let's go into the directory

cd rubygems-1.3.5

Run the install Ruby script.

ruby setup.rb

Now let's install Rails.

gem install rails

Now I am going to make the assumption here that you installed Apache, and MySQL during the initial Fedora Core setup. If not, you can install them now by running:

yum install httpd mysql-server -y

Ok, so now with that done, let's install the MySQL gem.

gem install mysql

Next, let's install Passenger.

gem install passenger

Now let's run the Passenger Apache Module Install.

passenger-install-apache2-module

As always, that will take a moment.

Ok, now copy the lines output from that Passenger install script into /etc/httpd/httpd.conf. To keep it organized since FC still uses the original httpd.conf format, you'll want to search for LoadModule in vi.

vi /etc/httpd/conf/httpd.conf
/ LoadModule

Now go to the bottom of that section, and paste those lines.

I
[Right cilck and paste]
ESC
:w
:q

Now let's make sure MySQL is started.

/etc/init.d/mysqld start

Now let's open a new tab in the Terminal, and create a rails site (we'll want the tab still running as root in a moment).

rails myapp -d mysql

And now let's go into our rails app's root folder.

cd myapp

And let's generate a quick controller.

script/generate controller hello index

And being the nature of the beast of rails whether you actually plan on using a db or not, you still need one. So let's create it.

rake db:create

And now let's fire up Mongrel or WEBrick and see our page.

script/server

And point your browser to http://localhost:3000/hello.

You should see #Hello. So that's all great. Now let's finish this by setting up the VirtualHost. Go back to our tab running as root.

Now let's open the httpd.conf in vi again, and go down the to the bottom.

vi /etc/httpd/conf/httpd.conf
:$

And let's add a VirtualHost, as since it's using the original structure of Apache, it's not modularized at all as in Ubuntu.

I
<VirtualHost :*80>
   ServerName localhost <or whatever the FQDN is>
   DocumentRoot /home/<username>/myapp/public
</VirtualHost>
ESC
:w
:q

Where <username> is your Linux username.

Ok, now let's restart Apache.

/etc/init.d/httpd restart

Now point your browser to http://localhost/hello. And you should be set.

Now some considerations. SELinux will probably cause issues. I just disable it because it's annoying. If you're not comfortable doing so, you will have to configure a few policies.

If you catch any typo's, or have any questions or concerns, let me know in a reply below. Enjoy! big_smile