logic_earth — 2009-10-25T14:33:20-04:00 — #1
Installing PHP (5.3 currently) on Windows
Installing Apache HTTP Server
Installing Internet Information Services
There is certainly a lot of different way to installing PHP or configuring it under different servers or platforms, most seasoned developers will probably have their own variations on it. This guide is going to cover but a few possible always of installing PHP using the author’s (of this guide) variation. Covers Apache using mod_php, Internet Information Services (IIS) 7 which is available on Windows Vista, Windows 7, and Windows Server 2008 using FastCGI. To a lesser extent in future revisions, IIS 5.1 included with Windows XP Professional, IIS 6 included with Windows Server 2003 will be added.
This guide does not cover MySQL. It might be added in future revisions, however, there are no plans.
Setting up the Environment
Having a good environment is a big plus to running a development server on your personal computer. While leaving the default settings for Apache and PHP, and saving the file you need in your Documents folder is perfectly fine. However, that seems all rather messy and inconvenient. This section of the guide is completely optional, giving a few pointers and ideas to create your own environment that suits you.
Having everything to do with the servers and your websites or projects under a single location can aid in backups and management. For example take this particular directory layout: (Aside from keeping Apache and PHP out of Program Files, keeps UAC prompts to a minimum during configuration.)
C:\Work\workspace\environment\http-service would hold Apache if you were going down that route. For this case sandbox referrers to the default localhost location a playground of sorts. Having configuration files for PHP and/or Apache here, instead of C:\Program Files lets you manage them without elevating an application (UAC) in Windows Vista or Windows 7. For this guide, the above directory structure will be used, except will be on its own drive (W: Drive).
logic_earth — 2009-10-25T14:34:23-04:00 — #2
First thing that needs to be done before installing. We need to download PHP which is available from: http://windows.php.net/download/. Ever sense the deal between Microsoft and Zend some years ago running PHP on Windows never been better. PHP 5.3 brought about a lot of new methodologies in PHP’s development making Windows a first-class citizen among UNIX and Linux. However, some confusion comes with this direction, evident by the choices to download. We have VC9 x86 Non Thread Safe and Thread Safe then there is VC6 x86 Non Thread Safe and Thread Safe. So what is the difference? (Will have x64 version in the future.)
VC9 was compiled with Visual C++ version 9 or under a more commercial name Visual Studio 2008. VC6 is the legacy compiler of Visual Studio 6 (4 versions behind, soon to be 5.) The VC9 binaries have a lot of improvements in performance and stability. However, we cannot use the VC9 binaries with Apache’s still VC6 binaries so we must use VC6.
Now for thread safe and non thread safe, it stems from the different architecture of Windows being a thread to processor model instead of process to processor model in Unix/Linux systems. Apache will require thread safe binaries for modules, while CGI uses and benefits from non thread safe binaries. The reason for this, Apache modules are threaded from a single executable, while CGI launches an executable for every request.
So which version to download? Well are you going to use Apache or IIS? Apache module or CGI? Apache module: VC6 Tread Safe, Apache CGI: VC6 Non Thread Safe. For IIS we are going to use FastCGI; VC9 Non Thread Safe will work fine for our needs. When downloading get the ZIP archive.
Extract the PHP ZIP file to W:\workspace\environment\language\php\5.3.0, or substitute your own location. PHP is now installed, pretty simple. Okay well it is not really complete we still need to do some configuration. Make a copy a php.ini-developmet and rename it php.ini there is only a few settings that need to be changed: extension_dir, upload_tmp_dir, session.save_path. Noticed all of these directive deals with paths? While I can tell you where to point extension_dir, the other two are more subjective. Could point those two towards W:\ emp\sessions and W:\ emp\uploads. For extension_dir set it to just “ext” if that does not work use the full path: W:\workspace\environment\language\php\5.3.0\ext.
There is just one last step if you are using the VC9 binaries. You need to download Microsoft Visual C++ 2008 Redistributable Package: http://www.microsoft.com/downloads/details.aspx?FamilyID=9B2DA534-3E03-4391-8A4D-074B9F2BC1BF&displaylang=en
Too make sure PHP is ready to perform, SHIFT + Right-click on the installation folder for PHP, select “Open command windows here” (available in Windows Vista and 7). You should get a command prompt, enter “php –v” should get version numbers if everything is working.
logic_earth — 2009-10-25T14:38:24-04:00 — #3
Installing Apache HTTP Server.
At the time of this guide, the current version for Apache is 2.2.14. Future versions within the 2.2.x branch should—or might be rather—be compatible with this guide. Before we get started when need to make sure we get all the required files and downloads. First lets head on over to Apache’s site, http://httpd.apache.org/download.cgi. For this particular guide “Win32 Binary without crypto (no mod_ssl) (MSI Installer)” is going to be used.
Apache uses a graphical installer so at this point this going in going to break down into a few screens shots and notes for key points. When you start the installer it will give a few non-essential steps which should require no explanation what to do. When you get to the screen below, we’ll cover a few key points.
Network Domain, Server Name, and Email all of them can be set to anything pretty much as long as there are no spaces or invalid characters. Down below the text fields you have a couple options how you want Apache to start. Automatic or manual? Installing it as a Service will start Apache when the computer starts, don’t even need to login. The second options should of course be self explanatory.
For most cases you could just skip this step and pick Typical for the installation type this will satisfy most. For the sake of this guide, Custom is going to be chosen it will also give you a chance to see what options you have.
The above screen is not set at the default settings, a lot of the stuff installed in useless if you are not in need of them. However, if you are not sure it is best to leave them as is. You won’t save a whole lot of HDD space either way. The real important part is where you are installing Apache to. You will need to enter this directory later on to configure Apache. My recommendation is not to install it to C:\Program Files, this location as a few of its own problems to deal with. Just to modify any files you must have Administrative privileges, this requires invoking your text editor with “Run as” and navigating from there.
After installation, open your favorite web browser and enter: http://localhost/ into the address bar. You should see “It Works!” on screen. Congratulations Apache is installed and running—a bit default configurations.
There is not a whole lot to configure at this time other then setting our own “htdocs” location. Having this folder located in Apache’s directory isn’t all that ideal. For this guide W:\websites\sandbox will be used. Head into “conf” inside Apache’s installation directory, then open httpd.conf. We need to alter DocumentRoot and one of the <Directory> blocks (the second one after DocumentRoot). To keep things simpler change Options, and AllowOverride in the same <Directory> block, add “All” to both. Minus the comments should have something similar to below:
Options All Indexes FollowSymLinks
Allow from all
Scrolling all the way down there is a few include statements, just a few need to the hash (#) to be removed. Server-pool management, Multi-language error messages, Fancy directory listings, Language settings, Various default settings. That should cover most configurations out of the box.
Every time you modify Apache’s configuration you must restart the server. There are several ways to do this, in Windows Services Manager, shortcuts Apache installed in the start menu, or if you installed the “Apache Service Taskbar Icon” it can be done there. Remember to always restart after any changes.
If you kept the default installation location for Apache, in C:\Program Files then before editing httpd.conf you either need to run your text editor as Administrator, or make a copy on your desktop then move it back into the conf folder.
Adding PHP as an Apache Module
Setting up PHP for use with Apache is a simple matter of making some blank space at the bottom of httpd.conf and adding a few lines.
LoadModule php5_module "W:\\workspace\\enviroment\\language\\php\\5.3.0\\php5apache2_2.dll"
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
Once done, restart Apache then create a PHP file in the sandbox directory with: <?php phpinfo();then access that file from the browser. You should be greeted with a long page of information.
logic_earth — 2009-10-25T14:42:42-04:00 — #4
Installing Internet Information Services
You probably heard a lot of bad things about IIS, from various groups. If you were holding off using IIS because of that well now is the time to re-evaluate IIS with version 7. A lot of the problems that plaques IIS were cured way back in IIS 5. Introduced in IIS 7 was a new architecture similar to Apache with its modules. Everything in IIS 7 is a module, an extension that can be removed. Just need a basic HTTP server? No problem! Just remove or deactivate everything but the HTTP service module.
Where do you get IIS? You already have it if you are running Windows Vista Home Premium, Business, Ultimate, or Windows 7 under the same SKUs as Vista. It is also on Windows Server 2008. There are some limitations to be aware of. On Windows Vista and Windows 7 Home Premium is limited to 3 con-current request, Business/Professional, and Ultimate are limited to 10. However this limit will never come into play because this server is for development not production.
Enabling IIS we need to open Windows Features, it can be found in the Control panel in various locations under the name “Turn Windows features on or off” instead of wasting time traversing though the Control Panel open the start menu and use the search box. Typing the first few letters of “turn windo” will bring up the desired item.
Just by selecting “Internet Information Services” will add most of the required defaults, explorer around the list for anything you might think you would like to add. There is one area we do require to change, open the tree for “Application Development Features” you want to enable .NET Extensibility, and CGI. It should take but a moment to fully install.
Windows Features will close once it is done, opening your favorite browser and head to: http://localhost/ should let you know IIS is up and running.
There are two ways to configure IIS, one is to use the GUI control panel, or to modify the XML configuration file in your favorite text editor. This guide is only going to focus on using the GUI. One thing that sets IIS apart from Apache during configuration, you never need to restart IIS either making changes from the GUI or directly to the XML file. IIS will instantly recycle it processes when changes are detected. To open the IIS manager, you can go though the Control Panel to Administrative Tools, or you can simple just type “IIS” into the search box.
The first thing we should do is point our localhost site to the proper location, W:\websites\sandbox. In the far left pane, expand the server (the name of your computer) then expand sites. There should already be an entry for “Default Web Site” just delete it. Right click anywhere in the left pane, select “Add Web Site…” Enter “Sandbox” as the site name, for the physical path W:\websites\sandbox, then hit okay. You should be greeted by site level configuration options.
This can get pretty complicated with the number of options that can be configured and the number of levels available to configure at. There is global settings that affect every site, there is site level settings, and folder level settings. It can get really glandular and confusing quickly. The global settings are access by the root node on the far left pane. Site level is on each site node, expanding the site nodes reveal the folder level nodes.
One of the first global settings you want to change is “Directory Browsing”, double click its icon to change the middle pane’s view. The far right pane changed as well, it will change often based on what options or nodes you enter. Click on “Enable” in the right pane. Afterwards you can go back, either by hitting the back button (top left on the window frame), or selecting the root tree node on the left.
Adding PHP Support
Adding PHP is rather easy, while in the global settings:
- Open Handler Mappings
- On the right pane, select “Add Module Mapping…”
- Following this guide use these options:
- Request path: *.php
- Module: FastCgiModule
- Executable: W:\workspace\environment\language\php\5.3.0\php-cgi.exe
- Name: PHP 5.3 FastCGI
- Click OK
Bonus for Windows 7 users, on the main settings page open FastCGI Settings then double click on the path that leads to PHP which was just configured. You want to change “Monitor changes to file” and point it to php.ini which can be found in PHP’s directory. You will not have to restart IIS when you change PHP’s configuration anymore. For Windows Vista users I have not found a similar option.
There are a few settings that need to be changed in php.ini before we continue. You want to change: cgi.force_redirect, cgi.fix_pathinfo, and fastcgi.impersonate. All but cgi.force_redirect should be set to 1, for cgi.force_redirect you must turn it off so set it to 0.
Once done, restart IIS (if and only if you are using Windows Vista or not followed bonus instructions) then create a PHP file in the sandbox directory with: <?php phpinfo(); then access that file from the browser (http://localhost/). You should be greeted with a long page of information.
system — 2009-10-27T05:44:38-04:00 — #5
xampp comes with apache and php 3.0 you can try it out download xamp from here http://www.apachefriends.org/en/xampp.html
johnnycash — 2009-10-28T08:14:55-04:00 — #6
Yes ...this is the version i used: VC6 Thread Safe
as stated in the book corrections:
# p.12 Installing PHP
Although this book provides download and installation instructions for PHP 5.2, the newly-released (at the time of this writing) PHP 5.3 includes some new download options that aren’t covered in the book.
There are four different versions of PHP 5.3. for Windows: VC6 Non Thread Safe, VC6 Thread Safe, VC9 Non Thread Safe, and VC9 Thread Safe. Talk about confusing!
First of all, you definitely want a Thread Safe version of PHP. The Non Thread Safe versions are not suitable for use as a plugin for Apache.
Secondly, assuming you will install (or have already installed) a version of the Apache HTTP Server from httpd.apache.org (see page 13), you will need the VC6 version of PHP.
In short, to follow the instructions in this book, you need the VC6 Thread Safe version of PHP 5.3 for Windows.
infoaddicts987 — 2009-12-02T09:06:29-05:00 — #7
According to the PHP QA site, if you are using PHP with Apache 1 or Apache2 then you need to be using the VC6 release candidates, not the VC9. VC9 is for use with IIS.
Since the link you provided in your question goes to a VC9 download, I would assume that's what you downloaded, and I'd say you should go download the VC6 version instead.
teckyhead — 2009-12-03T00:44:58-05:00 — #8
I have my development PC set up with PHP, Apache and MySQL and there's a couple of other things I do with most of my sites.
For each site I add an entry in my hosts file and create a virtual host. Let's say the site is www.mybigdevelopmentsite.com. I would add this to the hosts file (which is usually in C:\Windows\System32\drivers\etc):
Then in the apache config I add:
CustomLog "logs/mbds.localhost-access_log" common
You can add the virtual host in your main apache config or in extra/httpd-vhosts.conf (I use the latter).
When I set the database up I use the same database name and credentials that are on the live server.
There are usually a few server specific things such as a full path to a config file and in those cases I use code like this:
if($_SERVER["SERVER_NAME"] == "mybigdevelopmentsite.localhost")
$config_path = 'd:/webroot/mybigdevelopmentsite.com';
$config_path = '/home/mybigdev/public_html';
It makes it really easy to test changes on the local PC, knowing that I can just upload them to the live server and in 99.99% of cases it will just work.
scout1idf — 2009-12-27T03:39:59-05:00 — #9
I am interested in learning PHP and decided to use the built in server on my computer instead of downloading one.
I'm very new to all of this and during the learning process don't want to mess up my computer.
That brings me to my question:
For the purpose of learning only, what exactly do I need to turn on and what do I need to leave turned off so I am the only one to have access to my computer/server?
Also after reading that IIS 7 is available, will I have to down load it manually or with IIS 6 turned on will I get it as an "auto update"?
I don't know if this is important for my questions but, I am running Windows Vista Home Premium service pack 2.
<font size='"2"'><font size='"1"'>□Internet Information Services
[INDENT]□Web Management Tools[/INDENT]
[INDENT][INDENT]□IIS 6 Management Compatibility[/INDENT][/INDENT]
[INDENT][INDENT][INDENT] □IIS 6 Management Console
□IIS 6 Scripting Tools
□IIS 6 WMI Compatibility
□IIS Metabase and IIS 6 configuration Compatibility[/INDENT][/INDENT][/INDENT]
[INDENT][INDENT]□IIS Management Console
□IIS Management Scripts and Tools
□IIS Management Service[/INDENT][/INDENT]
[INDENT]□World Wide Web Services[/INDENT]
[INDENT][INDENT]□Application Development Features[/INDENT][/INDENT]
[INDENT][INDENT] □Common Http Features[/INDENT][/INDENT]
□Health and Diagnostics
□Http Compression Dynamic
□Static Content Compression
Thanks in advance for your help......
logic_earth — 2009-12-27T04:57:06-05:00 — #10
For the absolute minimum for IIS, check these items:
Internet Information Services
Web Management Tools
IIS Management Console
World Wide Web Services
Application Development Features
Common Http Features
However selecting everything wouldn't hurt nothing either...And Windows Vista comes IIS 7.
billo — 2010-03-29T20:14:51-04:00 — #11
I had no problems installing and configuring php5.3.x on WindowsXP professional with Apache2.2 and MySQL. It was a snap.
I had been having problems with an older version of php5, and it was not reading the php.ini file. This solved that problem, and now everything works.
Only word of caution: Apparently short open tags are disabled by default on this version (I don't use them) so I ran into a problem on a couple of pages when I discovered that for some reason I had used them <? vs. <?php by mistake.
So, if a page doesn't load, and is just blank, check that you have not used short open tags by accident.
billo — 2010-04-01T14:30:22-04:00 — #12
Windows (keyboard between Ctrl and Alt) + Pause/Break, Advanced, Environment Variables
But you don't really need to do it if things are working as they should. This was the problem that I had, and after I got PHP to read the php.ini file (by installing the correct version of PHP5.3, everything works fine without that. Makd sure you have in your httpd.conf the following all the way at the bottom:
LoadModule php5_module "c:/php/php5apache2_2.dll"
AddType application/x-httpd-php .php
Of course, use your paths and Dir.
dockraz — 2010-09-25T05:19:21-04:00 — #13
Hey All -
I'm posting this here in case someone else comes up with this problem (and hopefully I'll get a solution).
I'm having an issue getting PHP and Apache working.
I have a Clean install of Win7.
I have 2 hard drives - so I made one W for Work (had done that anyway), and on it, I created a programming folder - and under there I have the same directory structure as listed in the first post, so it looks like:
I downloaded php-5.3.3-Win32-VC6-x86.zip file (VC6 Safe Thread). Unzipped it and stuck it in W:\programming\workspace\environments\language\php\5.3.0
Made the 3 changes listed (extension was unremarked and left at "ext", while the other two were listed as W:\Temp\sessions & W:\Temp\uploads.
Tested as listed and got the correct php version.
On to Apache!
For Apache - I downloaded httpd-2.2.16-win32-x86-no_ssl.msi from the site, and installed as directed in the instructions ( under W:\programming\workspace\environment\http-service )
I made the following changes to the httpd.conf file:
(changed allowoverride to all)
I Saved - stopped, and restarted the service. All Well. went to http://localhost - It Worked!
Went further and unhashed the 4 items suggested - Stopped and Restarted - All Well.
Here is where I have problems.
Added the following:
LoadModule php5_module "W:\\programming\\workspace\\enviroment\\language\\php\\5.3.0\\php5apache2_2.dll"
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
So the example - only modified by adding the "programming" directory to the front - and when I stop and restart - I get "The Requested Operation has failed" error when the apache server tries to restart.
If I comment out the 4 new lines and re-save - then it restarts - so its not liking something with php, and I'm at a loss to figure out what!
Any ideas/help on this?
spacephoenix — 2010-09-25T05:29:39-04:00 — #14
Swap all the \ in these two lines for / save, then restart the server
LoadModule php5_module "W:\\programming\\workspace\\enviroment\\language\\php\\5.3.0\\php5apache2_2.dll" PHPIniDir "W:\\programming\\workspace\\enviroment\\language\\php\\5.3.0"
dockraz — 2010-09-26T03:20:42-04:00 — #15
Swapped \ for / in those 2 lines, so my httpd.conf file looks like:
LoadModule php5_module "W:/programming/workspace/enviroment/language/php/5.3.0/php5apache2_2.dll"
Still get the "the requested operation has failed" error when I attempt to start the apache service.
By sheer coincidence - after I had posted this message (up to the "further" line) - I shut down my chrome browser, and as I was going to shut down windows, I noticed "Test" in my Start menu programs, with the apache logo, so I clicked it. I got the following cmd box prompt:
httpd: Syntax error on line 485 of W:/programming/workspace/environment/http-ser
vice/conf/httpd.conf: Cannot load W:/programming/workspace/enviroment/language/p
hp/5.3.0/php5apache2_2.dll into server: The specified module could not be found.
Now - just to verify, if I go to W:\programming\workspace\environment\language\php\5.3.0\ there is in fact a php5apache2_2.dll file.
So I'm still at a loss as to what is happening!