The Good Kind of Spying

Claudia: The good kind of spying, like “Here, have some flowers, and a puppy, and some spying”…

Yes! Angela Lansbury…

Claudia: Yes! Angela Lansbury, you’ve solved the mystery…

Leopard Web Development Setup

I cobbled this together from a few sources to set up your local PHP/MySQL development environment on a stock OS X Leopard installation with VMware Fusion.

Set up virtual hosts

Edit the hosts file

Open the file /private/etc/hosts. At the bottom of the file, enter your local IP address (127.0.0.1) and the name of each site you want to set up:

127.0.0.1 local.site.com

Edit the Windows hosts file

Get your Parallels (vnic0) / VMWare Fusion (vmnet1) virtual machine IP address in Terminal:

ifconfig vnic0

Open the file `c:windowssystem32driversetchosts`. At the bottom of the file, enter your VM IP address (172.16.157.1 or similar) and the name of each site you want to set up:

172.16.157.1 local.site.com

Add the virtual host in Apache

Open the file /private/etc/apache2/extra/httpd-vhosts.conf. You should see:

#
# Use name-based virtual hosting.
#
NameVirtualHost *:80

Underneath this, enter this for each site you want to set up:

<virtualhost *:80>
DocumentRoot "/Users/username/Sites/local.site.com"
ServerName local.site.com
</virtualhost>

Activate virtual hosts in Apache

Open the file /private/etc/apache2/httpd.conf Find the line:

# Virtual hosts
#Include /private/etc/apache2/extra/httpd-vhosts.conf

Uncomment the line:

# Virtual hosts
Include /private/etc/apache2/extra/httpd-vhosts.conf

Permissions

Open the file /etc/apache2/users/username.conf. Modify the file:

<directory "/Users/username/Sites/">
Options All
AllowOverride All
Order allow, deny
Allow from all
</directory>

Restart Apache

In Terminal, execute:

sudo apachectl graceful

Set up MySQL

Specify socket location

If it doesn’t exist, create the PHP configuration file:

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

Open the file `/etc/php.ini`. Find the line:

mysql.default_socket =

Modify the line:

mysql.default_socket = /private/tmp/mysql.sock


Find the line:

mysqli.default_socket =

Modify the line:

mysqli.default_socket = /private/tmp/mysql.sock

## Restart Apache

In Terminal, execute:

sudo apachectl graceful

Repair /etc

If you managed to break your OS X installation so badly that it’s come to this, you can repair it with:

/sbin/mount -uw /
cd /
ln -s /private/etc etc
/sbin/fsck -fy
chown root:wheel /etc

And, yes, it is possible to do this to yourself...

Using regular expressions with MySQL

The basic syntax to use regular expressions in a MySQL query is:

SELECT something FROM table WHERE column REGEXP 'regexp'

For example, to select all columns from the table events where the values in the column id end with 5587, use:

SELECT * FROM events WHERE id REGEXP '5587$'

A more elaborate example selects all columns of the table reviews where the values in the column description contain the word excellent:

SELECT * FROM reviews WHERE description REGEXP '[[:<:]]excellent[[:>:]]'

MySQL allows the following regular expression metacharacters:

. match any character
? match zero or one
* match zero or more
+ match one or more
{n} match n times
{m,n} match m through n times
{n,} match n or more times
^ beginning of line
$ end of line
[[:<:]] match beginning of words
[[:>:]] match ending of words
[:class:] match a character class
i.e., [:alpha:] for letters
[:space:] for whitespace
[:punct:] for punctuation
[:upper:] for upper case letters
[abc] match one of enclosed chars
[^xyz] match any char not enclosed
| separates alternatives

MySQL interprets a backslash (``) character as an escape character. To use a backslash in a regular expression, you must escape it with another backslash (`\`).

Haap! Logo

more