Documentos de Académico
Documentos de Profesional
Documentos de Cultura
With the recent release of PHP 5.0, many PHP developers might
be thinking about upgrading their existing PHP installations to the new
standard. Although PHP 5.0 may not be ready yet for a live environment, this
tutorial will show you how to build a PHP 5.0 server on Windows that would be
suitable for hosting live applications with future builds of PHP 5.x.
In general, a "dot zero" version of a new system has not been tried and tested
enough to be considered safe for production servers. With an application as
complex as PHP 5.0, it is an absolute certainty that bugs will be found, and
corrected promptly, within the coming months. I would expect a 5.0.1 version to
be released shortly, which may prove to be stable enough for live servers.
If you have never heard of some of these packages, don't worry I will explain
each one in turn before I describe how to install them. In general with these
installation tutorials, your system and version numbers will not exactly match
mine, so there may be different options or steps required to get your
configuration up-and-running, but hopefully these guidelines will provide all
the instructions you need.
You will find a section of links at the bottom of this page to the download
sites for all of the software you need to setup your server. Download the latest
versions of everything you need (I estimate about 50 MB in total for all
downloads), save them to a local folder on your C drive, then you are ready to
begin.
2. Installing IIS
on Windows 2000
The first thing we need to do is set up IIS
from our Windows 2K CD. IIS (Internet Information Service) is Microsoft's
equivalent of Apache, a HTTP server that will run on your PC, listening to a
network port (by default port 80) on your machine for HTTP requests, and
responding to these requests, normally requests for HTML pages, by sending the
HTML page to the client machine looking for the data.
You could use Apache 2.x, or some other web server, for this step instead, but I
do not discuss Apache sever configuration options at any stage so you might get
lost. I use a LAMP (Linux Apache MySQL PHP) test server at home, and Windows IIS
servers in work, so am comfortable with either environment. Therefore, I may
publish a tutorial on setting up a LAMP server with PHP 5.0 at a later date,
which is a radically different process to the one we are about to follow.
Insert your Windows 2000 CD, and kill any start-up screen
that pops up.
Click Start -> Settings -> Control Panel, and then double
click Add/Remove Programs.
On the left panel, click Add/Remove Windows Components.
5. Click Next, Finish and then you may require a restart (hey,
it is Windows!).
Now to test out IIS, start up Internet
Explorer and type in http://localhost/ as the site to visit: you should
get the default "Welcome to IIS 5.0" web page.
2.2 Enabling Support for Detecting Usernames
In my experience building Intranet-based PHP
applications, I have found that many users prefer systems that can automatically
log them in based on their network credentials. Here we are operating on the
principal that if they were able to log onto a network workstation, then they
must possess a valid username and password. Rather than asking them to login
again to our PHP applications, we can grab the client's network credentials,
including the NT username, and login the user automatically, a technique often
termed "pass-through authentication".
In reality, I have found the ISAPI module to be unstable with PHP 5 and IIS on
Windows, often causing access violations. These issues will most likely be
resolved in time, and may be by the time that you are reading this.
The second version, a standard C executable, is the one that we will be using.
This runs under IIS as an external CGI (Common Gateway Interface) call, similar
to the way Perl/CGI works, so as a result is not as quick as the ISAPI module,
but it is very stable. In the trade-off between speed and stability, we should
always favour stability for a live production server.
4.1 Installation Steps
Unzip the contents of the zip file you downloaded for PHP
5 into C:\PHP
In C:\PHP , rename php.ini-dist to
php.ini
You may want to add C:\PHP onto the system path
variable, as you did for MySQL in the previous section.
That's it! Now onto configuring PHP 5.
4.2 Working with the php.ini File
The C:\PHP\php.ini for is the main
configuration file for PHP on our server, so we will be spending quite a bit of
time working with this file. Open it up now with a text editor, you will find it
to be very well commented and easy to work with. This is a good example of the
difference between open source software and commercial software, for example IIS
uses a difficult-to-navigate tab-based GUI (Graphical User Interface) to
configure the server, while Apache uses a text file similar to the one that PHP
uses called httpd.conf . Personally, I like this simple no-nonsense
approach.
4.3 Enabling E-mail Support
If you have access to a mail sever, for
example an Exchange server, then you can instruct PHP to use this server to send
mails from its mail() function. Modify the following lines in your
php.ini file to pint to the network address of your mail server, where
available:
[mail function]
; For Win32 only.
SMTP = mailserver.mydomain.com
smtp_port = 25
PHP will now route e-mails from the mail() function to this sever.
; cgi.force_redirect = 1
with:
cgi.force_redirect = 0
As stated in the comment in the php.ini file, you MUST turn this off to get
PHP to work as a CGI in IIS.
Save your modified php.ini file. Now in C:\Inetpub\wwwroot\
create the following PHP script:
<?php
phpinfo();
?>
If you scroll down on this page, you will see that it details
everything about your PHP installation, which is a very useful guide for
installation purposes. I will refer back to this page frequently throughout the
rest of this tutorial as "the PHP info page"; you can take this to mean
http://localhost/info.php in your web browser.
You should also be able to find your username stored in an environment variable
on this page, normally in something like $_SERVER["AUTH_USER"] or
$_SERVER["LOGON_USER"], which you can access from your PHP scripts (assuming you
followed the steps to disable anonymous access in IIS).
4.5 Enabling MySQL Support
There are two separate APIs (Application
Programmers Interface) available for MySQL with PHP 5.x. The standard MySQL API
is the one that came with PHP 4.x, while the new MySQL Improved API (or
mysqli ) contains all the new PHP functions for accessing the new features
of MySQL 4.1 and above, such as stored procedures that will be introduced in
MySQL 5.
extension_dir = "./"
with
extension_dir = "./ext"
Or to reflect where your extension DLL files are for PHP 5, they are usually
in C:\PHP\ext (hence the relative path "./ext" should work fine).
; extension=php_mysql.dll
with
extension=php_mysql.dll
Or if it is not already there, then add it in the same section as the other
extension files listed.
Now add:
extension=php_mysqli.dll
Reload the PHP info page, and scroll down until you find a section on mysql
and another on mysqli.
;extension=php_gd2.dll
with
extension=php_gd2.dll
FPDF does not need to be installed, it simply needs to be extracted from is zip
into a suitable location. The best place to put this is on the include path for
PHP.
The include path is the first place that PHP will look in for a file that is
included without a location being specified, for example:
include('myfile.php');
When this line of code is executed, PHP will look for myfile.php in the current
folder, and in the folder(s) specified in the include path directive in the
php.ini file. If it cannot find the file, it will throw an error.
;include_path = ".;c:\php\includes"
with
include_path = ".;c:\php\includes"
Create the folder C:\PHP\includes
Unzip the contents of the FPDF zip file you downloaded to
C:\PHP\includes
require_once('fpdf.php');
Firstly, we will install the PEAR framework, and then we will install the DB
extension. The process for installing the extensions from PEAR are all the same,
so here we are using DB as an example.
5.1 Installation Steps
Type go-pear
Press enter to continue
PEAR will ask you for details on your network proxy
server (if you have access to one) so that it can automatically download
packages from the PEAR website. Skip this, just press enter.
PEAR will then give you a summary of the directory
structure for your PHP installation. The key thing to confirm is that the
PHP prefix is C:\PHP . Press enter if everything looks ok.
PEAR will ask to change the include path for PHP, say no
( n ).
When PEAR installs, change your include path in your
php.ini file to:
include_path = ".;c:\php\includes;c:\php\pear"
require_once('DB.php');
; extension=php_pspell.dll
with
extension=php_pspell.dll
Now when you check your PHP info page, you should now an
entry for pspell saying that it is enabled.
7. Download Resources
Resource
URL
Description
PHP
http://www.php.net/
The home site for PHP, from here you can access the
download section, the online manual, and also keep in touch with other
PHP-related news.
PEAR
http://pear.php.net/
The PEAR home site, where you can browse and download
all of the PEAR packages, as well as access the PEAR manual.
MySQL
http://www.mysql.com/
http://aspell.net/win32/
FPDF
http://www.fpdf.org/
By John Collins
About the Author:
John Collins is a freelance web developer and software design consultant from
Dublin, Ireland. You can find more articles by him at his home site
http://www.design-ireland.net/
printer-friendly version