PHP GD MYSQL Apache

So I read most of the "penultimate-tutorial-to-installing-php-mysql-apache-gd-on-tiger" and you know what? They just don't work - most of those tutorials being about as useful as having a shovel of bat shite shoved up your left nostril. But many of them did provide pointers and after looking at a zillion of these tutorials, I managed to do the PHP with GD lirary, MYSQL and Apache on Tiger thang.
This may end up being one of those lousy tutorials but it works for me every time I need to set up clean on OSX Tiger - give it a whirl and if it does not work then be angry!
Before you start
Install the Xcode tools from the installation DVD that came with Tiger - Don't install the documentation if you don't need it and save yourself 733MB of disk space.
Installing the Xcode tools will install the compiler that you need to compile stuff - otherwise you will just end up with some "compiler not installed" or some similar annoying error message.
Installing MYSQL
Get "mysql-standard-4.1.11-apple-darwin7.8.0-powerpc.dmg" from mysql.com - mount and click on installer package.Create a file called ".my.cnf" (Don't forget the dot in front of the file name) with the following 3 lines and stick it in your /etc/ directory.
[mysqld]
datadir=/Volumes/store/data/websites/mysql_data
port=10101
Note that the "datadir" should point to your mysql data directory if you dont want it the default location. I wanted my mysql directory on a seperate volume which is why I do this - if you are just after a plain installation, you do not have to do any of the above.
At this point, you should really have some tool like InVisibles to show all invisible files on your hard drive (those beginning with a dot). When you do this however, many of your other file icons will look kind of faded out - I have no idea why this happens. You also get that annoying ".DS_Store" file everywhere - its the file which contains information on the folder that you are looking at.
Installing Apache
Apache actually comes with OSX Tiger - all you have to do ia a few wee tweaks
Under " /private/etc/httpd/ " you will find the "httpd.conf" file. Open it and uncomment the following 2 lines by removing the hash before them. Doing this allows you to use PHP by loading the PHP modules.
LoadModule php4_module libexec/httpd/libphp4.so
AddModule mod_php4.c
About half way down the httpd.conf file, you will see the following comment...
# This controls which options the .htaccess files in directories can
# override. Can also be "All", or any combination of "Options", "FileInfo",
# "AuthConfig", and "Limit"
#
AllowOverride None
Change where it says "AllowOverride None" to "AllowOverride All". This allows you to do stuff such as freely use mod_rewite - I put all my mod_rewrite comments in the .htaccess file. mod_rewrite is an Apache module which allows you to do a ton of things include feed the cat and rewrite URLS to be search engine friendly - more on how to do this in a future post. Don't worry about this if you don't know what I am babbling on about.
If you are developing a zillion sites on your machine - you should add virtual directories in httpd.conf. Near the bottom-ish of the httpd.conf file, you will see the following.
#
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for requests without a known
# server name.
#
Just below the above comment, you can add lines like the following...
Listen 1116
<VirtualHost localhost:1116>
DocumentRoot "/Volumes/store/guncannon/Sync/websites/somesite"
</VirtualHost>Listen 1117
<VirtualHost localhost:1117>
DocumentRoot "/Volumes/store/guncannon/Sync/websites/dannychoo/"
</VirtualHost>What this means is that I can have a site called "dannychoo" located at "/Volumes/store/guncannon/Sync/websites/dannychoo/" - I would access this site from my browser using "http://localhost:1117"
I can have another site called "somesite" located at "/Volumes/store/guncannon/Sync/websites/somesite" accessable on port 1116.
You can have as many sites set up this way in your httpd.conf file - just remember to restart apache after you make changes.
Two notes:
1. Restart apache using "sudo apachectl restart" - you have to make an alias first though (see bottom of this post)
2. Use a text editor like TextWangler to edit your httpd.conf file because other text editors may give you a crummy "do not have permission to save file."
Installing GD graphic Libraries
If you are going to manipulate images in PHP you need to install the GD libraries - namely the libjpeg and libpng source distributions.
Fire up Terminal located in your Utilities directory and do the following - "guncannon$" is my prompt - yours will probably be yourusername$
guncannon$ cd ~/Desktop
guncannon$ mkdir gdbuild
guncannon$ cd gdbuild
guncannon$ curl -O ftp://ftp.uu.net/graphics/jpeg/jpegsrc.v6b.tar.gz
guncannon$ curl -O http://heanet.dl.sourceforge.net/sourceforge/png-mng/libpng-1.2.5.tar.gz
guncannon$ gnutar xzf jpegsrc.v6b.tar.gz
guncannon$ gnutar xzf libpng-1.2.5.tar.gz
New we need to build libjpeg - get back to the terminal and do the following...
guncannon$ cd jpeg-6b
guncannon$ sudo mkdir -p /usr/local/include
guncannon$ sudo mkdir -p /usr/local/bin
guncannon$ sudo mkdir -p /usr/local/man
guncannon$ sudo mkdir -p /usr/local/lib
guncannon$ sudo mkdir /usr/local/man/man1
The above commands create directories that may be missing (for some reason) from your OSX Tiger. If for example you already have a "/usr/local/bin" directory - you Don't need to create it again.
Now that these directories are ready, time to lock, load, wash your armpits then build and install...
guncannon$ ./configure
guncannon$ sudo make install
guncannon$ sudo make install-lib
guncannon$ sudo ranlib /usr/local/lib/libjpeg.a
guncannon$ cd ..
Now that libjpeg is installed, we need to install libpng which is ever so slightly a pain in the left earlobe. Do the following at the terminal.
guncannon$ cd libpng-1.2.5
guncannon$ cp scripts/makefile.macosx ./Makefile
Now open the file "Makefile" that you just copied to your libpng-1.2.5 directory in TextWrangler.
Look for the following comments...
# Where the zlib library and include files are located
#ZLIBLIB=/usr/local/lib
#ZLIBINC=/usr/local/include
ZLIBLIB=../zlib
ZLIBINC=../zlib
Change the above so that it looks like the below...
# Where the zlib library and include files are located
ZLIBLIB=/usr/local/lib
ZLIBINC=/usr/local/include
#ZLIBLIB=../zlib
#ZLIBINC=../zlib
Now search for the following
LDFLAGS=-L. -L$(ZLIBLIB) -lpng -lz -current_version $(PNGVER)
and change it to...
LDFLAGS=-L. -L$(ZLIBLIB) -lpng -lz
Save the changes and then go and watch Gundam Seed Destiny. When you get back, go to the terminal again and unleash the following...
guncannon$ make
guncannon$ sudo make install
guncannon$ sudo ranlib /usr/local/lib/libpng.a
guncannon$ cd ..
Now everything up until now should have gone smoothly - if not then stick in a comment to this post and tell me how angry you are.
Building and Installing PHP
We are nearly there - in no time you will be making a ton of affiliate sites to pay for your expensive hobbies (like mountain climbing with a toilet strapped to your back - expensive stuff).
Time to fire up that terminal again and do the following...
guncannon$ cd ~/Desktop
guncannon$ mkdir phpbuild
guncannon$ cd phpbuild
guncannon$ curl -O http://museum.php.net/php4/php-4.3.6.tar.gz
guncannon$ gnutar -xzf php-4.3.6.tar.gz
guncannon$ cd php-4.3.6
The next step is to configure, build and install PHP. Enter the following
guncannon$./configure --with-xml --with-zlib --with-gd --with-jpeg-dir=/usr/local --with-png-dir=/usr/local --with-apxs=/usr/sbin/apxs
guncannon$ make
guncannon$ sudo make install
The above takes a bit of time to run after each command so go and make yourself a cup of tomato soup with croutons - everything should be ready when you get back.
If you are a bad programmer like me, you will want to erm turn global variables on (gulp) - You will need to configure your php.ini file - do the following at the terminal...
guncannon$ cp php.ini.default /usr/local/lib/php.ini
This makes a copy of the php.ini-dist file and saves it as php.ini in your /usr/local/lib/ folder. Open the file in TextWrangler and change the line where "register_globals = Off" to "register_globals = On"
And after you have done that, make sure you spend time learning how to program without using global variables - doh!
Other stuff to do
Create some aliases to make your life just that much easier.
alias mysqladmin=/usr/local/mysql/bin/mysqladmin
alias mysqld_safe=/usr/local/mysql/bin/mysqld_safe
alias apachectl=/usr/sbin/apachectl
Which now means you can....
guncannon$ sudo apachectl start
guncannon$ sudo apachectl stop
guncannon$ sudo apachectl restart
guncannon$ sudo mysqld_safe (starts mysql)
guncannon$ mysqladmin -u root shutdown (stop mysql)
I hope this works for you as it worked for me on a clean installation of Tiger. If it does not work then you are permitted to get all wound up as I did reading other bods tutorials on the same subject.
If you are interested in reading about life in Japan, seeing photos taken daily around Tokyo, like Japanese subculture (anime, manga, figures, Dollfies) then you may want to start delving into the Japan or Figure categories for a start or have a gander at all photo articles.
If you don't have much time now, maybe subscribe to the RSS Feed, Twitter Feed or join the other readers in the FaceBook Page.
Alternatively, you may want to read more about the site.
If you are a regular reader then this message will probably annoy you each time - hide it forever.
-Akihabara News – Gadgetry from Japan (Subscribe)



















