<?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>Havoc Inspired &#187; Media Temple</title>
	<atom:link href="http://www.havocinspired.co.uk/category/media-temple/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.havocinspired.co.uk</link>
	<description>Home of Ryan Taylor</description>
	<lastBuildDate>Tue, 25 May 2010 21:20:33 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Plesk, PEAR, include_paths, open_basedir and Media Temple</title>
		<link>http://www.havocinspired.co.uk/tutorial/plesk-pear-include_paths-open_basedir-and-media-temple/</link>
		<comments>http://www.havocinspired.co.uk/tutorial/plesk-pear-include_paths-open_basedir-and-media-temple/#comments</comments>
		<pubDate>Sun, 01 Nov 2009 23:52:04 +0000</pubDate>
		<dc:creator>Ryan Taylor</dc:creator>
				<category><![CDATA[Hosting]]></category>
		<category><![CDATA[Media Temple]]></category>
		<category><![CDATA[PEAR]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://www.havocinspired.co.uk/?p=740</guid>
		<description><![CDATA[In this tutorial I'll talk you through enabling PEAR packages on a server running the Plesk control panel.]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.havocinspired.co.uk%2Ftutorial%2Fplesk-pear-include_paths-open_basedir-and-media-temple%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.havocinspired.co.uk%2Ftutorial%2Fplesk-pear-include_paths-open_basedir-and-media-temple%2F&amp;source=ryanhavoc&amp;style=normal&amp;service=TinyURL.com" height="61" width="50" /><br />
			</a>
		</div>
<p>If you <a href="http://www.havocinspired.co.uk/freelance/so-i-got-hacked/">follow my blog</a> you’ll know that I’ve recently moved to <a href="http://www.mediatemple.net">Media Temple</a> as my hosting provider. I’ve gone for a <a href="http://mediatemple.net/webhosting/dv/">Dedicated Virtual</a> server and so far I’m very pleased with the flexibility I have with it.</p>
<p>Media Temples’ servers, like many other providers, run <a href="http://www.parallels.com/uk/products/plesk/">Plesk</a> as their control panel which means there are a few quirks that need to be overcome.</p>
<p>I should say at this point that I don’t claim to be a Linux/Plesk expert, i simple know enough to find my way around (or enough to be dangerous depending on who you’re asking).</p>
<h3>Default behaviour</h3>
<p>By default Plesk uses the <a href="http://www.php.net/manual/en/ini.sect.safe-mode.php#ini.open-basedir">PHP open_basedir</a> directive to limit access to files outside a sites directory-tree. So if you have setup the domain example.com all your files go into the httpdocs folder (unless you’re using an SSL certificate in which case they go in the httpsdocs folder). For our example.com domain the server path would be:</p>
<pre class="brush: bash;">/var/www/vhosts/example.com/httpdocs</pre>
<p>Plesk’s default value for open_basedir is:</p>
<pre class="brush: bash;">/var/www/vhosts/example.com</pre>
<p>Which means any PHP script you place in the httpdocs cannot dig any further down the directory-tree than the example.com folder.</p>
<p>This is a security measure.</p>
<h3>The problem</h3>
<p>There are two scenarios (that I’ve come across) where this is a problem. The first is if you want to use <a href="http://pear.php.net/">PEAR</a>, which is the scenario I’m most common with and will be covering the solution for here, and the second is if you want to use the Expression Engine Multi Site Manager.</p>
<p>Both require PHP scripts to access files outside of their directory-tree.</p>
<h3>The solution</h3>
<p>To enable access to PEAR packages we need to add the server path to the open_basedir variable as well as the include_path variable. If you’re on a Media Temple server like me the path should be:</p>
<pre class="brush: bash;">/usr/share/pear</pre>
<p>If not you’ll need to locate the folder that PEAR is installed in on your server.</p>
<h4>Step 1 &#8211; SSH to the server</h4>
<p>You need to SSH into your server, if you are with Media Temple and this is the first time you are trying to do this, you’ll first need to enable Root Access for your domain through your <a href="https://ac.mediatemple.net/">Media Temple Account Center</a>.</p>
<p>If you’re on a Mac you can use Terminal to SSH to your server with:</p>
<pre class="brush: bash;">ssh admin@example.com</pre>
<p>Then your passworld.</p>
<p>If you’re on a PC you can use <a href="http://www.chiark.greenend.org.uk/~sgtatham/putty/">Putty</a>. My memory is fuzzy on the exact use however, so you’ll need to consult the manual.</p>
<p>Once you are connected to your server you will need to switch user to root for the next step. To do this enter:</p>
<pre class="brush: bash;">su - root</pre>
<p>Then your password.</p>
<h4>Step 2 &#8211; Create a vhost.conf file</h4>
<p>Be careful, you now have godly control of your server!</p>
<p>We now need to create a vhost.conf file for our example.com domain which will override Plesk’s default settings.</p>
<p>The following command will create the file:</p>
<pre class="brush: bash;">vim /var/www/vhosts/example.com/conf/vhost.conf</pre>
<p>If you’ve never used vim (which is an editor for Linux) you need to know that pressing the &#8216;<strong>a</strong>&#8216; key puts you into author mode and the &#8216;<strong>esc</strong>&#8216; key takes you out (this is about the extent of my vim knowledge, I hope you are impressed!).</p>
<p>While in author mode enter the following information:</p>
<pre class="brush: bash;">
&lt;Directory &quot;/home/httpd/vhosts/example.com/httpdocs&quot;&gt;
php_admin_value open_basedir &quot;/home/httpd/vhosts/example.com/httpdocs:/usr/share/pear:/tmp&quot;
php_admin_value safe_mode Off
php_admin_value include_path &quot;.:/usr/share/pear&quot;
&lt;/Directory&gt;
</pre>
<p>To save the file and quit, press the &#8216;<strong>esc</strong>&#8216; key to leave author mode and type &#8216;<strong>:wq</strong>&#8216; (write and quit) and press enter.</p>
<p>So you can see that we specify the location of our example.com domain, added /usr/share/pear to the open_basedire variable and turned off safe_mode&#8230;?</p>
<p>PHP documentation states that open_basedir isn’t effected by safe_mode being on or off however from my experience if you don’t have it turned off, PEAR doesn’t work, as I say I’m no expert so maybe someone can enlighten me?</p>
<p>You can also see that we set the PHP include_path to also include /usr/share/pear</p>
<h4>A little gotcha</h4>
<p>We use php_admin_value to set the include_path. This means that the include path cannot be change using the PHP <a href="http://php.net/manual/en/function.set-include-path.php">set_include_path</a> function.</p>
<p>If you want to be able to change the include_path from within your script, perhaps you want to include a folder containing your own classes for example, you need to change:</p>
<pre class="brush: bash;">php_admin_value include_path &quot;.:/usr/share/pear&quot;</pre>
<p>To:</p>
<pre class="brush: bash;">php_value include_path &quot;.:/usr/share/pear&quot;</pre>
<h3>Step 3 &#8211; The scary bit! Reconfigure and restart apache</h3>
<p>You now need to run the following command so that the server knows to use our new vhost.conf file:</p>
<pre class="brush: bash;">/usr/local/psa/admin/sbin/websrvmng --reconfigure-vhost --vhost-name=example.com</pre>
<p>And then restart apache:</p>
<pre class="brush: bash;">
/etc/init.d/httpd stop
/etc/init.d/httpd start
</pre>
<h3>Conclusion</h3>
<p>That should be it, you’re all PEAR’ed up and ready to go. You should note that this configuration will only effect the example.com domain. If you create a new domain you&#8217;ll have to create a vhost.conf file for that domain as well. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.havocinspired.co.uk/tutorial/plesk-pear-include_paths-open_basedir-and-media-temple/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
	</channel>
</rss>
