Portable Development - PHP
So now we have an Apache instance on a USB Key. Great. Can’t do much with it, other than brochureware, so our next step is to get PHP working.
Fortunately, the nice people at PHP provide Windows Binaries in a zip file. No messing with installers and then re-copying everything. Just go and grab the latest stable Windows Binary Zip of PHP from their downloads section. This can then just be extracted into /development/php.
I’ve gone for PHP5, later, I’ll show you a quick change to the portable environment I have that enables me to test Geeklog on PHP4 as well. (I use my portable environment for the stuff I do to Geeklog too, and that needs to support older PHP versions).
We have to edit a couple of files to get this to work on the key. Firstly, we need to configure the php.ini file to support our environment. Again, the first step here is to change paths to relative ones. Simple job of finding all the paths and editing them. Boring hey?
We then have to edit the httpd.conf file again to get it to load PHP:
LoadModule php5_module "/development/php/php5apache2.dll" addtype application/x-httpd-php .php .php4 .php5 .php3 .htm .inc .fire PHPIniDir "/development/php/php.ini"
Once that’s done, we can shut down and re-start. We also need a test php file to be sure whether or not the PHP instance is working, this is done by creating a new file called phpinfo.php, dropping it onto our web root and putting the following code into it:
<?php phpinfo(); ?>
We then visit that url in our browser: http://localhost:8080/phpinfo.php and should see a nice page telling us all about how our PHP instance is configured.
We don’t really want to leave things there, there are a number of further configuration options that it’s worth getting out of the way now, since we’re tuning for development not production and the sample distributed php.ini is a sensible startign point for a production server.
The main thing we need to turn back on is error reporting to screen and log. Both of runtime and startup errors. As we add and remove extensions and as we code, we need to know in real time that errors are happening:
display_errors = on display_startup_errors = on log_errors = on
The magic_quotes_gpc directive is an interesting one. It’s there to protect the not so great programmers from common attack vectors. I turn it off, always, and make sure that I work round the case where it’s on. This means I have to turn it on to test. But I keep it off for development. Geeklog (an open source project to which I contribute) works with it on or off. I write my applications to work with it in either state, but, I prefer to have it off, because it saves resource and I trust my code to protect my code better than the magic_quotes_gpc setting.
If you are not sure whether you want it on or off, find out what your production host has set, and use that.
With PHP5 you need to ensure that the mysql extension is loaded (remove the ; which has commented it out), and in preparation for our mobile MySQL on USB instance, we’re going to change the default MySQL port in the MySQL area of the ini file.
extension=php_mysql.dll
and
mysql.default_port = 3306
And that should be it, a fully working, development adjusted PHP5 in Apache instance set up and ready to go.
Popularity: 44% [?]









