I wrote the below BASH function today. It's good because it performs super well compared to the alternative commands (which are commented out below above the new commands):

own() {

  echo "Taking ownership..."
  #chown -R jj5:jj5 .
  find . \! -user jj5 -or \! -group jj5 -execdir chown jj5:jj5  "{}" \;
  [ "$?" = 0 ] || { echo "Could not take ownership in '$PWD'."; exit 1; }

  echo "Fixing directory permissions..."
  #find . -type d -execdir chmod u+rwx "{}" \;
  find . -type d -and \( \! -perm /u=r -or \! -perm /u=w -or \! -perm /u=x \) -execdir chmod u+rwx "{}" \;
  [ "$?" = 0 ] || { echo "Could not fix directory permissions in '$PWD'."; exit 1; }

  echo "Fixing file permissions..."
  #find . -type f -execdir chmod u+rw "{}" \;
  find . -type f -and \( \! -perm /u=r -or \! -perm /u=w \) -execdir chmod u+rw "{}" \;
  [ "$?" = 0 ] || { echo "Could not fix file permissions in '$PWD'."; exit 1; }


The basic premise is don't do work which doesn't need to be done!

Creating a user and database in PostgreSQL

To create a database and user account for use on PostgreSQL:

root@devotion:~# su - postgres

postgres@devotion:~$ psql
psql (8.4.21)
Type "help" for help.

postgres=# create user "www-data" superuser;

postgres=# create database mydb with owner "www-data";

postgres=# \c mydb
psql (8.4.21)
You are now connected to database "mydb".
mydb=# alter user "www-data" with password 'secret';

Running Apache as ME!

On my development machine I want Apache to run under my user id so I can automatically generate files (and have permission to write them).

I configured Apache like this:

root@mercy:/etc/apache2# grep -R www-data .
./envvars:export APACHE_RUN_USER=www-data
./envvars:export APACHE_RUN_GROUP=www-data

root@mercy:/etc/apache2# vim envvars 

export APACHE_RUN_USER=jj5

root@mercy:/etc/apache2# apache2ctl graceful
/var/lock/apache2 already exists but is not a directory owned by jj5.
Please fix manually. Aborting.

root@mercy:/etc/apache2# chown jj5:jj5 /var/lock/apache2

root@mercy:/etc/apache2# apache2ctl graceful


Wait... that didn't work. The problem was apache2ctl graceful didn't pick up the new envvars file, this fixed it:

root@mercy:/etc/apache2# /etc/init.d/apache2 restart

phpMyAdmin #1045 Cannot log in to the MySQL server

I was using phpMyAdmin and trying to login to my server with a new user that I'd created called 'pma' but I was getting the error "#1045 Cannot log in to the MySQL server". The 'pma' user was also my phpMyAdmin control user and as its login wasn't working advanced features of phpMyAdmin weren't functional and I was getting an error letting me know.

I thought maybe the problem was that I'd specified the password for the 'pma' user incorrectly so I reset the 'pma' user password just to be user:

  update user set password=PASSWORD("secret") where user='pma';

But the problem persisted. I had a look in the mysql.user table to see what was in there. The results included the following:

  mysql> use mysql;
  Database changed
  mysql> select Host, User, Password from user;
  | Host      | User      | Password                                  |
  | localhost |           |                                           |
  | %         | pma       | *BD053A55278DA675E32F28360C759B3FBEE32B3E |

Note the entry on the first line with a blank username. I have no idea how that entry got into my mysql.user table but basically it seems to be interpreted as "any user" at localhost with no password. I didn't like the look of that so I deleted that entry. After that entry had been deleted the login for my 'pma' user started to work.