{"id":1618,"date":"2011-04-26T11:04:13","date_gmt":"2011-04-26T03:04:13","guid":{"rendered":"http:\/\/hazelong.com\/?p=1618"},"modified":"2011-05-04T16:55:14","modified_gmt":"2011-05-04T08:55:14","slug":"deploying-rails-centos-5-apache","status":"publish","type":"post","link":"https:\/\/musenmaker.com\/hazelong\/?p=1618","title":{"rendered":"Deploying Rails to Centos 5 : Apache"},"content":{"rendered":"<p>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.<\/p>\n<p>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.<\/p>\n<p>In the end, the nice people at <a href=\"http:\/\/ipserverone.com\">IPserverONE<\/a> have to help me reformat the server. Lol. And what&#8217;s more, <a href=\"http:\/\/www.ipserverone.com\/services\/dedicatedServer\/green\">the server<\/a> is sponsored by them just for me to learn rails. Damn I love them.<\/p>\n<p><strong>Deploying Rails to Centos 5<\/strong><\/p>\n<ul>\n<li><strong>You are here!<\/strong><\/li>\n<li><strong><a href=\"http:\/\/hazelong.com\/?p=1622\">Part 2 \/\/ mySQL<\/a><\/strong><\/li>\n<li><strong><a href=\"http:\/\/hazelong.com\/?p=1625\">Part 3 \/\/ Git<\/a><\/strong><\/li>\n<li><strong><a href=\"http:\/\/hazelong.com\/?p=1631\">Part 4 \/\/ Ruby, Gems &amp; Rails<\/a><\/strong><\/li>\n<li><strong><a href=\"http:\/\/hazelong.com\/?p=1634\">Part 5 \/\/ Passenger<\/a><\/strong><\/li>\n<li><strong><a href=\"http:\/\/hazelong.com\/?p=1637\">Part 6 \/\/ Gitosis<\/a><\/strong><\/li>\n<li><strong><a href=\"http:\/\/hazelong.com\/blog\/2011\/05\/04\/deploying-rails-centos-capistrano\/\">Part 7 \/\/ Capistrano <\/a><\/strong><\/li>\n<\/ul>\n<p>First you need ssh access to the remote server. Then pop up your shell, terminal or <a href=\"www.chiark.greenend.org.uk\/~sgtatham\/putty\">PuTTy<\/a> 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]<\/p>\n<p>By the way, I am running all this from my Mac Terminal fyi. :p<br \/>\nEnter the password as prompted and when you are in, check if apache is available by running: [shell] httpd [\/shell] if it says &#8220;no command found&#8221;, then installing apache is a good idea. \ud83d\ude42<\/p>\n<p>[shell]yum install httpd mod_ssl[\/shell]<\/p>\n<p>When it is done installing, make sure to make apache start on boot.[shell]chkconfig &#8211;levels 235 httpd on[\/shell]<\/p>\n<p>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 <code>httpd.conf<\/code> file by doing so: [shell] locate httpd.conf[\/shell] Then you can replace the path with the previous command.<\/p>\n<p>Now you should have accessed the <code>httpd.conf<\/code> file. You can use arrows to scroll up and down and read the file etc.<br \/>\nReplace 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.<br \/>\n[shell]Timeout 30<br \/>\nKeepAlive On<br \/>\nMaxKeepAliveRequests 500<br \/>\nKeepAliveTimeout 3<br \/>\nListen 80<br \/>\nServerAdmin webmaster@yourdomain.com<br \/>\nServerName domain.com:80<\/p>\n<p>Options FollowSymLinks<br \/>\nAllowOverride None<br \/>\nOrder deny, allow<br \/>\nDeny from all<\/p>\n<p>Options -Indexes +FollowSymLinks +MultiViews +Includes<br \/>\nDirectoryIndex index.html index.html.var index.shtml index.html.erb<br \/>\nOrder allow,deny<br \/>\nDeny from all<\/p>\n<p>Order allow,deny<br \/>\nDeny from all<br \/>\nOrder allow,deny<br \/>\nDeny from all<br \/>\nOrder allow,deny<br \/>\nDeny from all<br \/>\nOrder allow,deny<br \/>\nDeny from all<br \/>\nOrder allow,deny<br \/>\nDeny from all<\/p>\n<p>[\/shell]<\/p>\n<p>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&#8217;t pointing to it yet, you would have to tinker with your domain&#8217;s DNS settings.<\/p>\n<p>In the same file, type the following when you have located the chunk that you need to replace\/type:<br \/>\n[shell] NameVirtualHost 111.111.111.111:80<\/p>\n<p>ServerAdmin webmaster@localhost<br \/>\nAliasMatch ^\/~([^\/]+)(\/.*)* \/home\/$1\/public$2<br \/>\nDocumentRoot \/var\/www\/html\/<br \/>\nServerName localhost<br \/>\n[\/shell]<\/p>\n<p>Now you are ready to add in your domains right below the chunk of code above in your config file.<br \/>\n[shell]<\/p>\n<p>ServerName www.yourdomain.com<br \/>\nServerAlias yourdomain.com www.yourdomain.com<br \/>\nServerAdmin webmaster@yourdomain.com<br \/>\nDocumentRoot \/home\/yourdomain\/public<\/p>\n<p>Options -Indexes FollowSymLinks MultiViews Includes<br \/>\nAllowOverride All<br \/>\nOrder allow,deny<br \/>\nAllow from all<\/p>\n<p>[\/shell]<\/p>\n<p>If you have multiple domains you can use the same code above for the other domains.<br \/>\nYou are done configuring Apache! Hit Esc to get out of editing mode and Shift+Z twice to exit vim.<\/p>\n<p>To make things happen, you need to create the directories first. Create all the directories for your domains like so: [shell] mkdir \/home\/yourdomain\/<br \/>\nmkdir \/home\/yourdomain\/public[\/shell]<br \/>\nRepeat for all domains.<\/p>\n<p>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.<\/p>\n<p>To do that, either one of these commands should work [shell] \/usr\/sbin\/apachectl -k start<br \/>\nhttpd -k start[\/shell]<\/p>\n<p>Now go to your browser and type one of the domains in and see if you are greeted by Centos Apache&#8217;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.<\/p>\n<p>If so, you can try if this works [shell] iptables -A RH-Firewall-1-INPUT -m state &#8211;state NEW -m tcp -p tcp &#8211;dport 80 -j ACCEPT [\/shell]<\/p>\n<p>Save the new iptables configuration [shell]\/etc\/init.d\/iptables restart[\/shell]<\/p>\n<p>Now, restart your apache by doing [shell] httpd -k restart [\/shell]<\/p>\n<p>It should work \ud83d\ude42<\/p>\n<p><strong>Next : mySQL<\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>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&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1776],"tags":[1840,1845,1836,1841,1844,1843,1788,1842],"class_list":["post-1618","post","type-post","status-publish","format-standard","hentry","category-coding-tutorials","tag-apache","tag-capistrano","tag-centos","tag-git","tag-gitosis","tag-passenger","tag-rails","tag-ruby"],"acf":[],"_links":{"self":[{"href":"https:\/\/musenmaker.com\/hazelong\/index.php?rest_route=\/wp\/v2\/posts\/1618","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/musenmaker.com\/hazelong\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/musenmaker.com\/hazelong\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/musenmaker.com\/hazelong\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/musenmaker.com\/hazelong\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1618"}],"version-history":[{"count":0,"href":"https:\/\/musenmaker.com\/hazelong\/index.php?rest_route=\/wp\/v2\/posts\/1618\/revisions"}],"wp:attachment":[{"href":"https:\/\/musenmaker.com\/hazelong\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1618"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/musenmaker.com\/hazelong\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1618"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/musenmaker.com\/hazelong\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1618"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}