<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Gilluminate &#187; MySQL</title>
	<atom:link href="http://www.gilluminate.com/tag/mysql/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.gilluminate.com</link>
	<description>By Jason Gill</description>
	<lastBuildDate>Sat, 28 Jan 2012 21:01:18 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
		<item>
		<title>WestHost on Rails 2007 (for cheapskates)</title>
		<link>http://www.gilluminate.com/2007/07/24/westhost-on-rails-2007-for-cheapskates/</link>
		<comments>http://www.gilluminate.com/2007/07/24/westhost-on-rails-2007-for-cheapskates/#comments</comments>
		<pubDate>Tue, 24 Jul 2007 15:35:00 +0000</pubDate>
		<dc:creator>Jason Gill</dc:creator>
				<category><![CDATA[Developer Blog]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[WestHost]]></category>

		<guid isPermaLink="false">http://blog.gillumiante.com/2007/07/24/westhost-on-rails-2007-for-cheapskates</guid>
		<description><![CDATA[By Aaron Gustafson. Updated by Jason Gill While it is true that WestHost now offers Ruby on Rails, it&#8217;s only available on some of the packages and not all. If you are a cheapskate like me and want to add Ruby on Rails to the Personal Starter plan where RoR isn&#8217;t available, this tutorial is [...]]]></description>
			<content:encoded><![CDATA[<h3>By Aaron Gustafson. Updated by Jason Gill</h3>
<p>While it is true that <a href="http://affiliates.westhost.com/z/14/CD1084/">WestHost</a> now offers <a href="http://rubyonrails.org/">Ruby on Rails</a>, it&#8217;s only available on some of the packages and not all. If you are a cheapskate like me and want to add Ruby on Rails to the Personal Starter plan where RoR isn&#8217;t available, this tutorial is for you! This even works on packages that come with RoR for those of you who are unsatisfied with how limited WestHost&#8217;s install is. I&#8217;ve adapted <a href="http://www.easy-designs.net/articles/WesthostOnRails/">Aaron Gustafson&#8217;s tutorial</a> and updated it to be more relevant, more current, and (hopefully) more helpful for 2007.</p>
<p><strong>The Requisite Disclaimer:</strong> If you are on a different hosting company, I cannot guarantee this tutorial will work for you (though it may be helpful in figuring out your issues). As always, before you make changes to critical files (http.conf, .bashrc, etc.), do yourself a favor and make a backup copy; this tutorial offers assistance, but no warranty, so if you mess something up during the install, you&#8217;re on your own (but Westhost tech support should be helpful). Finally, this tutorial assumes some familiarity with the <em>Site Manager</em> from Westhost and some basic knowledge of the Linux shell. This tutorial uses <a href="http://en.wikipedia.org/wiki/Pico_(text_editor)">pico</a> as a text editor, but <a href="http://en.wikipedia.org/wiki/Vi">vi</a> is also an option and this tutorial assumes familiarity with inline text editors. I prefer <a href="http://en.wikipedia.org/wiki/Emacs">emacs</a>, but it&#8217;s not installed by default on WestHost servers.</p>
<p>Now that I&#8217;ve had to muddle through it a few times, I decided that, for my own sanity and to aid anyone else out there who may be going through the same thing, I would put together a comprehensive tutorial on how to install <a href="http://www.rubyonrails.com/">Ruby on Rails</a> at Westhost. The major problems that arise and could trip you up are</p>
<ol>
<li>Westhost now runs <a href="http://www.apache.org/">Apache 2.0</a></li>
<li><a href="http://www.fastcgi.com/">FastCGI</a> is not an option in some packages (and Rails will run incredibly slow without it), and</li>
<li>you cannot install applications in <em>/usr/bin</em>.</li>
</ol>
<p>This tutorial will get you up and running with a very simple Rails page on your Westhost VPS server using Apache 2.0 with FastCGI. For simplicity&#8217;s sake, I am going to set up the test Rails app on its own hostname (<em>demo.yoursitehere.com</em>).</p>
<h2>Required Site Applications</h2>
<p>Before we get started, log into your <em>Site Manager</em> (it can be found at <em>http://www.yoursitehere.com/manager</em>) and make sure the following are installed:</p>
<ul>
<li>MySQL 5.0.27 – because you&#8217;ll want a database</li>
<li>GNU Compiler Collection 1.0 – because we&#8217;ve got some compiling to do</li>
<li>Perl 5.8.8 – At present I can&#8217;t remember why, but I had problems without this installed.</li>
<li>FastCGI 2.4.0 (If available with your package).</li>
</ul>
<p>Now SSH into your site and we can get started.</p>
<h2>Step 1: Collect &amp; unpack</h2>
<p>First of all, make sure you are in your home directory</p>
<pre>[yourusername][~]$ cd /home/your_username</pre>
<p>or</p>
<pre>[yourusername][~]$ cd ~</pre>
<p>and then we can start the downloading and unpacking. First we get Ruby (the latest is 1.8.6 as of this writing), unpack it, and remove the archive:</p>
<pre>[yourusername][~]$ wget http://rubyforge.org/frs/download.php/18421/ruby-1.8.6.tar.gz
[yourusername][~]$ tar -xvzf ruby-1.8.6.tar.gz
[yourusername][~]$ rm -f ruby-1.8.6.tar.gz</pre>
<p>Next up is the latest Ruby Gem Manager (version 0.9.4 at present)</p>
<pre>[yourusername][~]$ wget http://rubyforge.org/frs/download.php/20989/rubygems-0.9.4.tgz
[yourusername][~]$ tar -xvzf rubygems-0.9.4.tgz
[yourusername][~]$ rm -f rubygems-0.9.4.tgz</pre>
<p>then the latest FastCGI Developer&#8217;s Kit (version 2.4.0 at present)</p>
<pre>[yourusername][~]$ wget http://www.fastcgi.com/dist/fcgi-2.4.0.tar.gz
[yourusername][~]$ tar -xvzf fcgi-2.4.0.tar.gz
[yourusername][~]$ rm -f fcgi-2.4.0.tar.gz</pre>
<p>and, finally, the FastCGI module for Apache (version 2.4.2 at present)</p>
<pre>[yourusername][~]$ wget http://www.fastcgi.com/dist/mod_fastcgi-2.4.2.tar.gz
[yourusername][~]$ tar -xvzf mod_fastcgi-2.4.2.tar.gz
[yourusername][~]$ rm -f mod_fascgi-2.4.2.tar.gz</pre>
<h2>Step 2: Configure &amp; Install Ruby</h2>
<p>Starting in your home directory, get into the Ruby folder</p>
<pre>[yourusername][~]$ cd ruby-1.8.6</pre>
<p>We need to configure the source before we compile, letting it know that Ruby will be installed in <em>/usr/local/ruby</em> instead of <em>/usr/local</em>:</p>
<pre>[yourusername][ruby-1.8.6]$ ./configure --prefix=/usr/local/ruby</pre>
<p>Then go ahead and create the makefile and install Ruby.</p>
<pre>[yourusername][ruby-1.8.6]$ make &amp;&amp; make install</pre>
<p>If you get OpenSSL errors, you can compile without (assuming you don&#8217;t want to use ssl security):</p>
<pre>[yourusername][ruby-1.8.6]$ ./configure --prefix=/usr/local/ruby --without-openssl</pre>
<pre>[yourusername][ruby-1.8.6]$ make &amp;&amp; make install</pre>
<p>As we will be working with Ruby from the command line, we need it as part of our PATH, which means editing our .bashrc file:</p>
<pre>[yourusername][ruby-1.8.6]$ pico /.bashrc</pre>
<p>looking a few lines down from the top, you will see this line</p>
<pre>export PATH="$PATH:/usr/local/apache/bin"</pre>
<p>Change it to read</p>
<pre>export PATH="$PATH:/usr/local/apache/bin:/usr/local/ruby/bin"</pre>
<p>and save as you exit. Make sure your current session is using the new .bashrc file and then check your Ruby version (which will tell us if Ruby is working):</p>
<pre>[yourusername][ruby-1.8.6]$ source /.bashrc
[yourusername][~]$ ruby -v
ruby 1.8.6 (2007-03-13 patchlevel 0) [i686-linux]</pre>
<h2>Step 3: Installing Ruby Gem Manager</h2>
<p>We will be using the Ruby Gem Manager to install pretty much every other Ruby or Rails component we need, so it is next on our list. First of all, enter its folder</p>
<pre>[yourusername][~]$ cd rubygems-0.9.4</pre>
<p>and then install it using Ruby</p>
<pre>[yourusername][rubygems-0.9.4]$ ruby setup.rb</pre>
<p>give gem a test run</p>
<pre>[yourusername][rubygems-0.9.4]$ gem list</pre>
<p>We don&#8217;t have any gems installed yet (other than source), but that&#8217;s what we&#8217;re doing next.</p>
<h2>Step 4: Install Rails</h2>
<p>Now that we have the Gem Manager installed, the rest of the basic stuff is a snap. To install Rails, simply type the following</p>
<pre>[yourusername][rubygems-0.9.4]$ gem install rails --include-dependencies</pre>
<p>If you get the error &#8220;Could not find rails (&gt; 0) in any repository&#8221; you just need to run the following command:</p>
<pre>[yourusername][rubygems-0.9.4]$ rm -f /usr/local/ruby/lib/ruby/gems/1.8/source_cache</pre>
<p>now run</p>
<pre>[yourusername][rubygems-0.9.4]$ gem update</pre>
<p>and run the gem install command again.</p>
<pre>[yourusername][rubygems-0.9.4]$ gem install rails --include-dependencies</pre>
<p>This could take a little while, but should complete within a few minutes.</p>
<p>Now that we&#8217;ve done that, we can test our Rails install:</p>
<pre>[yourusername][rubygems-0.9.4]$ cd /var/www
[yourusername][www]$ rails demo
[yourusername][www]$ cd demo
[yourusername][demo]$ ruby script/server</pre>
<p>Open web browser to <em>http://www.yoursitehere.com:3000/</em> and look what you did. Congratulations, you&#8217;ve put Ruby on Rails!</p>
<h2>Step 5: Getting FastCGI up on Apache 2.0</h2>
<p><em>(If you have a hosting package from WestHost with FastCGI, you can just install it using the manager and skip step 5 altogether. Then again, if you have that package, you can probably install Rails from there also and you aren&#8217;t in need of this tutorial in the first place.)</em></p>
<p>OK, all of that stuff was pretty easy, but know things get just a little more complex. Be warned that it gets very tedious from here on in.</p>
<p>First off, return to your home directory:</p>
<pre>[yourusername][demo]$ cd ~</pre>
<p>We need to install the FastCGI Dev Kit. To do that, enter its directory, configure and install it similarly to how we did Ruby:</p>
<pre>[yourusername][~]$ cd fcgi-2.4.0
[yourusername][fcgi-2.4.0]$ ./configure --prefix=/usr/local/fcgi
[yourusername][fcgi-2.4.0]$ make &amp;&amp; make install</pre>
<p>Next on the agenda is getting Apache2 to understand FastCGI. To do this, we need to compile and install the DSO for Apache, which uses a slightly different process:</p>
<pre>[yourusername][fcgi-2.4.0]$ cd ../mod_fastcgi-2.4.2
[yourusername][mod_fastcgi-2.4.2]$ cp Makefile.AP2 Makefile
[yourusername][mod_fastcgi-2.4.2]$ make top_dir=/usr/lib/httpd
[yourusername][mod_fastcgi-2.4.2]$ make install top_dir=/usr/lib/httpd</pre>
<p>That put FastCGI in Apache&#8217;s modules directory, but not in the config file, so we&#8217;ll need to edit it.</p>
<pre>[yourusername][mod_fastcgi-2.4.2]$ pico /etc/httpd/conf/httpd.conf</pre>
<p>We need add the following in the list of already present modules</p>
<pre>LoadModule fastcgi_module   modules/mod_fastcgi.so</pre>
<p>Finally, create an instance of our demo app near the bottom of the httpd.conf file:</p>
<pre># FastCGI

FastCgiIpcDir /tmp/fcgi_ipc
FastCgiServer /var/www/demo/public/dispatch.fcgi -processes 1 -idle-timeout 60</pre>
<p><strong>Processes:</strong> Why only one process? Well, 1 is usually enough for most applications. If you are getting <em>really heavy</em> traffic, you could bump it up to 2, but FastCGI can be a bit resource hungry. It is even worse if you run multiple FastCGI servers on a single box. For instance, according to a tech at WestHost, 4 server instances running a large number of processes (say 15) each will frequently cause over 400MB of RAM and 1GB of swap to be used on the server, resulting in the cyclic behavior of freeing and reallocating memory. This is <em>very</em> resource intensive and it causes the server&#8217;s load to spike, which is problematic for any other users on the same server (in a VPS situation).</p>
<h2>Step 6: Configuration</h2>
<p>Go into <em>Domain Management</em>, set up a new Sub Domain Name: for your domain using the following values:</p>
<ul>
<li>Sub Domain Name:: <em>demo</em></li>
<li>Root directory for the new sub domain will be: <em>/var/www/demo</em></li>
</ul>
<p>Now configure your virtual host so that</p>
<pre>ServerName demo.mysite.com
ServerAlias www.demo.mysite.com
DocumentRoot /var/www/demo/</pre>
<p>becomes</p>
<pre>ServerName demo.mysite.com
ServerAlias www.demo.mysite.com
DocumentRoot /var/www/demo/public/
ErrorLog /var/www/demo/log/server.log

Options ExecCGI FollowSymLinks
AllowOverride all
Allow from all
Order allow,deny</pre>
<p>Save the file as you exit and then test it to make sure you didn&#8217;t screw anything up before restarting Apache:</p>
<pre>[yourusername][mod_fastcgi-2.4.2]$ apachectl configtest
Syntax OK
[yourusername][mod_fastcgi-2.4.2]$ apachectl restart</pre>
<p>Hang in there, we&#8217;re almost done. To set up Rails to use FastCGI, we need to edit the .htaccess file in your public folder:</p>
<pre>[yourusername][mod_fastcgi-2.4.2]$ pico /var/www/demo/public/.htaccess</pre>
<p>In that file, change</p>
<pre>RewriteRule ^(.*)$ dispatch.cgi [QSA,L]</pre>
<p>to read</p>
<pre>RewriteRule ^(.*)$ &lt;strong&gt;dispatch.fcgi&lt;/strong&gt; [QSA,L]</pre>
<p>Then save when you exit.</p>
<p>Finally, we need to set up the Ruby-FastCGI Gem</p>
<pre>[yourusername][mod_fastcgi-2.4.2]$ gem install fcgi --with-fcgi-dir=/usr/local/fcgi</pre>
<h2>Step 7: Let&#8217;s get rolling</h2>
<p>Finally we are in a position to test our install. To do so, we&#8217;ll add a simple controller to our demo Rails install. We start by moving into the demo folder</p>
<pre>[yourusername][mod_fastcgi-2.4.2]$ cd /var/www/demo</pre>
<p>and then we use the Generator to make us a controller:</p>
<pre>[yourusername][demo]$ ruby script/generate controller Say</pre>
<p>That doesn&#8217;t do a whole lot since we have no actions. Let&#8217;s define an empty one:</p>
<pre>[yourusername][demo]$ pico app/controllers/say_controller.rb</pre>
<p>Edit the file to read</p>
<pre>class SayController &lt; ApplicationController
def hello
end
end</pre>
<p>and save as you exit.</p>
<p>Now that&#8217;s all well and good, but we get an error if we try to surf to <em>http://demo.yoursitehere.com/say/hello</em> because there is no view associated with it. That&#8217;s easy enough to remedy, we&#8217;ll create one.</p>
<pre>[yourusername][demo]$ pico app/views/say/hello.rhtml</pre>
<p>Type out something simple, such as</p>
<pre>Hello World</pre>
<h1>Hello from Rails!</h1>
<p>The current time is</p>
<p>and then revisit <em>http://demo.yoursitehere.com/say/hello</em>. Now you&#8217;re rolling. Good luck and enjoy.</p>
<h2>Step 8 : What? You want MySQL?</h2>
<p>Okay, so you want to hook up Rails to your MySQL database now. To do this, there&#8217;s a few hoops you need to jump though. First of all, you&#8217;ll need to edit your database configuration file.</p>
<pre>[yourusername][demo]$ pico config/database.yml</pre>
<p>Fill in your database names for the development, test and production environments and the username and password for each. Then add the socket path:</p>
<pre>development:

adapter: mysql
socket: /var/lib/mysql/mysql.sock
database: your_development_db
host: localhost
username: root
password: your_password

# Warning: The database defined as 'test' will be erased and
# re-generated from your development database when you run 'rake'.
# Do not set this db to the same as development or production.

test:

adapter: mysql
socket: /var/lib/mysql/mysql.sock
database: your_test_db
host: localhost
username: root
password: your_password

production:

adapter: mysql
socket: /var/lib/mysql/mysql.sock
database: your_production_db
host: localhost
username: root
password: your_password</pre>
<p>and save as you exit. Without the socket information, Rails will never find MySQL, which sucks.</p>
<p>(This information licensed under a <a href="http://creativecommons.org/licenses/by-sa/3.0/">Creative Commons</a> License.)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.gilluminate.com/2007/07/24/westhost-on-rails-2007-for-cheapskates/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>MySQL 4.1.x and formatting the new TIMESTAMP with PHP</title>
		<link>http://www.gilluminate.com/2005/07/11/mysql-4-1-x-and-formatting-the-new-timestamp-with-php/</link>
		<comments>http://www.gilluminate.com/2005/07/11/mysql-4-1-x-and-formatting-the-new-timestamp-with-php/#comments</comments>
		<pubDate>Mon, 11 Jul 2005 15:00:00 +0000</pubDate>
		<dc:creator>Jason Gill</dc:creator>
				<category><![CDATA[Developer Blog]]></category>
		<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://blog.gillumiante.com/2005/07/11/mysql-4-1-x-and-formatting-the-new-timestamp-with-php</guid>
		<description><![CDATA[In MySQL 4.1 and up, the properties of the TIMESTAMP column type change from YYYYMMDDHHMMSS to YYYY-MM-DD HH:MM:SS. If you have built anything in PHP that relies on the old format, it will break if you upgrade from older versions of MySQL (such as this blog!). If you want the same view of a timestamp [...]]]></description>
			<content:encoded><![CDATA[<p>In MySQL 4.1 and up, the properties of the <a href="http://dev.mysql.com/doc/mysql/en/timestamp-4-1.html">TIMESTAMP</a> column type change from <strong>YYYYMMDDHHMMSS</strong> to <strong>YYYY-MM-DD HH:MM:SS</strong>. If you have built anything in PHP that relies on the old format, it will break if you <a href="http://dev.mysql.com/doc/mysql/en/upgrading-from-4-0.html">upgrade from older versions of MySQL</a> (such as this blog!).<br />
If you want the same view of a timestamp field in 4.1.x as it was in in earlier mysql versions, you can add a &#8220;+ 0&#8243; to the column name.</p>
<pre>SELECT ts_col + 0 FROM tbl_name;</pre>
<p>That much has at least been documented and can be found after a quick <a href="http://www.google.com/search?q=mysql+4.1+timestamp">google search</a>. However, getting the earlier format to appear in PHP is undocumented as far as I can tell. You might just guess that you nees to use the exact same sql statement, and you&#8217;d be right for the most part:</p>
<pre>$result = mysql_query("SELECT ts_col + 0 FROM tbl_name");
$row = mysql_fetch_array($result);</pre>
<p>But what took some trial and error to figure out for myself, was that you then have to use the &#8220;+ 0&#8243; again when you refer to that column as such:</p>
<pre>$date = $row['tbl_name + 0'];</pre>
<p>I haven&#8217;t figured out how to get the date formatted yet when doing a wildcard query like this:</p>
<pre>SELECT * + 0 FROM tbl_name;</pre>
<p>so if you know how to do that please leave a comment here.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.gilluminate.com/2005/07/11/mysql-4-1-x-and-formatting-the-new-timestamp-with-php/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>

