Converting a Mini to a Server, Part 3: MySQL and PHP
To summarize what has gone before, I now have headless, network access to a Mac X86 Mini, and have successfully installed Apache 2.0.55. The next step is to install MySQL, PHP, and WordPress; then copy The Cafes and elharo.com from the old server to the Mini.
First up, MySQL. This almost couldn’t be easier. MySQL AB publishes a precompiled binary for X86 Macs, and it’s installed using the usual Mac installer. This is about the easiest server side install I’ve ever had to do. The only thing that could be better would be to not include a separate install for the autolauncher. Oh, and it should probably ask you for a database root password while installing rather than letting it be set later. Let’s do that before I forget:
mini:/usr/local/mysql elharo$ ./bin/mysqladmin -u root password mynewpassword
mini:/usr/local/mysql elharo$ ./bin/mysql -u root -pmynewpassword
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 5 to server version: 5.0.18-standard
Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the buffer.
mysql> DELETE FROM mysql.user WHERE User = ”;
Query OK, 2 rows affected (0.00 sec)
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)
But honestly these are nickel-and-dime issues compared to what you have to go through with most server side software.
Next up is PHP. I’ll need to build this one from source.
mini:~/Desktop/php-5.1.2 elharo$ ./configure –with-apxs2=/usr/httpd/bin/apxs –with-mysql=/usr/local/mysql –prefix=/opt/php5 –with-libxslt –with-tidy
creating cache ./config.cache
checking for Cygwin environment… no
checking for mingw32 environment… no
…
creating main/internal_functions_cli.c
+——————————————————————–+
| License: |
| This software is subject to the PHP License, available in this |
| distribution in the file LICENSE. By continuing this installation |
| process, you are bound by the terms of this license agreement. |
| If you do not agree with the terms of this license, you must abort |
| the installation process at this point. |
+——————————————————————–+
Thank you for using PHP.
Now onto make:
mini:~/Desktop/php-5.1.2 elharo$ make
/bin/sh /Users/elharo/Desktop/php-5.1.2/libtool –silent –preserve-dup-deps –mode=compile gcc -Iext/libxml/ -I/Users/elharo/Desktop/php-5.1.2/ext/libxml/ -DPHP_ATOM_INC -I/Users/elharo/Desktop/php-5.1.2/include -I/Users/elharo/Desktop/php-5.1.2/main -I/Users/elharo/Desktop/php-5.1.2 -I/usr/include/libxml2 -I/Users/elharo/Desktop/php-5.1.2/ext/date/lib -I/usr/local/mysql/include -I/usr/include/tidy -I/Users/elharo/Desktop/php-5.1.2/TSRM -I/Users/elharo/Desktop/php-5.1.2/Zend -no-cpp-precomp -I/usr/include -g -O2 -c /Users/elharo/Desktop/php-5.1.2/ext/libxml/libxml.c -o ext/libxml/libxml.lo
/Users/elharo/Desktop/php-5.1.2/ext/libxml/libxml.c: In function ‘php_libxml_streams_IO_open_wrapper’:
/Users/elharo/Desktop/php-5.1.2/ext/libxml/libxml.c:264: warning: pointer targets in passing argument 1 of ‘xmlParseURI’ differ in signedness
/Users/elharo/Desktop/php-5.1.2/ext/libxml/libxml.c:265: warning: pointer targets in passing argument 1 of ‘xmlStrncmp’ differ in signedness
/Users/elharo/Desktop/php-5.1.2/ext/libxml/libxml.c:265: warning: pointer targets in passing argument 2 of ‘xmlStrncmp’ differ in signedness
/Users/elharo/Desktop/php-5.1.2/ext/libxml/libxml.c: In function ‘_php_list_set_error_structure’:
/Users/elharo/Desktop/php-5.1.2/ext/libxml/libxml.c:433: warning: pointer targets in passing argument 1 of ‘xmlStrdup’ differ in signedness
/Users/elharo/Desktop/php-5.1.2/ext/libxml/libxml.c:433: warning: pointer targets in assignment differ in signedness
…
/Users/elharo/Desktop/php-5.1.2/ext/tidy/tidy.c:1084: warning: pointer targets in initialization differ in signedness
/Users/elharo/Desktop/php-5.1.2/ext/tidy/tidy.c: In function ‘zif_tidy_get_output’:
/Users/elharo/Desktop/php-5.1.2/ext/tidy/tidy.c:1100: warning: pointer targets in initialization differ in signedness
make: *** [ext/tidy/tidy.lo] Error 1
Hmm, those libxml warnings are troublesome. I wonder if Tidy and/or libxsl assuming something they shouldn’t be about the signedness of a Mac? I don’t think I have to have libxsl or libtidy right now so let’s reconfigure and try again without them.
mini:~/Desktop/php-5.1.2 elharo$ make clean
find . -name \*.lo -o -name \*.o | xargs rm -f
find . -name \*.la -o -name \*.a | xargs rm -f
find . -name \*.so | xargs rm -f
find . -name .libs -a -type d|xargs rm -rf
rm -f libphp5.la sapi/cli/php libs/libphp5.bundle modules/* libs/*
mini:~/Desktop/php-5.1.2 elharo$ ./configure –with-apxs2=/usr/httpd/bin/apxs –with-mysql=/usr/local/mysql –prefix=/opt/php5
loading cache ./config.cache
checking for Cygwin environment… (cached) no
checking for mingw32 environment… (cached) no
checking for egrep… (cached) grep -E
checking for a sed that does not truncate output… (cached) /usr/bin/sed
checking host system type… i686-apple-darwin8.5.3
checking target system type… i686-apple-darwin8.5.3
checking for gcc… (cached) gcc
…
Build complete.
(It is safe to ignore warnings about tempnam and tmpnam).
OK. That worked. I’ll have to remember that I don’t have libtidy or libxslt installed in this. Finally install:
mini:~/Desktop/php-5.1.2 elharo$ sudo make install
Password:
Installing PHP SAPI module: apache2handler
/usr/httpd/build/instdso.sh SH_LIBTOOL=’/usr/httpd/build/libtool’ libs/libphp5.so /usr/httpd/modules
/usr/httpd/build/libtool –mode=install cp libs/libphp5.so /usr/httpd/modules/
cp libs/libphp5.so /usr/httpd/modules/libphp5.so
Warning! dlname not found in /usr/httpd/modules/libphp5.so.
Assuming installing a .so rather than a libtool archive.
…
Wrote PEAR system config file at: /opt/php5/etc/pear.conf
You may want to add: /opt/php5/lib/php to your php.ini include_path
Installing PDO headers: /opt/php5/include/php/ext/pdo/
OK. Let’s load up a simple PHP page and see if PHP is working or if I need to restart Apache or some such. Nope. Doesn’t work. It’s just displaying the PHP file, not interpreting it. Let’s restart the server. OK. Now something’s changed. It isn’t showing anything at all instead of showing the PHP source code. At least that means it understands there’s something didfferent about a .phtml file. Let’s look in the error log and see what we see. [Tue Mar 07 13:46:33 2006] [notice] child pid 18205 exit signal Bus error (10)
[Tue Mar 07 13:46:37 2006] [notice] child pid 18206 exit signal Bus error (10)
[Tue Mar 07 13:46:51 2006] [notice] child pid 18207 exit signal Bus error (10)
Could that be the problem? Let’s reload the .php page one more time and see if that adds an error. Yep, that’s it all right. Now the question becomes, why is that happening? Googling on the error message is sometimes productive. This thread may be relevant, but doesn’t seem to have a definite answer.
OK. Figured it out. I hadn’t installed a php.ini in /usr/ocal/lib. You’d think that would have been installed by default but I guess not. But now it’s back to showing the PHP source code? Why?
OK. Figured that out. I had not yet added the line
AddType application/x-httpd-php .php .phtml
to httpd.conf. Again the installer should have done this, but it didn’t. Believe it or not, it took me longer than it should have to figure out the problem because of yet another variation of the nastiest bug. This time, I had httpd.conf files from two different web servers open in several different terminal windows, and I checked for the AddType line in what I thought was the new server but was in fact the old server.
In any case, I now seem to have a functioning Apache 2/MySQL 5/PHP 5 system compiled natively for the Mac Mini. The next step is to set up the virtual hosts, install WordPress in each one, and load the old data. This seems like as a good a time as any to update to the latest version of WordPress, and since I have it on good authority that 2.0.2 is coming out very soon, I think I’ll wait for that before moving ahead.
March 9th, 2006 at 1:15 PM
1) Are these books you actually have and recommend, or is this some kind of adwords system? It would be helpful if you always said “I recommend these books” if that’s the case.
2) Will you be giving us your insights as you learn PHP? I for one would be very interested.
March 9th, 2006 at 1:38 PM
It’s more like AdWords. The only one of these I’ve read myself amd still use is the Practical SQL Handbook. Possibly I’ve skimmed a couple of the others once or twice.
I don’t have a lot to say about PHP. It’s just a simple tool I pull out for occasional simple server side tasks. WordPress is written in it. That’s why I’m using it here. I chose WordPress, not PHP.
March 11th, 2006 at 8:30 PM
I had been trying to do exactly the same as you (put the latest AMP environment on to my Mac Mini) and I found your notes really useful. Thanks!
April 10th, 2006 at 3:25 PM
Interesting that someone uses a Mac Mini as server. I am thinking of doing it for myself, too. But I disagree with some things:
“[MySQL configuration] But honestly these are nickel-and-dime issues compared to what you have to go through with most server side software.”
I’d say no. It doesn’t really matter if you get a compilation error when installing Apache or PHP, it just takes some extra time. But leaving the root account of the database open by default is extremely dangerous. If you’re a newcomer to AMP chances are great that you leave this huge security hole open.
“Again the installer should have done this, but it didn’t.”
Again, no. :) The apache configuration architecture is already a mess. Having an installer that changes httpd.conf is bound to create a completely unmanageable situation, where you don’t really know what’s happening behind the scenes. That’s dangerous on a server.
And just one more thing, a small advice: Take backups frequently. I know two people who’ve got a Mini, me and my friend. I know about two crashed Mac Mini hard drives..
April 10th, 2006 at 4:07 PM
One of the nice things about using a Mini as opposed to Linux is that it fits very nicely into my Retrospect based backup system.
December 31st, 2006 at 9:49 PM
Wikipedia is the key to most success online, when it comes to collabritive content adding. I have spent many hours writing articles for Jimmy Wales and am very happy with this project. I am based in Seminole FL close to the wikipedia offices in St Petersburg. I love contributing!
Happy New Year Bloggers!