Tag Archives: mac

Problems connecting to unix:///var/mysql/mysql.sock

In a previous post I talked about MySQL 5.5 and Mac OSX.

In this post I’ll go through fixing the problems with PHP and connecting to your local mysql install, using “localhost”.

The problems began a while back, with lots of errors in my apache error log saying:

[error] [client ::1] PHP Warning:  mysql_connect(): [2002] No such file or directory (trying to connect via unix:///var/mysql/mysql.sock) in ...

In the rush I was in, I quickly changed my mysql connection to use: 127.0.0.1, which is the IP of your localhost. So basically the same thing.

Today I’m doing some freelance work for a customer, who has some problems with his server, after the PHP version was upgraded. I decided to fetch all his php files to my local Mac and then run through his webshop, fixing any errors I might see in the log etc.
When starting the my apache and running the website, I quickly found the MySQL connect error again.

Since this project should be a “search and fix” mission, I didn’t have time to change the mysql_connect(xxx) statements in the code (yes yes, not my code, so I didn’t create the mess…), so instead, I wanted to fix my local PHP->MySQL connection.

The fix was relatively easy, and only contains 1 to 2 steps:

Step 1 (if needed)

If you haven’t activated php.ini on your local install, open a Terminal and write the following command:

sudo cp /etc/php.ini.default /etc/php.ini

This copies the default php settings to the php.ini file, which the apache server uses.

Then restart your apache server. (Using System Preferences->Sharing->Web sharing)

Your PHP is now using the php.ini file.

Step 2

Open /etc/php.ini file using your favorite text editor.

Goto line 1216 (or search for “mysql.default_socket = ” without the quotes) and change /var/mysql/mysql.sock to /tmp/mysql.sock

Restart your apache server and you should now be able to connect to localhost again.

Still have problems?

If you still have problems, then try the following:

Open Terminal and write:

mysqladmin version

It should print something like this:

mysqladmin  Ver 8.42 Distrib 5.1.53, for apple-darwin10.3.0 on i386
Copyright 2000-2008 MySQL AB, 2008 Sun Microsystems, Inc.
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under the GPL license

Server version		5.1.53
Protocol version	10
Connection		Localhost via UNIX socket
UNIX socket		/tmp/mysql.sock
Uptime:			2 hours 52 min 6 sec

Threads: 3  Questions: 58  Slow queries: 0  Opens: 16  Flush tables: 1  Open tables: 9  Queries per second avg: 0.5

The path in the UNIX socket is the “localhost” connection point. So go back to Step 2 and use that path instead.

MySQL 5.5, Mac OS X and startup item security error

A few days ago I got a shiny new macbook at work and I needed to install my dev environment again.

I came across a few problems when installing the new MySQL community server package though, which had been upgraded to 5.5 instead of the 5.1 release I had on my old Mac.

Fixing MySQL server startup

The first problem I came across was that the server would not start properly, using the prefpane item.

This is easily fixed by editing the file /usr/local/mysql/support-files/mysql.server and going to line 46 + 47 and replacing the lines there with this:

basedir=/usr/local/mysql
datadir=/usr/local/mysql/data

You can now use the prefpane item to start your MySQL server.

source: http://forums.mysql.com/read.php?11,399397,399606#msg-399606

Fixing the autostart

If you are like me, you like it when all the services start at boot, since you don’t have to start ’em by hand.
However, there is a problem with getting MySQL server 5.5 to start using the prefpane.

In order to get the autostart up and running you need to fix the privileges on the startup item.
Open a terminal and do the following:

sudo chown :wheel /Library/StartupItems/MySQLCOM/MySQLCOM 
sudo chown :wheel /Library/StartupItems/MySQLCOM/StartupParameters.plist

After that you need to restart the computer. Logging out and back ind will not do the job.

source: http://bugs.mysql.com/bug.php?id=57790#c350454

Cycle through history in linux/mac terminal

If you are like me, you often use the terminal for… well.. let’s face it, most things.
I cannot remember one day, when i’m not bashing the keys in the terminal, trying to find, script or copy my way out of things.

Often I need to do the same things more than once. This could be connecting to a server to configure something, run a script I made earlier to resize some images, some FFMPEG command that I used earlier…

Eventually you get tired from hitting the arrow up key, and some years ago I got introduced to the “reverse history search”.
This is a way to search through your recent history (history being commands you’ve used in the terminal).

Simply hit CTRL+R to start the search, and the terminal will now look like this:
(reverse-i-search)`':

When you start typing, it searches through the history of your terminal.

One thing that bothered me though, was that I could only get the most recent result, and arrow up/arrow down doesn’t search through the results.

Hitting CTRL+R again displays the next result, that has the same command.

Just wanted to share it, happy bash’ing

Fixing symlinks in Mac OS 10 + built in Apache

The other night I was fiddling about with my macbook, trying to setup a “MySQL-Apache-PHP” server on my system. Digging a bit about the system and googling a bit, it seems that the system comes with a built in apache server and php installation.

I thought to myself, why not use the built in server instead of installing a MAMP package?

Anyways, seconds went by and I found the option in the system preferences, turned on “web sharing” and excitedly headed on to localhost. It worked perfectly, now I just needed to set it up as it was on my linux desktop.

The apache’s httpd.conf file is located in the folder: /private/etc/apache2/httpd.conf
(I used textmate to edit the file.)

What I wanted to do was, since I’m the only user on this laptop, I wanted my Sites folder to have a www “folder”, which was a symlink to a folder in my Documents folder. The symlink would then point to the webapp I was currently coding.

This worked on my linux desktop, so it should also work here.

The first thing I did was to fix the DocumentRoot so it now points directly to my /Users/username/Sites/www folder (or actually the symlink, which we’ll create now).
The I added PHP support by removing the comments from line 116, containing:

LoadModule php5_module         libexec/apache2/libphp5.so

Then I went into my Sites folder and created a symlink to a folder in the Documents folder called “current_project” (yes yes, secret stuff here). This is done using the following command:

ln -s ~/Documents/current_project ~/Sites/www

After that, just reboot you apache server (you can use the Web Sharing option in the System Preferences. Just uncheck the web sharing checkbox and recheck it again).

An here my problems began. I got a lot of warnings in my apache error log (/private/var/log/apache2/error_log) saying:

Symbolic link not allowed or link target not accessible: /Users/username/Sites/www

After googling for a while with no answers, I thought : “why not disable the userdir module? I’m not going to use the localhost/~username anyways”

This turned out to do the trick.

The solution was simply to disable the userdir module in apache.
Comment out line 112 (LoadModule userdir_module libexec/apache2/mod_userdir.so) and line 465 (Include /private/etc/apache2/extra/httpd-userdir.conf)
Restart the apache server (web sharing thingy in the System preferences interface) and you server can now access the symlink.

I hope this will help you on your way, when coding using a Mac.

Small update: (2010-06-02 at 13:15)
Remember to right click the Documents folder and choose “Get Info”. Unfold “Sharing & Permissions” and set “Everyone” to “Read only”, else you will get a permission denied