<?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>workbench @ haefelinger.it &#187; macports</title>
	<atom:link href="http://workbench.haefelinger.it/archives/tag/macports/feed" rel="self" type="application/rss+xml" />
	<link>http://workbench.haefelinger.it</link>
	<description>Notes, thouhts and other stuff on software development</description>
	<lastBuildDate>Wed, 07 Apr 2010 07:02:31 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>MacPorts, MySQL, PHP5 and that socket thing ..</title>
		<link>http://workbench.haefelinger.it/archives/162</link>
		<comments>http://workbench.haefelinger.it/archives/162#comments</comments>
		<pubDate>Sat, 13 Feb 2010 20:36:37 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[macosx]]></category>
		<category><![CDATA[macports]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://workbench.haefelinger.it/?p=162</guid>
		<description><![CDATA[I&#8217;m using MacPorts to have a variety of Open-Source software on my computer. Amongst them MySQL and Apache&#8217;s web server with PHP. In addition I&#8217;m also running Wordpress, a popular blog software, and  Mediawiki, the software behind Wikipedia. Both applications are written in PHP and can be configured to use MySQL as database. 
I [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m using MacPorts to have a variety of Open-Source software on my computer. Amongst them MySQL and Apache&#8217;s web server with PHP. In addition I&#8217;m also running Wordpress, a popular blog software, and  Mediawiki, the software behind Wikipedia. Both applications are written in PHP and can be configured to use MySQL as database. </p>
<p>I install those two web applications myself rather than using MacPorts to do so. The installation is basically nothing more than unzipping the distribution package and to modify the configuration files to make sure they connect to my MySQL database on my <em>localhost</em>. However, while installing Wordpress went smooth, I run into <em>database connection failures</em> when installing Mediawiki. It took me some time to figure out what is going on here.</p>
<p>If you have weird connection problems using PHP and MySQL then try one or both of the following solutions:</p>
<ul>
<li><strong>Solution</strong>: Use <code>127.0.0.1</code> instead of <code>localhost</code> as host of your MySQL database server. This has a rather surprising effect, see below.
</li>
<li><strong>Solution</strong>: Change your PHP&#8217;s configuration file, which is  <code>/opt/local/etc/php5/php.ini</code>, to contain the following two lines:
<ol>
<li>Tell PHP about the Unix domain socket to use
<pre>
   mysql.default_socket = /opt/local/var/run/mysql5/mysqld.sock
</pre>
</li>
<li> In addtion make sure that PHP&#8217;s save mode is off (notice that this feature has been deprecated and removed in PHP 6), otherwise your previous modification will be gracefully ignored:
<pre>
    safe_mode = Off
</pre>
</li>
</ol>
<p>Notice that in addition you need to <strong>restart your Apache web server</strong> so that your changes are taken into account. You can do that with <code>apachectl restart</code>.
</li>
</ul>
<h4>Background Information</h4>
<p>Neither Mediawiki nor Wordpress (nor most other PHP based web application accessing MySQL) implement the gory details how to connect to a database. Usually they just delegate this to <code>mysql_connect();</code>, a API function provided by PHP.</p>
<p>PHP in turn uses the functionality of a (shared) library provided by MySQL, i.e. the MySQL driver. MySQL allows you to connect to the database via <strong>two routes</strong>:</p>
<ol>
<li>via <strong>Internet sockets</strong> (TCP/IP); and via</li>
<li><strong>UNIX domain sockets</strong></li>
</ol>
<p>So, how does one choose between this two routes? The answer is rather surprising. MySQL decided to give <em>localhost</em> a new meaning. If you specify <code>localhost</code>, then the UNIX domain socket route is chosen. If you say <code>127.0.0.1</code> instead, then you connect via an Internet socket. While this is probably the most natural thing for those MySQL folks, it&#8217;s a rather confusing fact for all other humans. It is rather carved deep in our brain for years now that  <code>127.0.0.1</code> and <code>localhost</code> is the same thing.</p>
<p>After I have changed both Mediawiki and Wordpress to use <code>localhost</code> I had for the first time a situation where both web applications behaved in the very same way. <em>They both did not work</em>. Then, when I changed to <code>127.0.0.1</code>, both worked fine. Btw, notice that <code>localhost</code> is the default <em>hostname</em> used by Mediawiki while  <code>127.0.0.1</code> is the default <em>host</em> suggested by Wordpress.</p>
<p>Using <code>127.0.0.1</code> is usually fine, however I <strong>do want</strong> to use the UNIX socket and I was wondering what went wrong.</p>
<p>The problem is that MacPorts MySQL port patches the original MySQL sources to use socket <code>/opt/local/var/run/mysql5/mysqld.sock</code> instead <code>/tmp/mysql.sock</code>. This change is not particular well documented. One would assume that this kind of change goes into an appropriate <code>my.conf</code> configuration file. That&#8217;s actually not the case. Even worse, MacPorts MySQL port does not even ship with such a configuration file. </p>
<p>Changing the default socket location is one thing, not telling us and the PHP5 maintainer this is another sin. So, while MySQL happily uses that weird socket location, PHP5 still expects <code>/tmp/mysql.sock</code>. In other words, PHP and MySQL are not working out of the box when using MacPorts. At least not when relying on Unix domain sockets. It does work when using Internet domain sockets cause that default port, being 3306, has not changed. Btw, the MacPorts maintainer of PHP and MySQL is one and the same person. Sounds familiar? Yes, I also have been thinking about <em>Dr. Jekyll and Mr. Hyde</em>. No serious. I assume that there is a serious reason why this does not work out of the box as we all wish. I just don&#8217;t get it.</p>
]]></content:encoded>
			<wfw:commentRss>http://workbench.haefelinger.it/archives/162/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Mediawiki on MacPorts</title>
		<link>http://workbench.haefelinger.it/archives/1</link>
		<comments>http://workbench.haefelinger.it/archives/1#comments</comments>
		<pubDate>Wed, 02 Sep 2009 19:11:30 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[admin]]></category>
		<category><![CDATA[macports]]></category>
		<category><![CDATA[macosx]]></category>
		<category><![CDATA[mediawiki]]></category>
		<category><![CDATA[mysql]]></category>

		<guid isPermaLink="false">http://workbench.haefelinger.it/?p=1</guid>
		<description><![CDATA[The installation of <a href="http://en.wikipedia.org/wiki/Mediawiki">Mediawiki</a> is not without pain, especially when using <a href="http://en.wikipedia.org/wiki/Macports">MacPorts</a> on <a href="http://en.wikipedia.org/wiki/Macos_x">MacOS X</a>. A repeating problem is the location of <a href="http://en.wikipedia.org/wiki/Mysql">MySQL</a>'s socket file. For unkown or rather questionable reasons, MacPorts moved that file from it's default location in folder <code>/tmp</code> to <code>/opt/local/var/run/mysql5/mysqld.sock </code> 
[..]]]></description>
			<content:encoded><![CDATA[<p>The installation of <a href="http://en.wikipedia.org/wiki/Mediawiki">Mediawiki</a> is not without pain, especially when using <a href="http://en.wikipedia.org/wiki/Macports">MacPorts</a> on <a href="http://en.wikipedia.org/wiki/Macos_x">MacOS X</a>. A repeating problem is the location of <a href="http://en.wikipedia.org/wiki/Mysql">MySQL</a>&#8217;s socket file. For unkown or rather questionable reasons, MacPorts moved that file from it&#8217;s default location in folder <code>/tmp</code> to </p>
<pre>
/opt/local/var/run/mysql5/mysqld.sock
</pre>
<p>Even  worse, the file&#8217;s name, usually <code>mysql.sock</code>, has now changed into <code>mysqld.sock</code>. So it comes to no surprise that applications like PHP, Mediawiki and oh-you-name-it simply choke. Except if you also install those via MacPorts. Then you may have a chance that it works. </p>
<p>Personnally however I don&#8217;t like this <em>all-or-nothing</em> approach. Ideally I would like to have a system where MacPorts lives in a friendly coexistence with tools not provided by MacPorts.  Wouldn&#8217;t it be good if there were a kind of <em>registry</em> knowing about locations? Unfortunatly, such a registry beast is still missing on UNIX based platforms. As much as I like the UNIX approach, all those config file locations and dialects drives me crazy. </p>
<p>So how would Mediawiki know that my MySQL&#8217;s configuration file is burried deep in <code>/opt/local/etc</code> and that furthermore, MySQL got pached to use that fancy location mentioned above? </p>
<p>Well, it simply can&#8217;t figure it out.</p>
<p>Now, you may think that&#8217;s no problem then. We just tell Mediawiki where it is. That&#8217;s not going to work either as long as you are unwilling to wrestle with Mediawikis PHP code: joy-oh-joy, it&#8217;s just hardwired to <code>/tmp/mysql.sock</code>. Period. So, what you need to do is to ask good old <code><a href="http://en.wikipedia.org/wiki/Ln_%28Unix%29">ln</a> -s</code> for rescue:</p>
<pre>
% sudo ln -s /opt/local/var/run/mysql5/mysqld.sock /tmp/mysql.sock
</pre>
<p>This works eventually but it&#8217;s really ugly cause the problem with links is that after a while no one knows why this link was created in the first place.</p>
<p>Happy Hacking.</p>
]]></content:encoded>
			<wfw:commentRss>http://workbench.haefelinger.it/archives/1/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
