« Error: 404 | Main | Time Killing Game: Flow »

March 11, 2006

PHP

I found a slick random image generator that I want to use, but it requires the Hypertext Preprocessor PHP. PHP is a server-side HTML embedded scripting language for building dynamic websites. So, I figured I could probably find a Perl random image generator, or a java script random image generator, but it won't hurt to install PHP, so I figured I'd do that first.

1. Download the PHP binaries

I found a site that explains How to Install and Configure PHP4 to Run with Apache on Windows. First, I went here and downloaded the latest version for windows as a .zip file. The website warned me that the .exe installation version didn't include the files necessary to run with Apache. C:\php512\php-5.1.2-installer.zip.

2. Installing PHP

I extracted all of the files into the c:\php512 directory.

3. Configuring PHP

I copied the php.ini-dist file to the windows and renamed it to c:\windows\php.ini

I edited the php.ini and changed the [mail function] as follows:

[mail function]
SMTP = mail.wispertel.net
smtp_port = 25
sendmail_from = peeniewallie@wispertel.net

I also set the register_globals on:
register_globals = On

4. Configure Your Apache Web Server

I've already done this.

4.a Running PHP as an Apache module

To configure Apache to load PHP as a module to parse your PHP scripts, use an ASCII text editor to open the Apache configuration file, "httpd.conf", typically found in "c:\Program Files\Apache Group\Apache\conf\".
So, I added the following line after all of the other LoadModule lines in the httpd.conf.

LoadModule php5_module "c:/php512/php5apache.dll"

Then, I added this line in the AddType section:

AddType application/x-httpd-php .php

Then I changed the DirectoryIndex by added index.php.

DirectoryIndex index.php index.html index.html.var index.cgi

Then, I saved the httpd.conf file and tried to restart the Apache server, but it failed:
The problem is that Apache didn't like this line in the httpd.conf file:

LoadModule php5_module "c:/php512/php5apache.dll"

Doh! I changed it to this:

LoadModule php5_module "c:/php512/php5apache2.dll"

Now it's working.


5. Testing Your PHP Installation

So, to test my php installation, I created the following one-line program and saved it as phpinfo.php:

And, I tested it http://www.peeniewallie.com/php/phpinfo.php

http://www.peeniewallie.com/phpinfo.php

Voila! PHP is working.

However, when I began having problems with my PHP4 script, I realized that PHP5 is different than PHP4, so I decided to try to install PHP4 also. So, I basically repeated the steps above and installed PHP4 in the directory c:\php422.

In the httpd.conf, I added:

LoadModule php4_module "c:/php442/sapi/php4apache.dll"

and

AddType application/x-httpd-php .php4


But, then, I started getting errors:
Cannot load C:/php442/sapi/php4apache2.dll into server: The specified module could not be found.

Apache wouldn't restart. It basically kept complaining that it couldn't find the php4apache2.dll

Eventually, I found this post, which mentioned copying the php4ts.dll to the c:\windows\system or c:\windows\system32 folder. So, I tried it and it worked. (You can put it in either folder. I ended up putting it in c:\windows\system).

OK. So, I got PHP4 working. But I'm still having a horrendous time trying to get this stupid php4 script to work. I'm now beginning to think that it's because I don't have my php extensions loaded. I get this error in my Apache log:

Call to undefined function: imagecreate()

This site http://www.modwest.com/help/kb5-100.html:

It is likely that you are using a function from a dynamic extension module that you do not have loaded. We've compiled php with all extensions compiled as shared objects. By default, only the mysql module is enabled. This other FAQ tells you how to enable and load modules.

When you try to use a function that is not part of the core PHP and you have not loaded the module for it, you will get an error like:

Fatal error: Call to undefined function: imagecreate()

In order to fix this, you just need to load the extension module that contains this function. In this example above, it would be the GD module, which you could load by uncommenting
; extension = gd.so
in your php.ini by removing the semicolon from in front of the line...

So, I uncommented this line in my c:\windows\php.ini file:

extension=php_gd2.dll

But, I still can't get it to work. So, I copied this php_gd2.dll into my c:\windows\system. Still no dice. I restarted my Apache server. Finally. A different error message. Now, my web page shows a maroon rectangle with the words Image File Not Found! And, a check in the log shows that it's not freaking out about the imagecreate function any more. So, apparently, you need to move these .dll files into c:\windows\system folder, uncomment them from the php.ini file, and then restart the Apache server.

So, I basically uncommented all my extensions, copied them all into c:\windows\system, and restarted Apache. I got lots of errors, but I feel better now.

Now, am debugging this error:

PHP Warning: opendir(www.peeniewallie.com/random/): failed to open dir: Invalid argument

http://www.codecomments.com/archive221-2004-11-332212.html

So, I went back to the original program that this genius had copied. I'm closer to getting this original version working. I'm down to jus t 1 error:

PHP Notice: Undefined variable: image

Simple Picture Gallery Manager

Posted by Peenie Wallie on March 11, 2006 at 9:42 AM