Pages

Hello PHP

Writing an hello program for PHP is quite straighforward. It just takes a bit to setup the environment, expecially if you are using a Windows machine.

I use Apache as HTTP server, version 2.2, actually. Since the target operating system is Windows, I downloaded the msi installer - that makes the installing job a bit easier.

The only change I made is about the starting/stopping. I changed the Apache2.2 service start mode to manual, and I wrote a couple of tiny script to do the job - but I could have used the cool Apache tool on the tray-bar, instead.

In any case, here is the two one-liner that start and stop the service (they required to be executed by an user having administrator priviledges):

net start Apache2.2

net stop Apache2.2

Then I downloaded PHP for Windows/Apache. Notice that for Apache you need the VC6 version, and not the VC9. I got again the msi, expecting to have less job to do in this way.

Actually, something went wrong, and after installing PHP, Apache did not startup anymore. I had a look at the Apache configuration file, conf\httpd.conf, and I found out that the PHP section was wrong - I had to correct manually the directories in this way:

#BEGIN PHP INSTALLER EDITS - REMOVE ONLY ON UNINSTALL
PHPIniDir "C:/dev/PHP"
LoadModule php5_module "C:/dev/PHP/php5apache2_2.dll"
#END PHP INSTALLER EDITS - REMOVE ONLY ON UNINSTALL

Notice the use of forward slash and not the "windows style" backslash. Obviously the pathname could be different in your setting.

In any case. Done that, I could run my hello php file. I put in the Apache htdocs directory a file named hello.php with inside just this line:
<?php phpinfo(); ?>
The result is a huge HTML page with lot of information on the current PHP configuration.

No comments:

Post a Comment