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

First you need ssh access to the remote server. Then pop up your shell, terminal or PuTTy if you are on windows and type [shell] ssh root@111.111.111.111 [/shell] or if your server admin specifically tell you the port to ssh in, you could do this : [shell] ssh root@111.111.111.111 -p 1234 [/shell]

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: [shell] httpd [/shell] if it says “no command found”, then installing apache is a good idea. 🙂

[shell]yum install httpd mod_ssl[/shell]

When it is done installing, make sure to make apache start on boot.[shell]chkconfig –levels 235 httpd on[/shell]

Now, you are going to have to configure apache by editing the configuration file thru the terminal using the vim command. [shell] vim /etc/httpd/conf/httpd.conf[/shell] 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: [shell] locate httpd.conf[/shell] 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.
[shell]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

[/shell]

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:
[shell] NameVirtualHost 111.111.111.111:80

ServerAdmin webmaster@localhost
AliasMatch ^/~([^/]+)(/.*)* /home/$1/public$2
DocumentRoot /var/www/html/
ServerName localhost
[/shell]

Now you are ready to add in your domains right below the chunk of code above in your config file.
[shell]

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

[/shell]

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: [shell] mkdir /home/yourdomain/
mkdir /home/yourdomain/public[/shell]
Repeat for all domains.

Now you need to start up Apache. But before you do that run: [shell] httpd[/shell] and see if it shoots up any syntax errors. Ammend them first before proceeding.

To do that, either one of these commands should work [shell] /usr/sbin/apachectl -k start
httpd -k start[/shell]

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 [shell] iptables -A RH-Firewall-1-INPUT -m state –state NEW -m tcp -p tcp –dport 80 -j ACCEPT [/shell]

Save the new iptables configuration [shell]/etc/init.d/iptables restart[/shell]

Now, restart your apache by doing [shell] httpd -k restart [/shell]

It should work 🙂

Next : mySQL