Deploying Rails to Centos 5 : Apache
This is part one of another series. I sorta lost my shell history so I figured I might as well blog it out so that I can has a reference next time.
Bear in mind that I started out with the ambition of configuring an existing Apache, PHP, mySQL, DirectAdmin running on a Centos 5.5 machine to work with rails deployment. Not a surprise, but I failed badly and managed to wreck a few working websites.
In the end, the nice people at IPserverONE have to help me reformat the server. Lol. And what’s more, the server is sponsored by them just for me to learn rails. Damn I love them.
Deploying Rails to Centos 5
- You are here!
- Part 2 // mySQL
- Part 3 // Git
- Part 4 // Ruby, Gems & Rails
- Part 5 // Passenger
- Part 6 // Gitosis
- Part 7 // Capistrano
First you need ssh access to the remote server. Then pop up your shell, terminal or PuTTy if you are on windows and type
ssh root@111.111.111.111
or if your server admin specifically tell you the port to ssh in, you could do this :
ssh root@111.111.111.111 -p 1234
By the way, I am running all this from my Mac Terminal fyi. :p
Enter the password as prompted and when you are in, check if apache is available by running:
httpd
if it says “no command found”, then installing apache is a good idea.
yum install httpd mod_ssl
When it is done installing, make sure to make apache start on boot.
chkconfig --levels 235 httpd on
Now, you are going to have to configure apache by editing the configuration file thru the terminal using the vim command.
vim /etc/httpd/conf/httpd.conf
If by doing this shoots you some error of not being able to find a file, you can locate the httpd.conf file by doing so:
locate httpd.conf
Then you can replace the path with the previous command.
Now you should have accessed the httpd.conf file. You can use arrows to scroll up and down and read the file etc.
Replace the values with the ones below once you can locate them. If they are commented out(has a # just before the line) remove the #. To start editing the file, hit i on your keyboard.
Timeout 30 KeepAlive On MaxKeepAliveRequests 500 KeepAliveTimeout 3 Listen 80 ServerAdmin webmaster@yourdomain.com ServerName domain.com:80 Options FollowSymLinks AllowOverride None Order deny, allow Deny from all Options -Indexes +FollowSymLinks +MultiViews +Includes DirectoryIndex index.html index.html.var index.shtml index.html.erb Order allow,deny Deny from all Order allow,deny Deny from all Order allow,deny Deny from all Order allow,deny Deny from all Order allow,deny Deny from all Order allow,deny Deny from all
Now you have to do some domain tying up. Your domain should be pointing to your ip address, in this example 111.111.111.111. If it isn’t pointing to it yet, you would have to tinker with your domain’s DNS settings.
In the same file, type the following when you have located the chunk that you need to replace/type:
NameVirtualHost 111.111.111.111:80 ServerAdmin webmaster@localhost AliasMatch ^/~([^/]+)(/.*)* /home/$1/public$2 DocumentRoot /var/www/html/ ServerName localhost
Now you are ready to add in your domains right below the chunk of code above in your config file.
ServerName www.yourdomain.com ServerAlias yourdomain.com www.yourdomain.com ServerAdmin webmaster@yourdomain.com DocumentRoot /home/yourdomain/public Options -Indexes FollowSymLinks MultiViews Includes AllowOverride All Order allow,deny Allow from all
If you have multiple domains you can use the same code above for the other domains.
You are done configuring Apache! Hit Esc to get out of editing mode and Shift+Z twice to exit vim.
To make things happen, you need to create the directories first. Create all the directories for your domains like so:
mkdir /home/yourdomain/ mkdir /home/yourdomain/public
Repeat for all domains.
Now you need to start up Apache. But before you do that run:
httpd
and see if it shoots up any syntax errors. Ammend them first before proceeding.
To do that, either one of these commands should work
/usr/sbin/apachectl -k start httpd -k start
Now go to your browser and type one of the domains in and see if you are greeted by Centos Apache’s introduction page. If the domain does not show any sign of Apache like mine then it is probably Centos firewall ipTables that is blocking the port.
If so, you can try if this works
iptables -A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
Save the new iptables configuration
/etc/init.d/iptables restart
Now, restart your apache by doing
httpd -k restart
It should work
Next : mySQL









If you liked my post, please leave a comment. Your comments encourage me to keep on blogging about my art, photography and makeup.