PHP Local Setup

external links: index . projects . home

in-file links: preamble - install - vista - fastcgi - xp - ubuntu - end

Preamble

For quite some time I have wanted to setup PHP to run locally, so I can fully locally test the script before uploading it to this site ... Well I eventually had some success, in Windows Vista (32-bits), and of course Ubuntu ... Of course, previously I could do 'command-line-testing' - that is I could use the c:\php\php.exe to read the php script and output HTML ... like -

cmd-prompt> php test.php > test.htm
cmd-prompt> start test.htm

This indirect method allowed me to do some basic testing, but not directly through using a browser. With my new Vista Ultimate (32-bits), with a dual boot with Ubuntu linux, gave me a chance to re-visit this ...

Installations

1. PHP

This is relatively easy ;=)) The main php site, [ http://php.net ] will have a link to download the latest stable version for windows. And usually offers two windows binaries - msi installer or manual zip. While the 'windows msi installer package makes it very easy, it seems its default install location is the usual 'Program File' - I chose to put PHP in a C:\php folder, and does not seem to include all the PHP Extensions (PECL), but there is a separate download for this.

Alternatively, the zip file represents a manual install, and does seem to include most PECL modules ... as above this zip can be unpacked directly into, in my case, the C:\php folder.

The next step is to manually adjust the php.ini file. While the installation places this in the C:\php folder, I learned later, to be able to use some extensions through the browser interface, it seem this MUST be in the %SystemRoot% folder, usually C:\Windows ... Below is a 'diff -u' of the php.ini-recommended from the zip file, and my final php.ini, that could be used to 'patch' a php.ini, but these modifications are better done manually with a suitable editor!

Another alternative, if you do NOT intend to us MS IIS, is to install WAMP (Apache, MySQL and PHP on Windows) from the WampServer site ... This did use a default C:\wamp folder for each of the installations.

If you intend to run php from the command line, and maybe even if you don't, then the path to php.exe should be added to the PATH environment variables - Start -> Control Panel -> System and Maintenance -> System -> Advanced System Settings -> [ Environment Variables ] button, and I put it in the 'System variables', rather than 'User variables for ....' - Select PATH, and click [ Edit ... ], and add the full path to php.exe after a semi-colon. It does not seem necessary to add a trailing back-slash ...

2. IIS7 (Microsoft Internet Information Services, version 7)

IIS7 is not installed by default, but should be available in your windows vista distribution. Click Start -> Control Panel -> Programs -> Turn Windows features on or off. In the Windows Features dialog, expand - click on the + - Internet Information Services. There is/was a brief video that explains all this here ... this excellent movie puts it all in simple terms. In the event that this site 'disappears' you can download a local copy, iis7_vista.wmv (27MB)...

When correctly installed, putting the following in a browser address line, and clicking 'Go', or clicking this link -

http://localhost

should bring up the IIS7 default page, which will probably be found in C:\inetpub\wwwroot ... this default location, which is write protected without administrator privileges can be changed by Start -> Control Panel -> System and Maintenance -> Administrative Tools -> Internet Information Services (IIS) Manager - which can also be loaded by Start -> Run ... -> inetmgr <enter>.

In the IIS Manager, expand the Connections on the left, and expand Sites and select 'Default Web Site', then on the right 'Actions', click 'Basic Settings...', and adjust the Physical path: to where you want the default web pages to be. Of course, you must put some pages there first. I chose a path of least resistance, C:\Users\username\www ;=))

I use MS Visual Web Developer 2008 Express Edition to create and modify my web pages, but it does not seem to do too well with scripts like php, and I have a small editor I purchased, EditPlus 3, which does very well with lots of page formats ...

top


Windows Vista

In general, I have had good success with enabling PHP in my Windows Vista machine. As installed above, this sports IIS7 (MS Internet Information Services, version 7), and after reading lots and lots of places got it to where I can put in a browser's address line :-

http://localhost/info.php 

with the info.php file containing only the line :-

<?php
  phpinfo();
?> 

and I get the LONG list of PHP variables, etc ... that is, it works as it should ...

I do sometimes get a little dialog that say some IIS component had a problem, and had to be shut down, but the main part seems to continue to work anyway, so not sure exactly what this message is all about ...

I did also TRY to set up a 'Virtual Host', but have NOT had much success with that yet ... I can configure it, but can not even get the index page to show up in a browser ... I will keep working on this ...

Anyway, with IIS7 now running (mostly), I may consider embedding some php, or even fully converting some of my web pages to PHP, instead of the current HTML ... as explained, in PHP you can have one common header file, and one common tail file that can be included in every page ...

This means your pages can all have a 'standard' theme, and each new page only needs its specific content to be done ... the actual main PHP site - http://php.net - is a very good example of this ... every page you go to has the SAME blue header with link menu, and tail with links ... and their online documentation of all the PHP functions is excellent, EXCELLENT ;=)) ... not only do they clearly describe the function, but there is nearly always some user added examples at the bottom ...

The actual setup in Vista was quite involved. It started with Start -> Control Panel -> Programs -> Turn Windows features on or off. In the Windows Features dialog, expanding - click on the + - the Internet Information Services item, and enabling the 'Web Management Tools' ...

And now I have the ability to fully test PHP locally BEFORE uploading it to my GoDaddy WWW server pages ...

PHP via IIS7 CGI versus FastCGI (Common Gateway Interface)

All the above setup has been installed and uses the php php5isapi.dll ... in this standard CGI each http request opens, runs and close a process. In FastCGI mode the process first opened is maintained, and thus the requests handled per second can be greatly enhanced. In a video, (local), it rose from requests of 2/Sec to around 50/Sec, a significant performance boost. Even further speed is possible by setting up IIS output caching, up to around 850/Sec.

In that same video, it was suggested that the non-thread safe php-cgi.exe been downloaded and used, but in another video, (local), the normal thread-safe module was used.

top


Windows XP

Unfortunately can NOT get this working yet. It seems this XP only has IIS5, and I am still researching HOW to update it to IIS6 or even IIS7 ... I have unfortunately read some web sites that suggest such an update is NOT possible, but I am not sure I fully believe them yet ... but getting there ...

It seems IIS6 was an IIS upgrade put in Windows Server 2003, which came out after XP, and maybe XP is stuck with that now quite old IIS5 ???

I have tried and tried to configure it, IIS5, to run PHP scripts, but have so far failed, Failed, and FAILED, every time ;=((

top


Ubuntu Linux

Here, I got immediate success after I installed LAMP into my Ubuntu, but now that OS will not shutdown properly = YUCK!!! = and I have to use the POWER BUTTON to switch it off ... so it is not ALL success ... but am working on 'fixing' this ...

But at least the localhost works, using PHP scripts ...

top


php.ini.diff [up]

top


Hope this helps ...

Geoff.
Sunday, June 09, 2008.

top


checked by Tidy  Valid XHTML 1.0 Transitional