<?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>Phillip Napieralski &#187; Shared hosting</title>
	<atom:link href="http://blog.pnapieralski.com/category/shared-hosting/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.pnapieralski.com</link>
	<description>Programmer, Engineer, Researcher.</description>
	<lastBuildDate>Tue, 20 Dec 2011 16:41: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>
		<item>
		<title>How to Setup MongoDB PHP Extension on Shared Hosting</title>
		<link>http://blog.pnapieralski.com/mongodb/how-to-setup-mongodb-php-extension-on-shared-hosting/</link>
		<comments>http://blog.pnapieralski.com/mongodb/how-to-setup-mongodb-php-extension-on-shared-hosting/#comments</comments>
		<pubDate>Wed, 07 Jul 2010 21:38:04 +0000</pubDate>
		<dc:creator>Phillip Napieralski</dc:creator>
				<category><![CDATA[MongoDB]]></category>
		<category><![CDATA[Shared hosting]]></category>
		<category><![CDATA[Dreamhost]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[PHP Extensions]]></category>

		<guid isPermaLink="false">http://blog.pnapieralski.com/?p=57</guid>
		<description><![CDATA[Want to use MongoDB but don't want to switch to a more expensive hosting plan? This is a great alternative that I got working on Dreamhost in less than an hour!]]></description>
			<content:encoded><![CDATA[<p>Want to use MongoDB but don&#8217;t want to switch to a more expensive hosting plan? This is a great alternative that I got working on Dreamhost in less than an hour!</p>
<h2>Setup your external MongoDB</h2>
<p>I use <a href="https://mongohq.com/home">MongoHQ</a> to host my database (your first 16MB database is free). Make sure to take note of your connection string for later.</p>
<h2>Custom PHP.ini</h2>
<p>This part is somewhat tricky. Luckily, if you are using dreamhost, it is well documented on <a href="http://wiki.dreamhost.com/index.php/PHP.ini#Custom_php.ini_for_a_Single_domain">their wiki</a>. Thus, I won&#8217;t go into detail of that here. Follow the directions and proceed to the next step (or leave a comment asking for help if you have issues).</p>
<p>After setting up your custom ini file for your domain, add the following lines to the very end of your php.ini:</p>
<pre class="brush: php; title: ; notranslate">
extension_dir = &quot;/home/YOUR_USERNAME/bin&quot;
extension = mongo.so
</pre>
<p><strong>NOTE:</strong> This step loads the MongoDB extension but, we don&#8217;t have it yet! The next steps will fix that.</p>
<h2>Compile MongoDB: Part 1</h2>
<p>Using SSH, cd into your home folder (/home/YOUR_USERNAME) and type the following:</p>
<pre class="brush: bash; title: ; notranslate">
mkdir bin
cd bin/
wget http://download.github.com/mongodb-mongo-php-driver-1.0.6-0-gd261d7a.tar.gz
tar zxvf mongodb-mongo-php-driver-1.0.6-0-gd261d7a.tar.gz
cd mongodb-mongo-php-driver-gd261d7a/
phpize
</pre>
<p>If you receive the error <em>Cannot find autoconf</em> after running the command <em>phpize</em>, follow the next section. Otherwise, skip it!</p>
<h2>Compile/install autoconf</h2>
<pre class="brush: bash; title: ; notranslate">
wget http://ftp.gnu.org/gnu/autoconf/autoconf-2.66.tar.gz
tar -zvxf autoconf-2.66.tar.gz
cd autoconf-2.66/
./configure &quot;--prefix=$HOME&quot;
make
make install
</pre>
<p>The <em>configure</em> line will tell <em>make install</em> to put the library (.so) file into our home/bin directory (eg, /home/YOUR_USERNAME/bin). Quickly check that you have a few autoconf folders in your bin directory and continue on.</p>
<p><strong>IMPORTANT:</strong> You must now tell linux to look for libraries in your home/bin directory. To do this, you must change the PATH as follows:</p>
<pre class="brush: bash; title: ; notranslate">
EXPORT PATH=$HOME/bin:$PATH
</pre>
<h2>Compile MongoDB: Part 2</h2>
<p>Remember that <em>phpize</em> function? Yea, try it again:</p>
<pre class="brush: bash; title: ; notranslate">
cd $HOME/bin/mongodb-mongo-php-driver-gd261d7a/
phpize
</pre>
<p>This time, you should not receive an autoconf error. Now, we actually compile the extension.</p>
<pre class="brush: bash; title: ; notranslate">
./configure &quot;--prefix=$HOME&quot;
make
</pre>
<p>And, for some reason, the <em>make install</em> commands ignores our prefix&#8230; so we can just manually copy the needed (.so) file to our bin folder:</p>
<pre class="brush: bash; title: ; notranslate">
cp modules/mongo.so $HOME/bin/
</pre>
<p>Now double check that Mongo.so exists in your home/bin directory (eg, /home/YOUR_USERNAME/bin/mongo.so)</p>
<h2>Test it</h2>
<p>Now, here&#8217;s a simple script to test if you can insert something into your external Mongo database.</p>
<pre class="brush: php; title: ; notranslate">
&lt;?php
   $m = new Mongo(&quot;mongodb://YOUR_USERNAME:YOUR_PASSWORD@YOUR_SERVER:27046/YOUR_DATABASE&quot;);
   $m-&gt;connect();
   $db = $m-&gt;YOUR_DATABASE
   $collection = $db-&gt;YOUR_COLLECTION;

   $collection-&gt;insert(array('name' =&gt; 'super test 5000'));
</pre>
<p>There! You should have just inserted a new record into your database collection. Test by changing the insert line to the following:</p>
<pre class="brush: php; title: ; notranslate">
$cursor = $collection-&gt;find();

echo $cursor-&gt;count() . ' documents found. &lt;br/&gt;';
foreach ($cursor as $obj) {
   var_dump($obj);
   echo '&lt;br/&gt;';
}
</pre>
<p>Now when you run that last script, you should see at least the one record you JUST added! </p>
<h2>Conclusion</h2>
<p>This is the approach I am currently using for one of my smaller pet projects. I&#8217;m going to be doing a lot of testing on my local machine using XAMPP, then going live with it using Dreamhost. It is also unfortunate that I&#8217;m forced to use an external DB. But, considering the first 16MB of database from MongoHQ is free, I&#8217;m totally satisfied with this for now.</p>


<div class="shr-bookmarks shr-bookmarks-expand shr-bookmarks-center">
<ul class="socials">
		<li class="shr-twitter">
			<a href="http://www.shareaholic.com/api/share/?title=How+to+Setup+MongoDB+PHP+Extension+on+Shared+Hosting&amp;link=http://blog.pnapieralski.com/mongodb/how-to-setup-mongodb-php-extension-on-shared-hosting/&amp;notes=Want%20to%20use%20MongoDB%20but%20don%27t%20want%20to%20switch%20to%20a%20more%20expensive%20hosting%20plan%3F%20This%20is%20a%20great%20alternative%20that%20I%20got%20working%20on%20Dreamhost%20in%20less%20than%20an%20hour%21&amp;short_link=&amp;shortener=google&amp;shortener_key=&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=%2524%257Btitle%257D%2B-%2B%2524%257Bshort_link%257D&amp;service=7&amp;tags=&amp;ctype=" rel="nofollow" class="external" title="Tweet This!">Tweet This!</a>
		</li>
		<li class="shr-digg">
			<a href="http://www.shareaholic.com/api/share/?title=How+to+Setup+MongoDB+PHP+Extension+on+Shared+Hosting&amp;link=http://blog.pnapieralski.com/mongodb/how-to-setup-mongodb-php-extension-on-shared-hosting/&amp;notes=Want%20to%20use%20MongoDB%20but%20don%27t%20want%20to%20switch%20to%20a%20more%20expensive%20hosting%20plan%3F%20This%20is%20a%20great%20alternative%20that%20I%20got%20working%20on%20Dreamhost%20in%20less%20than%20an%20hour%21&amp;short_link=&amp;shortener=google&amp;shortener_key=&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=&amp;service=3&amp;tags=&amp;ctype=" rel="nofollow" class="external" title="Digg this!">Digg this!</a>
		</li>
		<li class="shr-reddit">
			<a href="http://www.shareaholic.com/api/share/?title=How+to+Setup+MongoDB+PHP+Extension+on+Shared+Hosting&amp;link=http://blog.pnapieralski.com/mongodb/how-to-setup-mongodb-php-extension-on-shared-hosting/&amp;notes=Want%20to%20use%20MongoDB%20but%20don%27t%20want%20to%20switch%20to%20a%20more%20expensive%20hosting%20plan%3F%20This%20is%20a%20great%20alternative%20that%20I%20got%20working%20on%20Dreamhost%20in%20less%20than%20an%20hour%21&amp;short_link=&amp;shortener=google&amp;shortener_key=&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=&amp;service=40&amp;tags=&amp;ctype=" rel="nofollow" class="external" title="Share this on Reddit">Share this on Reddit</a>
		</li>
		<li class="shr-technorati">
			<a href="http://www.shareaholic.com/api/share/?title=How+to+Setup+MongoDB+PHP+Extension+on+Shared+Hosting&amp;link=http://blog.pnapieralski.com/mongodb/how-to-setup-mongodb-php-extension-on-shared-hosting/&amp;notes=Want%20to%20use%20MongoDB%20but%20don%27t%20want%20to%20switch%20to%20a%20more%20expensive%20hosting%20plan%3F%20This%20is%20a%20great%20alternative%20that%20I%20got%20working%20on%20Dreamhost%20in%20less%20than%20an%20hour%21&amp;short_link=&amp;shortener=google&amp;shortener_key=&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=&amp;service=10&amp;tags=&amp;ctype=" rel="nofollow" class="external" title="Share this on Technorati">Share this on Technorati</a>
		</li>
		<li class="shr-facebook">
			<a href="http://www.shareaholic.com/api/share/?title=How+to+Setup+MongoDB+PHP+Extension+on+Shared+Hosting&amp;link=http://blog.pnapieralski.com/mongodb/how-to-setup-mongodb-php-extension-on-shared-hosting/&amp;notes=Want%20to%20use%20MongoDB%20but%20don%27t%20want%20to%20switch%20to%20a%20more%20expensive%20hosting%20plan%3F%20This%20is%20a%20great%20alternative%20that%20I%20got%20working%20on%20Dreamhost%20in%20less%20than%20an%20hour%21&amp;short_link=&amp;shortener=google&amp;shortener_key=&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=&amp;service=5&amp;tags=&amp;ctype=" rel="nofollow" title="Share this on Facebook">Share this on Facebook</a>
		</li>
		<li class="shr-stumbleupon">
			<a href="http://www.shareaholic.com/api/share/?title=How+to+Setup+MongoDB+PHP+Extension+on+Shared+Hosting&amp;link=http://blog.pnapieralski.com/mongodb/how-to-setup-mongodb-php-extension-on-shared-hosting/&amp;notes=Want%20to%20use%20MongoDB%20but%20don%27t%20want%20to%20switch%20to%20a%20more%20expensive%20hosting%20plan%3F%20This%20is%20a%20great%20alternative%20that%20I%20got%20working%20on%20Dreamhost%20in%20less%20than%20an%20hour%21&amp;short_link=&amp;shortener=google&amp;shortener_key=&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=&amp;service=38&amp;tags=&amp;ctype=" rel="nofollow" class="external" title="Stumble upon something good? Share it on StumbleUpon">Stumble upon something good? Share it on StumbleUpon</a>
		</li>
</ul><div style="clear: both;"></div><div class="shr-getshr" style="visibility:hidden;font-size:10px !important"><a target="_blank" href="http://www.shareaholic.com/?src=pub">Get Shareaholic</a></div><div style="clear: both;"></div></div>

]]></content:encoded>
			<wfw:commentRss>http://blog.pnapieralski.com/mongodb/how-to-setup-mongodb-php-extension-on-shared-hosting/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
	</channel>
</rss>

