administration

Create MySQL configuration file (my.cnf) on MAMP

If you ever find yourself in need to adjust some MySQL settings and you're running a MAMP server on Mac OS X, you can always create a my.cnf file using the following command:

sudo cp /Applications/MAMP/Library/share/mysql/my-medium.cnf /Applications/MAMP/Library/my.cnf

You now have created your own my.cnf file where you can adjust some settings. Please make sure restart your MySQL instance after altering the configuration.

You have a few other starting point for creating a my.cnf file. MAMP ships with 5 configuration files for some typical settings. The filenames should be self explanatory:

./Library/share/mysql/my-huge.cnf
./Library/share/mysql/my-innodb-heavy-4G.cnf
./Library/share/mysql/my-large.cnf
./Library/share/mysql/my-medium.cnf
./Library/share/mysql/my-small.cnf

Update: Beware: The my.cnf file might enable binary logging. This may create huge log files (gigabytes). Check out webchick's post how to disable mysql binary logging.

Written on September 24, 2008 at 09:48, tagged as administration, MySQL, tips

MySQL server has gone away

I have had this one 2 times now. And it's always the same thing: too many fields in CCK.

Too many fields means too large queries to update the cache. And then MySQL goes down with this nice error message.

How to solve this? Increase the max_allowed_packet to a bigger number in your my.cnf (linux) or my.ini (windows).

If it's not there just add it.

max_allowed_packet=32M

Problem solved!

Written on August 06, 2008 at 14:36, tagged as administration, Drupal, MySQL, server management

Drupal custom URL rewriting - Change the admin url to enhance security

The following tip can be used in multiple scenarios (being anywhere you need custom URL rewriting and want to do this without .htaccess), but I'll illustrate it for two specific purposes.

  1. At our company all urls beginning with /admin are blocked from outside by a firewall for content security reasons. This sucks, because Drupal administration is done on pages with a /admin url. So we need to find a way to rewrite all of the urls to something like /config (or something else).
  2. If someone knows your site is on Drupal, this gives him some knowledge on how the site is structured. For example does he know that all administration is done on /admin. To make it harder to guess this url, we want to rename it.

Both of these cases can be tackled by one hook (custom_url_rewrite) in Drupal that has to be specified in the settings.php file. You can find a descent explanation of how this hook works in the Drupal API.

In the following example I rewrite all admin urls to config (and vice versa).

function custom_url_rewrite($op, $result, $path) {

  if ($op == 'alias') {
    if (preg_match('|^admin(/{0,1}.*)|', $path, $matches)) {
      return 'config'. $matches[1];
    }
  }
  
  if ($op == 'source') {
    if (preg_match('|^config(/{0,1}.*)|', $path, $matches)) {
      return 'admin'. $matches[1];
    }
  }
  
  return $result;
  
}
Written on March 10, 2008 at 15:02, tagged as administration, Drupal, security, settings, tips, url rewriting

About

drupalcoder.com is a blog on all things Drupal in specific and LAMP on OS X in general. It is maintained by Davy Van Den Bremt, a Belgian (Drupal) web developer and designer living in Ghent. The goal of this blog is to log all interesting things that have crossed the writer's path while developing Drupal sites. You can read all about Davy's professional activities on his LinkedIn profile. If you want to get in touch, use the contact form.