Notes
How to install Drush server-wide in less than one minute
Having Drush installed server wide is handy, especially if you have several users logging on the server. Use the appropriate url for the tarball, you can find the latest release of drush at http://drupal.org/project/drush. The lines below assume you have sudo access. If you don't, please check the README.txt file for other options.
Script: Strip trailing whitespaces and force new line at end of file
Many editors/ IDEs now support this code style rules. If you don't want to have to open every single file of a project and save each of them, you can use this script. It is somewhat adapted to the case of Drupal, but can be used in other cases too with some tweaks.
<?php
#!/bin/bash
# strip trailing white spaces.
for ext in "info" "css" "txt" "sh" "profile" "install" "test" "module" "inc" "php" "js"
do
find . -type f -name "*.$ext" -exec sed -i 's/[[:space:]]*$//' {} \;
done
# ensures all files end with a newline.
Connect to a VirtualBox guest machine with SSH and HTTP
You can easily setup a VBox VM to allow ssh and http connection from your host machine. See http://sk.c-wd.net/wp/2008/01/05/virtualbox-port-forwarding-with-linux-h... and http://mydebian.blogdns.org/?p=111
On MacBook Pro, this is the settings I needed as they appear in Library/VirtualBox/Machines/guestname/guestname.xml:
Easier canonical url management in .htaccess
I was looking for a quick way to make sure all my multisites are using a www. url, and I found this patch which was committed to Drupal 7: Better, multi-site friendly "www." addition/removal in .htaccess. While this won't be committed to Drupal 6, it's very easy to use it manually in your .htaccess file. Here are the relevant snippets (only use one of them depending on whether you want to www. prefix or not):
# To redirect all users to access the site WITH the 'www.' prefix,
Filepath fix for Drupal multisite installation
I can't believe this is still an issue in Drupal 6: whenever you move your site to a multisite installation (or whenever you want to rename the location where you sites files directory is), you need to hack the database. This has all changed now in Drupal 7 with the new fancy file support, but in the meantime for those still working with Drupal 6, I'd like to share the following tip. Drupal stores the path to the file relative to its root (where index.php is).
My favorites shell aliases
These are the aliases I use:
alias t='tar zxvf'
alias T='tar zcvf'
alias drush='~/.drush/drush/drush'
alias diff='diff -up'
alias gdiff='git diff --no-prefix'
alias gre='git reset --hard'
alias gst='git status'
alias sd='svn diff'
alias st='svn status'
alias cvs='cvs -q'
alias drcvs='cvs -d:pserver:anonymous:anonymous@cvs.drupal.org:/cvs/drupal'
alias cdiff='cvs -q diff'
# usual bash stuff
alias l.='ls -d .* --color=tty'
alias ll='ls -l --color=tty'
alias ls='ls --color=tty'
alias vi='vim'
alias which='alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde'I've also attached my git configuration file. Place it in your home directory, adapt it (change name and email) and rename it to .gitconfig.
Backup your Drupal sites with Drush and Git
Git is great for code development! But it can also be used for backing up your sites! Here is how I do it. I wrote a script leveraging Drush to dump the database(s) of your sites and then commit all these changes to a git repository.
cd /var/sites/multi6/
drupal/sites/default
drupal/sites/example1.org
drupal/sites/example2.com
database/default.sql
database/example1.org.sql
database/example2.com.sql
.git/Here is the script:
<?php
#!/bin/bash
# This script backups the databases of all the sites found in the
Create a new mysql database for a Drupal site via the command line
This is the command I use in the mysql CLI. Note that Drupal 6 does not require the CREATE TEMPORARY TABLE and LOCK TABLES permissions but some tools like drush or dbscripts require them.
GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER, CREATE TEMPORARY TABLES, LOCK TABLES
ON db.*
TO 'user'@'localhost' IDENTIFIED BY 'pass';
FLUSH PRIVILEGES;Redirect all HTTP traffic to HTTPS
Drupal and SSL - Multiple Recipes to Possible Solutions is a good related article on the topic in Drupal.
I recently had to set up a server where all traffic should be SSL, here is the snippet I used in /etc/apache2/sites-available/default
RewriteEngine On
RewriteCond %{HTTPS} off
# RewriteCond %{HTTPS} !=on
# RewriteCond %{SERVER_PORT} !^443$
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}I've commented some alternative of
RewriteCond I found on the web but they should all be equivalent in most cases.
Don't forget to edit /etc/php5/apache2/php.ini in order to set:
session.cookie_secure = 1otherwise your session cookies will be sent unencrypted on the internet.
Display the content of a table from the left bar in phpMyAdmin (MAMP)
In the latest version of MAMP there is no way anymore to browse a table directly from the left bar in phpMyAdmin. I miss that feature and I think I'm not the only one. Attached is a patch for the confing.inc.php which you can run from anywhere with the command:
patch -p0 < pma_php5_browse_tables.patch

