|
MySQL,
PHP and MySQL Tools for MacOS X
Preface MySQL is no questions the most popular SQL database server which currently powers over 1 million Web sites. It is extremely fast, reliable, and what is very important - free for anyone who is not distributing modified version of MySQL itself (it means, for example, that you can sell your own databases which just use MySQL, or install unmodified version of MySQL on unlimited number of servers without any fees).
Which MySQL? As with any Open Source (GPL) software, there are many ways to obtain the same software package:
For MacOS X client version users I would like to recommend two types of precompiled MySQL packages:
Installing MySQL deb First of all you need to install Fink. Fink tutorial for beginners is available here ("Safe and Happy UNIX Hacking with MacOS X"). Then, run "sudo apt-get update", "sudo apt-get install mysql" in terminal. Precompiled MySQL deb will be downloaded from Fink site and installed with all other necessary dependent packages. Fink will add mysql user, create initial tables and set owner/permissions for MySQL data directory. To create startup item for MySQL run "daemonic enable mysql".
In order to deploy MySQL with extra features (like InnoDB transaction safe table support) or more recent version of MySQL than the one provided by Fink, you have to download or build custom MySQL deb yourself. Please follow this link to another article "Safe and Happy UNIX Hacking with MacOS X" for instruction how to build deb packages on MacOS X. MySQL data files may be found in "/sw/var/mysql" (visible but not accessible in the Finder). To make data directory accessible in read only mode run "sudo chmod go+rx+rx /sw/var/mysql". Installing MySQL MacOS X Native Package MacOS X native packages do not offer advantages of debs (easy upgrade, removal, etc.). If for some reasons you still not convinced,, just follow this instruction step by step.
Security Run "mysqladmin -u root password your-new-password" or "mysqladmin -u root -h localhost -p password your-new-password" in order to set up password for MySQL root user (do not be confused with MacOS X/UNIX root user, MySQL users and UNIX users are not the same entity)! Try to run "mysql -u root". If this command succeed, it means anyone can connect to your database with full privileges and do everything he likes! Additionally, never run MySQL daemon as UNIX root, only as mysql user! You should study "General Security Guidelines" from MySQL manual very carefully. Running MySQL Launch MySQL daemon from terminal with "sudo safe_mysqld --user=mysql &" (for 3.x version) or "sudo mysqld_safe --user=mysql &" (for version 4.x) command. You do not have to run this command if you have installed MySQL startup item and restarted MacOS X.
Installing PHP Now its time to install middleware which will allow to publish MySQL data on the Web. The most often used one (along with PERL/DBI) is HTML server-side embedded scripting language called PHP (stands as "Hypertext Preprocessor"). Server-side means that scripts are executed on the server, not on the client workstation (like JavaScript). With PHP its possible to generate HTML pages, simple graphic, PDF and Flash animation on the fly. Since MacOS X client runs Apache Web server, you will need only to install Apache PHP module and update Apache configuration file.
To check if PHP module is installed and enabled (it may be installed but not enabled), create a text file with line"<?php phpinfo() ?>" and save it in Users -> Your Home Directory -> Sites with the name test.php. Do not forget to enable Web Sharing in System Preferences!. Now launch Web browser and open URL "http://your-IP/~your-name/test.php" (if you are connecting on the same machine where you are running Web server, use "http://127.0.0.1/~your-name/test.php"). PHP test page displayed will confirm that everything is OK, and you may skip next section and proceed further, otherwise see instruction below. Quit Text Edit if its already running (you need to launch Text Edit in superuser mode in order to have enough privileges to modify UNIX configuration files), then run "sudo open -a TextEdit /etc/httpd/httpd.conf" in terminal. Text Edit will open Apache configuration file. Find lines "# LoadModule php4_module libexec/httpd/libphp4.so", "# AddModule mod_php4.c", "# AddType application/x-httpd-php .php" and "# AddType application/x-httpd-php-source .phps", remove hash marks (#), save configuration file, and finally run "apachectl graceful" (it will instruct Apache Web server to restart). Try to load again PHP test page as have been described above. Success means that PHP module was installed but have not been enabled by default. If not, you have to download and install PHP module yourself (module and comprehensive instruction are available here). In short, just run consecutively these commands in terminal: "wget http://www.access.ch/ml/software/macosx/libphp4.so.gz" (please wait for download); or if UNIX "wget" command is not available (it was removed in MacOS X 10.1), download "libphp4.so.gz" manually with your Web browser from Marc Liyanage Web site into Users -> Your home directory), then run "gunzip libphp4.so.gz" (to unpack module), "sudo apxs -i -a -n php4 libphp4.so" (to install PHP module, "apxs" stands as Apache extension tool), "apachectl graceful" (to restart Apache) . Now PHP test should work. If everything is OK you can safely remove (or archive) "libphp4.so.gz" and "libphp4.so" from your home directory. phpMyAdmin is a powerful Open Source (GPL) Web-based administration utility for MySQL server written in PHP. Create mysqladm user, login as mysqladm, download stable (not experimental) release of phpMyAdmin, unpack archive and drop all files and folders into Users -> mysqladm -> Sites (of course, you can do the same using UNIX commands in terminal without even re-login). Find and open file named "config.inc.php". Read in documentation how to properly setup phpMyAdmin, but for basic (insecure) configuration (when MySQL is running on your local workstation) you need to change only these variables: "$cfgPmaAbsoluteUri = 'http://127.0.0.1/~mysqladm';", "$cfgServers[1]['host'] = 'localhost';", "$cfgServers[1]['adv_auth'] = FALSE;","$cfgServers[1]['user'] = 'root';" and "$cfgServers[1]['password'] = 'your-mysql-root-password-here';". Set up permissions for "config.inc.php" as read-write for the group staff (so you do not have to login as mysql user or use "sudo" to modify this file), Turn on Web Sharing, logout, connect as ordinary user, and open URL "http://your-IP/~mysqladm/index.php" (or in case of local setup "http://127.0.0.1/~mysqladm/index.php"). phpMyAdmin screenshots on MacOS X client available here. WEBMIN Administration Software WEBMIN is very capable and popular Web-based administration software written in PERL. Along with MySQL, WEBMIN covers a lot of other UNIX administration needs. Although WEBMIN is advertised as being compatible with MacOS X Server, I do not know if it is compatible with MacOS X client (which, for example, does not include many popular PERL modules like DBI). Commercial MySQL Packages for MacOS X Commercial MySQL packages for MacOS X available from the company InterServices (SQL4X) and OpenOSX.com. SQL4X offers very easy installation procedure, and nice looking, powerful and capable GUI-based MacOS X native administration tools written with Cocoa. OpenOSX.com sells two MacOS X packaged bundles with MySQL - Database CD and OpenWeb. Both are created using Fink, so you may just download Fink and install all this stuff yourself. Its up to you to decide whether these extras worth the price of SQL4X ($65) or OpenWeb ($30). However, if you are serious to develop something with MySQL, you should learn how to use UNIX hacks. Freeware MacOS X Native Clients for MySQL So far I found only one freeware MacOS X native client for MySQL called EstellaSQL (formerly XmySQL) written by Max Cantor. EstellaSQL is a Cocoa based application. Shareware MacOS X Native Clients for MySQL If you are not satisfied with phpMyAdmin or EstellaSQL for some reason or they do not suit your specialized needs you may give a try MySQL Magic or SQL Boss. The last supports a wide range of Open Source and commercial SQL databases like PostgreSQL, OpenBase, FrontBase, as well as database connectivity interface ODBC. Visual MacOS X Native Tools for PHP and MySQL Visual MacOS X native shareware editor JaneBUILDER for PHP/MySQL is available thanks to Jane Weeeland. JaneBUILDER allows quickly build dynamic Web pages using mouse/menu driven interface. JaneBUILDER is a great addition to extremely popular and capable general purpose programmer's text editor BBEdit. Downloads MySQL deb for MacOS X is available for download here.
|