Using MySQL with the built-in OSX Apache and PHP

Although it's quite simple to download and install MySQL on a Mac OS X system, most PHP apps that interact with the database won't run right out of the box without an initial tweak. For the purposes of this article, I am referring to Mac OS X 10.4.x (Tiger) and MySQL 5.0.x. As of the 10.4.6 patch of Tiger, Mac OS X has Apache 1.3.33 and PHP 4.4.1 built-in. A nicety of the system is that external MySQL support has been compiled in. However you will need to adjust a few things to make web apps work. If you get the official MySQL binary distribution installed, everything is put into its proper place but you still need to set the root MySQL password. This isn't detailed in the installer AFAIK (I could be wrong… I didn't read the notes… do any of you ever?). So before you go any further, open up your Terminal. Note that all MySQL executables are installed in /usr/local/mysql/bin where mysql is a symbolic link pointing the current distribution directory, named after its version. Either change to the MySQL bin directory or add it to your path and type: mysqladmin -u root password new_password where new_password is the new, initial password for the root MySQL account. Also note that Mac OS X should have a built-in UNIX user called 'mysql' with no shell and a home directory of /var/empty. Sweet! Now that you have the first security step done, you need to tell PHP that MySQL now exists. If you attempt run PHP/MySQL apps out of the box at this point, they will likely balk and say that your database is down. This is because the compiled-in MySQL socket path differs from what actually exists when you install MySQL from the official binary distribution. By default, the PHP config file does not exist on Mac OS X but a template config file is included so you can activate it. Make a copy of /etc/php.ini.default and name the copy /etc/php.ini …now edit the file and look for this line: mysql.default_socket = This needs to be updated because the compiled-in default value is /var/lib/mysql. Update that line to read: mysql.default_socket = /tmp/mysql.sock Save the file and restart Apache. Your PHP/MySQL web applications should now be running on Mac OS X. Be aware that Apple security updates have a nasty habit of breaking custom web apps if they touch Apache or PHP so keep track of your configuration files before you run Software Update. If you have problems with Apache and PHP on Mac OS X, in general, you might want to start by making sure PHP is activated. Check your Apache config file and ensure the PHP module is loaded. Create a generic phpinfo() PHP file, load that, and check all the settings.

Advertisements

Getting AWStats to see mod_gzip data from Apache logs

I'm having a hell of a time trying to get some file deflation statistsics to show up in AWStats considering I had added mod_gzip and changed my Apache log format to include such data. I must say, hacking httpd.conf and an awstats conf file is pretty arcane stuff if you don't understand the terms being thrown around. Let me also say that it appears Safari 2.0.3 is unable to view AWStats reports if you have BuildReportFormat=xhtml set. For now, use BuildReportFormat=html if you're using a Mac to administer stats. Zope.org has a good tutorial on getting mod_gzip initially installed, although the example uses the "common" format. I use "combined". Well, I hacked together

LogFormat="%host %other %logname %time1 %methodurl %code %bytesd %refererquot
%uaquot %other %other %gzipin %gzipout"

in the AWStats conf file for one of my sites since my entry in httpd.conf says

LogFormat "%h %l %u %t "%r" %>s %b "%{Referer}i" "%{User-Agent}i"
mod_gzip: %{mod_gzip_result}n In:%{mod_gzip_input_size}n
Out:%{mod_gzip_output_size}n:%{mod_gzip_compression_ratio}npct." combined-gzip

The old addage goes, "RTFM" which I probably should have done first. And, to my chagrin, the proper syntax is found on the AWStats FAQ page. Silly me. Unfortunately, I still can't get any mod_gzip stats out my logs. It USED to work. Anyone have any ideas? Here is an example line from my Apache log:

xxx.xxx.xxx.xxx - - [07/Apr/2006:12:04:34 -0700] "GET / HTTP/1.1" 200 2064 "-"
"Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en) AppleWebKit/418 (KHTML, like Gecko)
Safari/417.9.2" mod_gzip: OK In:4978 Out:1670:67pct.