Archive

Archive for July, 2011

Fixing mysql in OS X Lion upgrade

July 20th, 2011

After upgrading to OS X Lion today, MySQL seemed to stop working. In fact, mysql was still running, however there were 2 problems:

  1. php not connecting to mysql server
  2. mysql no longer in path (terminal commands “mysql -u root -p” doesn’t work)

I found the solution for (1) at: http://birdchan.com/home/2011/07/20/osx-lion-mysql-sock-path/
Here is what it says:

  1. shut down your Web Sharing
  2. cp /etc/php.ini.default /etc/php.ini (for some reasons my old php.ini got renamed to php.ini.default…)
  3. modify /etc/php.ini, change /var/mysql/mysql.sock to /tmp/mysql.sock
  4. enable Web Sharing

Or it looks like the file that you want to reinstate is “php.ini-5.2-previous” (had all of my old settings). If you follow the 4 steps above, you will also need to set the timezone in line 998 on you newly created php.ini: “date.timezone = Europe/London”.

To add the mysql into your path just create a file called mysql in /etc/paths.d :
sudo touch /etc/paths.d/mysql
Then add “/usr/local/mysql/bin” to the file using a text editor e.g.
sudo vi /etc/paths.d/mysql

Then I had to reboot.

Dan Spencer Computing, OS X

Apache 2 deflate for file compression

July 4th, 2011

Whilst reading a very good article from the techies at Yahoo, I found out that it would be a good idea to compress certain files on my Apache2 server to reduce the amount of data passed to the browser over the internet.

I found a pretty good article from How2forge at http://www.howtoforge.com/apache2_mod_deflate

I also modified the log output to include a timestamp to distinguish easily between different requests:
DeflateFilterNote Input input_info
DeflateFilterNote Output output_info
DeflateFilterNote Ratio ratio_info
LogFormat '"%t %r" %{output_info}n/%{input_info}n (%{ratio_info}n%%)' deflate
CustomLog /private/var/log/apache2/deflate_log deflate

The %t in the LogFormat line adds the timestamp.

Note the path to the CustomLog as I am on a Mac.

Dan Spencer Computing

Number of lines in multiple files

July 1st, 2011

The other day I wanted to find out how many lines of code I had written for a particular project. A quick web search through up a useful bit of code in the terminal.
Navigate to the directory that you wish to search and then:
find . -name "*.php" -exec wc -l '{}' \; | awk '{ sum += $1 } END { print sum }'
It will search all files in the directory and sub-directories beneath it.

Dan Spencer Computing