Sunteți pe pagina 1din 17

3 2

PHP
P
HP is a popular scripting language used to create
powerful and dynamic Web sites. PHP is currently in
use on over five million Web sites around the world.
PHP is open source software, which means it is available
free of charge. There are also no costs or restrictions
related to distributing the PHP scripts you create, whether
the scripts are for development or commercial use.
INTRODUCTION TO PHP
GETTING STARTED WITH PHP 1
Interactive Web Sites
Interactive Web sites contain Web pages that
exchange information between the Web site and
the user. Using PHP allows Web developers to
easily create Web pages that process information
from a user and then generate content depending
on the information submitted by the user.
Interactive Web sites allow Web developers to
tailor the content of Web pages to better appeal
to the user.
Database Manipulation
One of the most important features of PHP is
the ability to work with a number of different
databases, including MySQL, Oracle and Sybase.
PHP pages can be used to access a database and
then make the information stored in the database
available to users who visit the Web site. Using
databases to store information and PHP code to
access the information is an efficient method of
displaying up-to-date information in a Web site.
PHP can also allow users to manipulate the data
in a database. For example, a PHP page can be
used to add, delete or edit records in a database
depending on a user's request.
Versions
PHP is constantly evolving and a new version of the
language is released every few years. Each new version
of PHP offers more features than previous versions
but is still compatible with the previous versions.
This means that scripts you write using the current
version of PHP will be compatible with future versions.
PHP 4 is the current version of PHP and is used in the
examples throughout this book.
HTML
HyperText Markup Language (HTML) is the markup
language used to create Web pages. PHP can be used
to dynamically generate the HTML code for a Web
page. PHP code can also be embedded into the HTML
code for a Web page. PHP is embedded into HTML
code with the use of special tags, called delimiters.
Using the delimiters, you can add as many sections
of PHP code to an HTML document as you need.
Embedding PHP code in HTML code makes it possible
to enhance existing Web pages on a Web site.
Dynamic Web Sites
Dynamic Web sites contain Web pages that display
constantly changing content. Using PHP, you can
determine the content a Web page displays, depending
on many different factors. For example, you can have
a page automatically present different content to users
depending on the current date or the user's location.
Dynamic Web pages are more useful to each individual
user than static Web pages.
Cross Platform
PHP can be installed on computers using different
Windows and Unix operating systems. While some
specialized functions work only on specific platforms,
the vast majority of PHP code will work equally as
well on either platform. Many PHP developers write
their code on Windows-based computers and then
use the code on Web servers that run a Unix
operating system.
Web Servers
You do not require a dedicated Web server to publish
the Web pages you create using PHP. You can simply
install Web server software on your own computer.
A popular example of Web server software that
includes support for PHP is Apache. Microsoft's Web
server products, Internet Information Server (IIS) and
Personal Web Server (PWS), can also be used to
store and serve PHP pages. If you cannot install Web
server software on your computer, you can transfer
your PHP pages to a Web hosting service on the
Internet.
Development Tools
You do not require any special development tools
to create and view PHP pages. All you need is a text
editor and a Web browser. Although there are some
programming tools available that make creating PHP
pages easier, these tools are typically used only by
Webmasters who generate large amounts of PHP
code on a continuous basis.
Server-Side Processing
A Web server processes all the PHP code in a Web
page and translates the code into simple HTML code.
This means that Web developers do not have to take
into consideration the types of Web browsers used
by clients. Any browser that can view Web pages
can view pages containing PHP code processed by
a Web server.
Object-Oriented
Although PHP is not a true object-oriented language,
PHP does support object-oriented programming
concepts that allow Web developers to write code
in an object-oriented fashion. Object-oriented
programming is a type of programming that treats
packages of code as distinct modules, or objects.
Using objects can make a large Web application
easier to manage, especially if there are multiple
developers working on the same application.
Increased Security
Because PHP code is processed by a Web server,
a user cannot access the code used to create a
PHP page. This makes it safer to work with sensitive
data, such as login names and passwords. If a user
views the source code of a Web page created using
PHP within a Web browser, all the user will see is
the HTML code that was generated by the Web
server to create the page, not the PHP code itself.
5
C:\Program Files\Apache Group\Apache
I This area displays the
folder where Apache Web
server files will be installed.
I You can click Browse to
specify a different folder in
which to install the files.
Click Next to continue. Click the type of
installation you want
to perform.
Note: If you choose Custom,
the following steps will be
different for your installation.
4
PHP
INSTALL APACHE WEB SERVER ON WINDOWS
Double-click the icon
for the Apache Web server
installation program to start
installing the program.
I A welcome dialog box
appears.
I This area displays
information about the
Apache Web server program.
Click Next to continue.
I This area displays the
license agreement you
must read and accept
before continuing.
Click Yes to accept the
agreement and continue.
I An information
dialog box may appear,
providing information
about this version of the
Web server software.
Click Next to continue.
B
efore you can publish PHP pages, you must install a
Web server that can interpret and process PHP code.
Apache Web server is an extremely reliable and robust
Web server that can be used for serving a small intranet or a
large commercial Web site. Since Apache is the most popular
Web server used on the Internet, PHP has been developed to
work well with Apache to make PHP pages available on the
Web.
A recent release of Apache Web server is included on the
CD-ROM disc that accompanies this book, but you should
make sure you install the latest release of the server. The
latest version of Apache is available at the www.apache.org
Web site.
Before you can install Apache, you must install the TCP/IP
protocol on your computer. For information about installing
network protocols, refer to your operating system
documentation.
Apache Web server is relatively easy to install and maintain.
Although the Windows version of Apache was designed
primarily for use on computers running the Windows NT
or Windows 2000 operating system, it can also be used
on computers using Windows 95, 98, Me or XP.
On the Windows platform, Apache is installed using
a standard Windows installation program. The Apache
files must be installed in a folder on the computer. The
default installation location is C:\Program Files\Apache
Group\Apache. You can specify another destination folder,
but it is recommended that you accept the default folder.
Apache includes several parts, such as documentation,
modules that increase Web server efficiency and the source
code of the application program itself. You may not need to
install all the available components in order to use Apache.
The setup program allows you to choose the type of
installation you want to perform.
INSTALL APACHE WEB SERVER ON WINDOWS
GETTING STARTED WITH PHP 1
When installing Apache Web server, you can choose
one of three installation options. The Typical option
installs the most commonly used files and is the
recommended option. The Compact option installs
only the files required to run Apache. This option is
useful when installing Apache on a computer with
limited hard drive space available. The Custom option
allows advanced Web site developers to choose the
Apache Web server files they want to install.
If you are installing a more recent version of Apache
Web server than the one included on the CD-ROM
disc that accompanies this book, you should carefully
read the Web server documentation, especially the
areas that relate to PHP. Later versions of Apache may
work differently with PHP than the version used in
this book.
Unlike commercial programs, which often
include a support department to handle any
problems with the application, there is no
official support included with the Apache
program, so you must troubleshoot any
problems yourself. There are, however, many
Web sites, user groups, newsgroups and books
available that can be a source of information
for Apache users. The Apache FAQ located at
http://httpd.apache.org/docs/misc/FAQ.html
is a good starting point when looking for help
information.
CONTINUED
Click Next to continue.
7
My Documents
My Computer
Online
Services
Outlook
Express
Programs
Apache Web Server Apache as a service
Install service
Jack Smith...
Accessories
Apache
Games
Online Services
StartUp
INSTALL APACHE AS A SERVICE
Click Start.
Click Programs.
Click Apache Web Server.
Click Apache as a service.
Click Install service.
Restart the computer.
Apache Web server will
start automatically each
time the computer is
started.
TEST APACHE
Start the Web browser
you want to use to test
Apache Web server.
Click this area to
highlight the current Web
page address and then
type http://.
6
PHP
INSTALL APACHE WEB SERVER ON WINDOWS (CONTINUED)
I This area displays the
folder where program
icons for Apache will be
installed.
Click Next to install
Apache on your computer.
I A dialog box appears,
indicating that the
installation is complete.
If you do not want to
display the README file
after the dialog box closes,
click the box beside this
option ( changes to ).
Click Finish to close
the dialog box.
W
hen installing Apache Web server on a computer
running a Windows operating system, a folder
containing shortcut commands for Apache Web
server is added to the Programs folder on the Start menu.
This folder allows you to quickly access commands that let
you work with Apache from the Start menu.
The installation program allows you to choose whether
you want to view a README file that contains information
about the release of Apache you installed. If you choose
to display the file, it will open when the installation is
complete. You should carefully review the README file
for any new release of Apache you install.
Once Apache Web server is installed, you should install
the Web server as a service. A service is a term used
on Windows computers to describe a program that is
automatically executed and managed by the operating
system. When you install Apache as a service, the program
will start automatically and run in the background each time
the computer is started. Once the Web server has been
installed as a service, you should restart the computer.
To confirm that Apache Web server has been installed and
started properly, you can have the server display a page in
a Web browser. After starting the Web browser you want to
use, you enter the name or IP number of your computer as
the URL in the Web browser. The IP number indicates the
computer that is running the Web server software. If you
do not know the IP number of your computer, you can use
127.0.0.1, which is the IP number that computers running
TCP/IP use to refer to themselves. If the Apache installation
was successful, a default Web page will be displayed.
INSTALL APACHE WEB SERVER ON WINDOWS
GETTING STARTED WITH PHP 1
After installing Apache Web server as a service,
you can stop or restart Apache manually using
Start menu commands. To stop or restart Apache
on most Windows systems, click Start, select
Programs and choose Apache Web Server. Then
click Apache as a service and select Stop Service
or Restart Service.
You can also start and stop Apache Web server
from within a command prompt window. In the
command prompt window, change to the directory
that contains the Apache program files, usually
C:\Program Files\Apache Group\Apache, and type
apache at the prompt to start the Web server. You
can use the same method to stop Apache, except
type apache -k shutdown at the prompt.
If you are removing Apache Web server from
your computer, you may want to first uninstall
Apache as a service to ensure that the program
is removed correctly. To uninstall Apache as a
service, click Start, select Programs and choose
Apache Web Server. Then click Apache as a
service and select Uninstall service.
The Apache Web server program is written by a
group of dedicated and talented volunteers who
do not receive any payment for their work with
Apache. Apache Web server is completely free
to download, install and use. Unlike many free
programs that require a fee to be paid if the
software is used for business purposes, there
are no restrictions on the use of Apache.
Type the IP number of
your computer or 127.0.0.1
and then press Enter.
I The Web browser
displays a Web page
generated by Apache
Web server.
9
To confirm that Apache has been installed and started
properly, you can have the server display a page in a
Web browser. The Lynx Web browser is a text-based
browser available on most Unix computers. To display
a test page generated by Apache, type lynx http://
followed by the IP number or name of your computer
at the prompt. You can also use 127.0.0.1, which is
the IP number computers using TCP/IP commonly
use to refer to themselves.
On some Unix systems, such as Red Hat
Linux, you can use the Red Hat Package
Manager (RPM) to install Apache Web server.
RPM is an easy-to-use application that allows
you to quickly install, update and remove
applications from your computer. More
information about RPM is available at the
www.rpm.org Web site.
You can restart or stop Apache using the same
method you use to start the server. To restart
Apache, type /user/local/apache/bin/apachectl restart
at the prompt. To stop Apache, type
/usr/local/apache/bin/apachectl stop.
The tar command can be used to combine
multiple files into a single, more manageable
file. The letters xvf indicate settings you can
specify for the tar command. To display
information about the settings you can use
with the tar command, type man tar at the
prompt. When you finish reviewing the
settings, press q to quit.
To install the Apache
files on the computer, type
make install and then press
Enter.
I This message appears
when Apache has been
successfully installed.
8
PHP
INSTALL APACHE WEB SERVER ON UNIX
At the command
prompt, type gunzip
followed by the name
of the file you want to
unzip. Then press Enter.
To retrieve the unzipped
files from the archive, type
tar xvf followed by the name
of the tar file that contains the
Apache files. Then press Enter.
Note: A directory with the same name
as the tar file is automatically created
to store the files retrieved from the
archive.
To work in the directory
that contains the Apache
files, type cd followed by
the name of the directory.
Then press Enter.
To specify a directory where
you want to install the Apache
files, type ./configure prefix=.
Then type the name and
location of the directory and
press Enter.
To prepare Apache for
installation, type make and
then press Enter.
A
pache Web server was originally developed and
configured to run optimally on computers using
the UNIX operating system, which makes Apache
an ideal server to use to interpret and process PHP code
on a Unix computer.
A recent release of Apache is available on the CD-ROM
disc that accompanies this book, but you can check the
www.apache.org Web site for the latest release of the
server. The steps for installing Apache will depend on
the UNIX operating system and the version of Apache
you are using. You should carefully read the installation
instructions included with the software.
The Apache program files are usually stored in a compressed
file with the .Z extension. To access the Apache files,
you must first uncompress the compressed file using the
gunzip command. The files are then archived into a single
file with the .tar extension. You must extract the files from
the archive using the tar xvf command. The extracted
files are automatically saved in a new directory, which you
can access using the cd command.
The configure command allows you to set up some
Apache installation settings to suit your needs. You may
need to precede the configure command with ./ to
indicate the location of the command on the computer.
To specify a directory where you want Apache program
files to be installed, you use the --prefix parameter
with the configure command, specifying the name
and location of the directory as the value of the --prefix
parameter.
After you run the configure command, you must execute
the make command to prepare Apache Web server for
installation. You then use the make install command
to install the Apache files on the computer.
Once the Apache software has been installed, you can
use the start command to start the Web server.
INSTALL APACHE WEB SERVER ON UNIX
GETTING STARTED WITH PHP 1
START APACHE
To start Apache, type
the name and location of the
directory you specified in
the --prefix parameter in
step 4, immediately followed
by /bin/apachectl start. Then
press Enter.
11
I You can now use
Apache Web server
to process and display
PHP pages you create.
Save
The name and location of the Apache configuration
file depends on the operating system the computer
uses. The name of the configuration file is usually
httpd.conf. On Windows operating systems, the file
is typically located in the conf subdirectory of the
main Apache program directory. On Unix-based
computers, the file is usually found in the /etc
directory.
When you specify a file path in the Apache
configuration file, you should use slashes (/) instead
of backslashes (\) in the path name. For example,
the filename c:\php\php.exe should be typed as
c:/php/php.exe.
To set up PHP as an Apache module, you should
first move the php4ts.dll file, which is located in
the main PHP directory, to your system directory.
The name of the system directory depends on your
operating system. On computers running Windows
NT or 2000, you can move the file to the WINNT
directory. To indicate that you want to use PHP
as an Apache module, you must then add the
following code to the Apache configuration file:
LoadModule php4_module c:/php/sapi/php4apache.dll
AddType application/x-httpd-php .php .phtml
To specify that Apache should
pass files to the PHP program
before displaying the files in a
Web browser, type Action.
Type application/x-httpd-php
to specify the MIME type of the
files you want to pass to PHP.
Type the name and
location of the PHP
program file that will
process the files, enclosed
in quotation marks.
Save the Apache
configuration file.
10
PHP
CONFIGURE APACHE WEB SERVER TO WORK WITH PHP
Open the Apache
configuration file in a text
editor.
To create a virtual path
that will allow Apache to
access PHP program files,
type ScriptAlias.
Type the virtual path
you want to use.
Type the actual location
of the PHP files, enclosed
in quotation marks.
To specify which file
extensions Apache should
process as PHP files, type
AddType.
Type application/x-httpd-php
to specify the MIME type used
for PHP files.
Type the extensions
you want to use for
PHP files.
W
hen you configure Apache Web server to work
with PHP, you can set up PHP as a CGI binary
or as an Apache module. Setting up PHP as an
Apache module allows you to access additional capabilities
of the PHP program, but for most installations it is sufficient
to set up PHP as a CGI binary. To set up PHP as a CGI
binary, you need to specify certain settings, or directives,
in the Apache configuration file.
Initially, Apache Web server cannot access PHP program
files because the files are stored in a location outside the
server's directory structure. The ScriptAlias directive
allows you to create a virtual path Apache can use to access
the directory that stores PHP program files. For example,
on Windows computers, you can create the virtual path
/php/ to allow you to access files in the C:\PHP directory.
To ensure that Apache Web server processes PHP files
correctly, you use the AddType directive to specify the
Multimedia Internet Mail Extensions (MIME) type used
for PHP files. MIME types are a set of accepted file types
typically used by Internet applications. PHP files use
application/x-httpd-php as the MIME type. When using
the AddType directive, you also indicate the file extensions
you want to associate with PHP. PHP files commonly use
the .php extension, but may also use other extensions,
such as .phtml and .php3.
The Action directive allows you to specify that Apache
should pass PHP files to the PHP program for processing
before displaying the files in a Web browser. When using
the Action directive, you specify the MIME type of the
files you want to pass to PHP as well as the name and
location of the program that will process the files.
CONFIGURE APACHE WEB
SERVER TO WORK WITH PHP
GETTING STARTED WITH PHP 1
13
I You should restart the
computer before using
Internet Information
Server.
My Do
Int
Ex
Recy
My C
My N
P
Change or
Remove
Programs
Add New
Programs
Add/Remov
Windows
Component
My Do
Int
Ex
Recy
My C
My N
P
Change or
Remove
Programs
Add New
Programs
Add/Remov
Windows
Component
World Wide Web Server 1.9 MB
5.6
My Do
Int
Ex
Recy
My C
My N
P
Change or
Remove
Programs
Add New
Programs
Add/Remov
Windows
Component
Internet Information Services (IIS) 18.3 MB
My Do
Int
Ex
Recy
My C
My N
P
Change or
Remove
Programs
Add New
Programs
Add/Remove
Windows
Components
Before installing IIS, you should log on to the
computer using the administrator account,
since a user account may not have permission
to install all the components that IIS requires.
Logging on to the computer as administrator
will ensure that you have all the necessary
permissions to install IIS.
The Internet Information Services component
includes several optional parts you can install.
Documentation provides help files regarding
the use of IIS and should be installed. File
Transfer Protocol (FTP) Server allows IIS to host
FTP sites. Personal Web Manager provides a
graphical interface you can use to administer
your Web sites. SMTP Service allows IIS to
send e-mail messages.
After IIS is installed, the Internet
Information Services window provides
tools that allow you to administer your
Web sites. Display the Control Panel and
double-click Administrative Tools. In the
Administrative Tools window, double-click
Internet Services Manager to display the
Internet Information Services window.
You can remove IIS from a computer.
Perform steps 2 to 9 below, except select
each part of the Internet Information
Services component you want to remove
in step 6 ( changes to ). Removing
IIS from a computer does not remove the
Inetpub\wwwroot directory and the files
it stores from the computer.
Click the box ( ) beside each
part of the Internet Information
Services component you want to
install ( changes to ).
I In this example, Common Files,
Internet Information Services
Snap-In and World Wide Web
Server are selected.
Click OK to confirm
your selections.
Click Next to install
the parts of the Internet
Information Services
component you selected.
I When the installation is
complete, a message indicates
that you have successfully
completed the Windows
Components Wizard.
Click Finish to close the
wizard.
12
PHP
INSTALL INTERNET INFORMATION SERVER
Insert the Windows 2000
Professional CD-ROM disc
into a drive.
Note: If the Microsoft Windows 2000
CD dialog box appears, click to
close the dialog box.
In the Control Panel,
double-click Add/Remove
Programs to display the
Add/Remove Programs
window.
Click Add/Remove
Windows Components
to display the Windows
Components Wizard.
Click Internet Information
Services (IIS).
I This area displays a
description of the Internet
Information Services
component.
Click Details to display
the Internet Information
Services (IIS) dialog box.
M
icrosoft Internet Information Server (IIS) 5.0
is Web server software that allows you to
host multiple Web sites on the Internet or
on a network, such as a corporate intranet.
IIS 5.0 is designed for use with the Windows 2000
operating system and is available on the Windows 2000
Professional CD-ROM disc. IIS 5.0 offers many advanced
features that allow you to effectively host and manage
even the busiest Web sites. Although IIS 5.0 is powerful
server software, it can still be used to learn about Web
servers and PHP. IIS 5.0 can be used to perform all the
examples in this book.
To install IIS on a computer, you must add parts of the
Internet Information Services component to the computer.
The parts of the component that must be added are
Common Files, which are the files required to run IIS;
Internet Information Services Snap-In, which provides an
interface you can use to administer your Web sites; and
World Wide Web Server, which allows users to access
your Web sites.
IIS may affect the performance of an existing or new service
pack you install on the computer. If you need to install a
service pack, you should check the support.microsoft.com
Web site to determine whether the service pack should be
installed before or after IIS is installed.
After IIS has been installed, you may have to restart the
computer. IIS starts automatically each time the computer
is started.
PHP can be installed either before or after installing IIS.
You can have multiple installations of IIS on a computer,
but you can have only one installation of PHP.
INSTALL INTERNET INFORMATION SERVER
GETTING STARTED WITH PHP 1
15
New Virtual Directory
Site Default Web Site
You can also use Windows Explorer to add a
virtual directory to IIS. Start Windows Explorer
and then select the directory you want to add
as a virtual directory. Click the File menu and
then choose Properties. In the Properties
dialog box, click the Web Sharing tab and then
select the Share this folder option. In the Edit
Alias dialog box that appears, type an alias for
the virtual directory and then select the access
and application permissions you want to use
for the directory. Then click OK. Click OK in
the Properties dialog box to add the virtual
directory to IIS.
You can easily remove a virtual directory
you no longer need from IIS. Perform
steps 1 and 2 below to display the Internet
Information Services window and then
select the virtual directory you want to
remove. Click the Delete button ( )
and then click Yes in the dialog box that
appears. Removing a virtual directory
prevents users from accessing pages
stored in the directory but does not
remove the directory and its contents
from the computer.
I The Virtual Directory
Creation Wizard appears.
Click Next to continue. Type an alias for the
virtual directory.
14
PHP
ADD A VIRTUAL DIRECTORY TO INTERNET INFORMATION SERVER
In the Control Panel,
double-click Administrative
Tools to display the
Administrative Tools window.
Double-click Internet
Services Manager to display
the Internet Information
Services window.
Click to display
a list of Web sites on the
Web server ( changes
to ).
Click the Web site
you want to add a virtual
directory to.
Click Action.
Click New.
Click Virtual Directory.
W
hen Internet Information Server (IIS) is installed,
a number of directories are created that can
be used to store Web pages and PHP pages.
By default, these directories are stored in the document
root directory C:\Inetpub\wwwroot. Only pages stored
in the document root directory or its subdirectories can
be displayed by users. You can create a virtual directory
to make pages that are not stored in the document root
directory or its subdirectories available for viewing.
In order for PHP pages stored in a virtual directory to be
processed by the Web server, the virtual directory must be
properly configured. The Virtual Directory Creation Wizard
can help you add and configure a virtual directory.
You must give the virtual directory an alias, which is a
name users will use to access pages in the directory. An
alias is often used to shorten a long directory name. For
example, a directory named '2001_marketing_information'
could be assigned the alias 'marketing'. Short directory
names can help make a Web site easier for users to
navigate.
Virtual directories allow IIS to make a directory accessible
to users of a Web site regardless of the location of the
directory. For example, the directory C:\datapages can be
added to the abccorp.com Web site as a virtual directory
with the alias 'data'. Users can then use the address
www.abccorp.com/data/ to access pages in the virtual
directory. Users accessing a virtual directory you have
added to IIS will not be able to determine the actual
location of the directory on the computer.
ADD A VIRTUAL DIRECTORY TO
INTERNET INFORMATION SERVER
GETTING STARTED WITH PHP 1
CONTINUED
Click Next to continue.
Y
ou must specify the location of the directory you
want to add as a virtual directory to IIS. You must
also specify the access permissions for the directory.
Access permissions determine how the Web pages, PHP
pages and other files in the directory can be utilized.
The Read permission allows users to access Web or
PHP pages and must be turned on for a virtual directory
containing content you want to be displayed. The Read
permission is turned on by default.
The Run scripts permission allows scripts to run in the
directory and must be turned on for virtual directories
that contain PHP pages. The Run scripts permission is
turned on by default.
The Execute permission allows applications to run in
the virtual directory. For security reasons, the Execute
permission is rarely enabled.
The Write permission allows files to be created in the
directory and must be turned on for virtual directories
containing PHP pages that create files.
The Browse permission allows users to view a list of all
the subdirectories and pages the virtual directory contains.
When a user specifies a directory but does not specify the
name of the page they want to display, the user can select
a page, including a PHP page, from the list.
After a virtual directory is created, all the pages and files in
the directory will be available to users accessing the Web
site. You should be careful to store only files and Web or
PHP pages you want users to be able to view in the virtual
directory.
A virtual directory you add to IIS may be affected by folder
permissions set by the Windows operating system. Folder
permissions restrict who can access the folder and how the
files in the folder can be used. For more information about
folder permissions, see page 132.
ADD A VIRTUAL DIRECTORY TO
INTERNET INFORMATION SERVER
17
sales
I A message appears,
indicating that you have
successfully completed
the Virtual Directory
Creation Wizard.
Click Finish. I The virtual directory is
added to Internet Information
Server and appears in this area.
16
PHP
ADD A VIRTUAL DIRECTORY TO INTERNET INFORMATION SERVER (CONTINUED)
Type the path of the
directory you want to
add as a virtual directory.
I You can also click the
Browse button to locate the
directory on the computer.
Click Next to continue.
Click an access
permission in this area
to turn the permission
on ( ) or off ( ).
Click Next to continue.
GETTING STARTED WITH PHP 1
You can later change the execute permissions
for a virtual directory you have added to IIS.
Display the Internet Information Services
window and then select the virtual directory
you want to change. Click the Properties
button ( ) to display the Properties dialog
box and then click the Virtual Directory tab.
Click in the Execute Permissions area and
select the option you want to use. The Scripts
and Executables option allows all file types to
be accessed or executed in the directory. The
Scripts only option allows only scripts, such as
PHP files, to be run. The None option allows
access to only static files, such as HTML or
image files.
After adding a virtual directory to
Internet Information Server, you can
enable or disable the logging function
for the directory. Display the Internet
Information Services window and then
select the virtual directory you want to
change. Click the Properties button ( )
to display the Properties dialog box
and then click the Virtual Directory
tab. Click the Log visits option to
enable ( ) or disable ( ) the
recording of visits to the directory
in a log file.
Click to close
the Internet Information
Services window.
19
My Documents
Internet
Explorer
Recycle Bin
Internet Guest Account (PHP-WIN2000\I...
My Computer
My Network
Places
My Documents
Internet
Explorer
Recycle Bin
IUSR_PHP-WIN2000 PHP-WIN2000 My Computer
My Network
Places
My Documents
Internet
Explorer
Recycle Bin
Administrator (PHP-WIN2000\Administrator)
My Computer
My Network
Places
My Documents
Internet
Explorer
Recycle Bin
Properties
phone_extensi
ons
My Computer
My Network
Places
Great care must be taken when setting file and
folder permissions on a Web server. To gain a full
understanding of file and folder permissions and the
consequences of changing these permissions, you
should consult the operating system and Web server
documentation. Incorrectly setting file and folder
permissions on a Web server can leave the server
vulnerable to a range of problems, from accidental
data deletion to serious security breaches. Incorrect
file and folder permissions can also prevent all users
from accessing the Web server.
If you develop your PHP pages on a different Web
server than you publish the pages on, you must
ensure that the appropriate file and folder permissions
are set on the Web server on which the pages are
published. The permissions will not be transferred to
the Web server when you transfer the files for the
PHP pages.
If you no longer wish a user or group to
have permission to access a file or folder,
you can remove the user or group. Perform
steps 1 to 4 below to display the Security
tab of the Properties dialog box. Click the
user or group that you no longer want to
be able to access the file or folder and then
click Remove.
Click a user or group in
this area you want to have
access to the file or folder.
Click Add.
I The user or group you
selected appears in this area.
I You can repeat steps 6
and 7 for each user or
group you want to be able
to access the file or folder.
Click OK to confirm
your selection.
Click a user or group
in this area to view their
permissions.
I This area displays the
permissions granted to
the user or group.
18
PHP
SET WINDOWS FILE AND FOLDER PERMISSIONS
Click the file or folder
you want to change the
permissions for.
Click File.
Click Properties to
display the Properties
dialog box.
Click the Security tab.
I This area lists the users
and groups that can access
the file or folder.
Click Add to display the
Select Users, Computers,
or Groups dialog box.
Y
ou can change permissions to grant users and groups
of users different types of access to a file or folder
on Internet Information Server (IIS). The types of
permissions that can be set for a file or folder depend on
the operating system and file system installed on the Web
server. The steps below are for use on a server running the
Windows 2000 operating system with the NTFS file system.
When IIS is installed, a user account is created called
IUSR_ followed by the name of the computer, such as
IUSR_WEBSRV. This user account is part of the Everyone
group. If you deny the Everyone group access to a file or
folder, you can use the IUSR account to allow users to
access information in the file or folder.
You can allow or deny permissions for a user or group
to specify how a file or folder can be accessed. Full Control
allows users to modify, add, move and delete files, as well
as change permissions. Modify allows users to modify, add,
move and delete files. Read & Execute allows users to run
applications, such as PHP pages. List Folder Contents allows
users to display a list of files and folders stored in a folder.
Read allows users to display files and Write allows users to
change files.
Windows file and folder permissions work with the access
permissions set in IIS. Access permissions set for a folder in
IIS apply to all users who access the folder. Windows folder
permissions apply only to the users and groups you specify.
When Windows file and folder permissions and IIS access
permissions are set differently, the Web server uses the
most restrictive permissions. For more information about
IIS access permissions, see page 14.
SET WINDOWS FILE AND
FOLDER PERMISSIONS
GETTING STARTED WITH PHP 1
Click an option to allow
or deny the permission.
Click OK to confirm
your changes.
21
C:\Inetpub\wwwroot
In addition to Windows 98, PWS can be used on
a computer running the Windows 95 or Windows
NT Workstation operating system. If you do not have
your Windows 98 CD-ROM installation disc or you
are using Windows 95 or Windows NT Workstation,
you can obtain Personal Web Server 4.0 at the
www.microsoft.com Web site. PWS is part of the
Windows NT 4.0 Option Pack.
You do not have to start PWS manually each time
you want to use the software. Once you have
installed the Web server software, PWS will start
automatically each time you start your computer.
You can double-click the Personal Web
Server icon ( ) on the taskbar to display
the Personal Web Manager window. The
Personal Web Manager window allows you
to administer your Web site. For example,
to stop PWS and make your Web site
unavailable to users, click the Stop button.
To restart PWS, click the Start button.
In addition to wwwroot, several other
directories are created when PWS is
installed. In the Personal Web Manager
window, you can click C:\Inetpub\wwwroot
to display these directories.
I This area displays the
location of the Personal
Web Server home directory.
I If you want to use
a different directory as
the home directory, click
Browse to specify the
directory you want to use.
Click Next to continue.
I When the installation is
complete, a message appears
thanking you for choosing
Microsoft software.
I The Personal Web Server
icon appears on the taskbar.
20
PHP
INSTALL PERSONAL WEB SERVER
Locate and double-click
the setup.exe file for the
Personal Web Server setup
program.
Note: On the Windows 98 CD-ROM
disc, the setup.exe file is located in
the add-ons directory in the pws
subdirectory.
I The Microsoft Personal
Web Server Setup dialog
box appears, displaying
information about Personal
Web Server.
Click Next to continue.
Click the type of
installation you want
to perform.
Note: If you choose Custom,
the following steps will be
different for your installation.
M
icrosoft Personal Web Server (PWS) allows you to
host a single Web site on your own computer to
make Web and PHP pages available for viewing.
This allows you to test and troubleshoot any problems
before transferring the pages to a Web hosting service
on the Internet. Personal Web Server 4.0 is available on
the Windows 98 CD-ROM installation disc.
PWS is not suitable for making information available directly
to users on the Internet, but can be used to share documents
on small networks or intranets.
When installing PWS, you can choose the installation option
that best suits your needs. The Minimum option installs only
the files required to run PWS and is useful when installing
PWS on a computer with limited hard drive space available.
The Typical option installs the most commonly used PWS
files and is the recommended option. The Custom option
allows advanced Web site developers to choose the PWS
files they want to install.
The C:\Inetpub\wwwroot directory is automatically set as the
home directory for PWS. The home directory is where you
will store all the Web and PHP pages you want to be able to
display. If you do not want to use the C:\Inetpub\wwwroot
directory as the home directory, you can set another
directory as the home directory. This is useful if you already
have a directory that stores the pages you want users to be
able to display and you do not want to copy the pages to the
default home directory.
After PWS and PHP are installed, you can begin creating and
accessing Web and PHP pages. You can access pages using a
Web browser installed on the same computer that is running
PWS or a Web browser installed on another computer on the
same network. To install PHP on a Windows-based computer,
see page 22.
INSTALL PERSONAL WEB SERVER
GETTING STARTED WITH PHP 1
Click Finish to exit
the setup program.
I A message will appear
asking you to restart your
computer. Click Yes to
restart your computer.
23
My Documents My Documents My Documents
My Documents
The most recent release of PHP is available
at the www.php.net Web site. If you are
installing a more recent version of PHP than
the one included on the CD-ROM disc that
accompanies this book, you should carefully
review the documentation included with the
software. Newer releases of PHP may work
differently than the version used in this book.
If you wish to install the expanded
version of PHP, you will need a
program capable of unzipping files,
such as WinZip. WinZip is available
at www.winzip.com. You can find
complete installation instructions for
the expanded version in the install.txt
and README.txt files, which are
included with the PHP Zip file. You
should carefully review each of these
files before installing PHP.
Older versions of PHP are still available following
the release of a new version. This is useful for
system administrators who have standardized a
particular version of PHP for use on their Web
servers. Many Web and network administrators
will not immediately upgrade to the latest
available version of PHP unless they wish to take
advantage of a specific feature of the new version.
Administrators often decide to wait until a recent
version of PHP has been widely used so they are
aware of any errors or compatibility problems
before installing the new version.
Click the type of installation
you want to perform.
Note: If you choose Advanced, the
following steps will be different for
your installation.
Click Next to continue. I This area displays the
folder where PHP files
will be installed.
I You can click Browse
to specify a different
folder in which to install
the files.
22
PHP
INSTALL PHP ON A WINDOWS-BASED COMPUTER
Double-click the icon for
the PHP installation program
to start installing the program.
I A welcome dialog box
appears.
I This area displays
information about the
PHP program.
Click Next to continue.
I This area displays a
license agreement you
must read and accept
before continuing.
Click I Agree to accept
the agreement and continue.
I
n order to create and process PHP pages, you need to
install PHP on your computer. Recent Windows versions
of PHP can be used with Microsoft Windows 95, 98, NT,
2000, ME and XP.
A recent release of PHP is included on the CD-ROM disc that
accompanies this book. You can install PHP directly from the
CD-ROM disc. The PHP program is available in a standard
package, which includes a Windows installation program that
allows you to easily install the software. PHP is also available
in an expanded package that includes additional capabilities,
such as database support for different operating systems. The
standard package consists of a single executable file, while
the expanded package is compressed into a Zip file. For
Windows installations, it is usually sufficient to install the
standard package using the Windows installation program.
The computer on which you install PHP does not need to
be connected to the Internet. You can use a stand-alone
computer that has Web server software and the PHP program
installed to develop PHP pages. The pages can then be
transferred to a Web server connected to the Internet or
an intranet. The Web server to which you transfer the PHP
pages can use any type of operating system, such as UNIX.
When you start installing PHP, you must first accept a license
agreement before the installation will continue. The setup
program then allows you to choose the type of installation
you want to perform. The Standard option is recommended
for most users. The Advanced option allows experienced
Web site developers to specify additional options for
installing PHP.
You must also choose the directory where you want the
main PHP files to be stored. The default installation location
is C:\PHP. You can specify another destination folder, but it
is recommended that you accept the default folder.
INSTALL PHP ON A
WINDOWS-BASED COMPUTER
GETTING STARTED WITH PHP 1
CONTINUED
Click Next to continue.
25
My Documents
Internet
Explorer
Connect to
the Internet
Recycle Bin
My Computer
My Network
Places
My Documents My Documents
My Documents
PHP should be installed only on the hard drive
of the Web server. You should not install PHP
on a network drive or on removable media,
such as a Zip drive. While it is technically
possible to install PHP on these types of media,
the performance of the program will deteriorate
as the Web site is accessed more often.
When specifying the e-mail address you want
to display on outgoing e-mail messages, you
may want to use an e-mail address set up
especially for the Webmaster, instead of the
personal e-mail account of the person who
holds the Webmaster position. This lets you
avoid having to reconfigure the PHP settings
if the Webmaster changes in the future.
If the computer stops responding before the
PHP installation is complete, there may be a
problem with the installation program or with
the disk drive where PHP is being installed.
You should close all open programs and restart
the computer before attempting to re-install
the program. If the installation program stops
responding again, you can download another
copy of the installation files from the main
PHP Web site. You should also check the
computer's hard drive for possible errors.
I A dialog box appears,
indicating that you are
ready to install PHP.
I You can click Back to
return to a previous screen
and change the information
you entered.
Click Next to install
PHP on the computer.
I A dialog box appears
when the installation is
complete.
24
PHP
INSTALL PHP ON A WINDOWS-BASED COMPUTER (CONTINUED)
Double-click this area
and type the name of the
outgoing mail server.
I If you do not know the
name of the mail server,
you can type localhost.
Double-click this area
and type the e-mail address
you want to display on
outgoing mail.
Click Next to continue.
Select the type of Web
server you want to be
configured for use with PHP.
I If your Web server does
not appear in the list, you
can select None to configure
the server manually.
Note: PHP may not be able to
automatically configure the Web
server you select.
Click Next to continue.
W
hen installing PHP, the setup program allows
you to specify the name of the mail server the
computer will use to send e-mail messages.
Specifying e-mail information is important if you intend to
create PHP scripts that will send e-mail messages. Mail
servers used to send e-mail messages use the Simple Mail
Transfer Protocol (SMTP) and are often referred to as SMTP
servers. The network administrator or ISP should be able to
tell you the name of the mail server used to send messages.
If you do not have access to an SMTP server, you can type
"localhost" as the mail server name.
You should also specify the e-mail address you want to
display on outgoing e-mail messages. You would usually
specify the address of the Web server administrator, usually
referred to as the Webmaster.
PHP can automatically perform many of the configuration
tasks necessary to allow the PHP program to be used
correctly with some types of Web servers, such as Internet
Information Server (IIS). The setup program allows you
to select the type of Web server you will use with PHP.
Depending on the Web server you select, PHP may
automatically configure the server to work with PHP.
When you have specified all the installation options, you
can install PHP on your computer. The program should
take only a few minutes to install.
After PHP has been installed, you can configure PHP to suit
your needs using the php.ini file included with the program.
For more information about configuring PHP, see page 26.
You may also need to configure the Web server you want
to use with PHP. To configure Apache Web server, see
page 10. For information about configuring another type
of Web server, refer to the server's documentation.
INSTALL PHP ON A
WINDOWS-BASED COMPUTER
GETTING STARTED WITH PHP 1
Click OK to close
the dialog box and then
restart the computer.
27
On computers running the Windows
operating system, the php.ini file should be
stored in the main Windows directory, such
as C:\WINNT or C:\WINDOWS. On Unix
systems, the location of the php.ini file can
vary, but the file can often be found in the
/usr/local/lib/ directory.
When you enable extensions in the php.ini
configuration file, you may have to specify
where the files for the extensions are stored.
All extension files are stored in a directory
called extensions. By default, the extensions
directory is a subdirectory of the main PHP
directory. If the extensions directory is
stored in another location, you can use the
extension_dir directive in the php.ini
file to specify the location of the directory.
The extension_dir directive can be found
under the Paths and Directories
comment. In the following example, the
extensions directory is a subdirectory of
the C:\webfiles directory.
Example:
extension_dir = c:\webfiles
PHP is comprised of many modules that are
used to perform different tasks, such as the
MySQL module, which is used to work with
MySQL databases. The php.ini file can be
used to change and specify module settings.
Typically, each module has its own section
heading, such as [MySQL] or [Sybase].
Any text enclosed in brackets [] is ignored.
You can view more detailed information
about configuring PHP at the
www.php.net/manual/en/configuration.php
Web site.
To change the maximum
amount of memory a
script can use, locate the
memory_limit directive.
Delete the current
value and then type the
value you want to use.
ENABLE AN EXTENSION
To enable an extension,
locate the Dynamic
Extensions comment.
Locate the extension
directive you want to enable.
26
PHP
CONFIGURE PHP
Locate and open the
php.ini file in a text editor.
CHANGE RESOURCE LIMITS
Locate the Resource
Limits comment.
To change the maximum
amount of time a script
can execute, locate the
max_execution_time
directive.
Delete the current
value and then type the
value you want to use.
Y
ou can use the php.ini file to configure PHP to suit
your needs. The php.ini file is a text file that controls
how PHP processes scripts and is read by the Web
server when PHP is started.
You can edit the php.ini file using a simple text editor,
such as Notepad on a Windows computer, or vi, a text
editor available on most Unix computers.
The format of the php.ini file is very simple. The file
contains new lines and whitespace, which make the file
easy to read. The new lines and whitespace are ignored
and so do not affect the speed at which PHP operates.
The php.ini file also contains comments, denoted by a
semicolon. All the information from a semicolon to the
end of the line is ignored.
The php.ini file is comprised of many directives that
control the behavior of PHP. A directive consists of a
directive name followed by an equal sign (=) and a value.
For example, the directive used to turn off error logging
is log_errors = Off. You can change the value of a
directive to change the way PHP operates. For example,
you can change how long a script can execute or how
much memory a script can use. Each directive appears
on its own line in the file.
A semicolon precedes some of the directives in the
php.ini file, such as the directives that implement
extensions. These directives are commonly used directives
that can be enabled simply by deleting the semicolon.
For example, you can remove the semicolon that precedes
the extension=php_gd.dll directive to allow PHP
to generate images on the fly. Enabling an extension
allows you to add extra functionality to PHP.
CONFIGURE PHP
GETTING STARTED WITH PHP 1
Delete the semicolon
that precedes the
extension directive.
Save the changes you
made to the php.ini file.
29
If the Web server and PHP information
does not appear when you view the test file,
you should review the topics in this book
concerning the installation and configuration
of the Web server and PHP. You should also
review the documentation that came with
the Web server and your version of PHP.
If you do not want the phpinfo function to
display all of the available information about
the Web server and PHP, you can specify
the type of information you want to display.
To display only specific information, you
can include one of the following arguments
in the phpinfo function: INFO_GENERAL,
INFO_CREDITS, INFO_CONFIGURATION,
INFO_MODULES, INFO_ENVIRONMENT,
INFO_VARIABLES or INFO_LICENSE.
Example:
phpinfo(INFO_VARIABLES)
The name and location of a Web server's
document root directory depends on the
operating system installed, the type of Web
server and the installation choices made
when the Web server software was installed.
On Windows-based computers running
Internet Information Server (IIS) or Personal
Web Server (PWS), the document root
directory is typically C:\Inetpub\wwwroot.
On Windows-based computers running
the Apache Web server, the document root
directory is typically C:\Program Files\Apache
Group\Apache\htdocs. On Unix computers
running the Apache Web server, the
document root directory is typically
/usr/local/apache/htdocs or /home/httpd/html.
You can use any text editor to create the PHP
test file. When saving the file, ensure that
the file is saved in a text-only format.
Start a Web browser.
Click this area to
highlight the current
Web page address.
Type http://.
Type the name or
IP number of the Web
server followed by /.
Type the name of
the test file and then
press Enter.
I If the Web server
and PHP are functioning
properly, the Web browser
displays information about
the Web server and the
current state of PHP.
28
PHP
VERIFY THAT PHP IS INSTALLED CORRECTLY
Start a text editor.
Type the opening
delimiter <?php.
To display information
about the Web server and
PHP, type phpinfo();.
Type the closing
delimiter ?>.
Save the test file in the
document root directory
of the Web server.
I The filename must end
with the .php extension.
You may have to enclose
the filename in quotation
marks.
O
nce the Web server software and PHP have been
installed and the server has been configured to
use PHP, you should verify that the Web server
and PHP are working together properly. To do so, you can
create a simple PHP test file and save the file on the Web
server. You can then display the file in a Web browser.
The test file contains the phpinfo function enclosed
between the <?php opening delimiter and the ?> closing
delimiter. The delimiters tell the Web server where the
PHP code begins and ends. A semicolon must follow the
phpinfo function.
The phpinfo function is used to display information
about the setup and configuration of the Web server and
PHP. Using this function allows you to verify that the Web
server and PHP are working together properly, as well as
confirm installation and configuration choices.
The test file should be saved in the main, or document
root, directory of the Web server.
To display the test file in a Web browser, you must specify
the address of the file. The address must begin with http://
and include the name or IP number of the Web server.
If the Web browser you will use to view the file is running
on the same computer as the Web server, you can use the
computer name 'localhost' or the IP number 127.0.0.1. This
is the IP number that computers using the TCP/IP protocol
use to refer to themselves.
If the Web server and PHP are functioning properly, the
Web browser displays information about the Web server
and PHP when you display the test file. You can view
general information about PHP, such as the version
number, server information, such as the name of the
document root directory, and detailed information about
PHP extensions and variables.
VERIFY THAT PHP IS INSTALLED CORRECTLY
GETTING STARTED WITH PHP 1
31
Repeat steps 2 to 4
for each file for which
you want to change
permissions.
To view the new file
permissions, type ls l
and then press Enter.
I An updated list of files
appears, displaying the
new file permissions.
30
PHP
CHANGE UNIX FILE PERMISSIONS
To view a list of files
in the current directory
and the permissions for
each file, type ls l at the
prompt. Then press Enter.
I The list of files appears.
This area displays the
permissions for each file.
To change the permissions
for a file, type chmod.
Type the octal value that
represents the permissions
you want to assign to the file.
The octal value should be
preceded by a 0.
Type the name of the
file to which you want to
assign the permissions.
Then press Enter.
Note: To assign the same
permissions to more than one
file, you can type the name of
each file after the octal value.
E
ach file on a Unix computer includes a set of
permissions that determine who can access,
change or execute the file. The permissions for
a file can be changed to control access to the file.
Only the owner of a file or the system administrator
can change the permissions for a file.
To view the current permissions for a file, you can use
the ls -l command to display a list of all the files in
a directory. The permissions are usually displayed to the
left of each filename.
On Unix systems, files can be assigned read (r), write (w),
and execute (x) permissions. The permissions for a file
are typically represented by a dash followed by a series
of nine characters. The first three characters represent the
permissions for the file's owner. The next three characters
represent the permissions for the owner's group and the
last three characters represent the permissions for all other
users. For example, -rwxr--r-- indicates that the owner has
been assigned read, write and execute permissions and
the group and other users have been assigned only read
permission.
New file permissions are usually set using the chmod
command. The chmod command takes two arguments.
The first argument specifies a value that represents the
file permissions, while the second argument specifies
the name of the file to which the permissions are to be
assigned.
The value that represents file permissions is usually
specified using octal notation. Octal notation uses a
base-8 numbering system. The octal value consists of
three digits, which represent the permissions for the
owner, followed by the permissions for the owner's
group and the permissions for other users. For example,
the -rwxrw-r-- permissions will have an octal value of 764.
You should precede the octal value with a zero (0).
CHANGE UNIX FILE PERMISSIONS
GETTING STARTED WITH PHP 1
You can use this chart to determine and change
the permissions for a file on a Unix computer.
You can change the owner of a file using
the chown command. When using the
chown command, you must specify the
username of the new owner followed by
the name of the file you want to assign
to a new owner. For example, you can
type chown sandyr index.html to give
ownership of the index.html file to the
user sandyr.
You can use the chgrp command to
assign a file to a new group. To use the
chgrp command, specify the name of
the group to which you want to assign the
file followed by the name of the file. For
example, you can type chgrp webadmins
index.html to assign the index.html file
to the webadmins group.
PERMISSIONS: OCTAL VALUE: DESCRIPTION:
--- 0 None
--x 1 Execute only
-w- 2 Write only
-wx 3 Write and execute
r-- 4 Read only
r-x 5 Read and execute
rw- 6 Read and write
rwx 7 Read, write and execute
33
Country KitchenWeb
www.company.com
jsmith
Web hosting services are companies that
make Web pages available on the Web.
When choosing a Web hosting service,
you should consider several factors. For
example, you may want to look for a Web
hosting service with adequate technical
support services to meet your needs.
You should also ensure that your hosting
service offers enough storage space for
any multimedia files included in your
pages. A good Web hosting service will
also be able to supply you with statistics
about your pages, such as where users
are from and any error messages that
may have been generated.
You can create a new directory to store and
organize your Web server connections. In
the Configured Sites area of the Connection
dialog box, click the directory you want
to store the new subdirectory. If you want
to create a main directory, click the Sites
directory. Then click to create the
directory. In the New Folder dialog box,
type the name of the new directory and
then click Finish.
Click this area and type
your password. A symbol (
x
)
appears for each character
you type to prevent others
from seeing your password.
To save your password so
you will not need to retype the
password again later, click this
option ( changes to ).
Click Save to have
the program store the
information you entered
for the connection.
Click the connection for
the Web server you want to
transfer your Web pages to.
I If the connection you set
up is not displayed, click
the plus sign ( ) beside
the Ipswitch directory
( changes to ).
32
PHP
SET UP A CONNECTION CONNECT TO A WEB SERVER
Start the FTP program
you will use to transfer your
Web pages to a Web server.
I The Connection dialog
box appears.
Click to display the
New Site dialog box and set
up a new connection to the
Web server.
Type a name for the
connection.
Click this area and type
the address of the Web
server you want to transfer
your Web pages to.
Click Finish to continue.
I The name of the
connection appears
in this area.
I The address of the
Web server you specified
appears in this area.
Click this area and
type your user ID.
I
f you do not have a Web server that can make your
Web and PHP pages available on the Web, you must
transfer the pages to a Web hosting service's Web
server. You need a File Transfer Protocol (FTP) program
to transfer your Web and PHP pages to a Web server.
WS_FTP Pro for Windows is a popular FTP program.
In the example below, we use WS_FTP Pro version 6.7.
You can obtain the latest version of WS_FTP Pro at the
www.ipswitch.com Web site.
Before you can transfer Web and PHP pages to a Web
hosting service's Web server, you must set up a connection
to the server. FTP programs can connect and transfer files
to different types of Web servers using different types
of operating systems. For example, you can use an FTP
program to transfer PHP pages developed on a Windows
computer to a Unix computer.
To set up a connection to a Web server, you must know
the address of the server, your user ID and your password.
If you do not know this information, contact your Web
hosting service. Many FTP programs allow you to save
your password, which saves you from having to retype
your password each time you transfer Web pages to the
Web server. When you save your password, anyone who
uses your computer will be able to connect to the Web
server, so you should not save your password if other
people have access to your computer.
You need to set up a connection to a Web server only
once. After you set up a connection, you can connect
to the server at any time.
TRANSFER PAGES TO A
WEB HOSTING SERVICE
GETTING STARTED WITH PHP 1
CONTINUED
FTP programs allow you to set up multiple
connections. This is useful if you want
to use one connection to transfer your
Web and PHP pages to a Web server and
another connection to download files from
a different Web server. Perform steps 1 to 9
starting on page 32 for each connection
you want to set up.
Click Connect to
connect to the Web
server.
35
www.company.com
recipes . htm
www.company.com
My Webs
www.company.com
public
www.company.com
You should check all references to files
on your Web and PHP pages before
transferring the pages to a Web server. For
example, if an image on a page is stored
in the same directory as the page, make
sure you specified only the name of the
image (example: banner.gif). If the image
is stored in a subdirectory, make sure you
specified the location and name of the
image (example: images/banner.gif).
If you have accidentally transferred a
file to the Web server, you should delete
the file from the server. This helps save
storage space and prevents clutter on the
Web server. To delete a file from the Web
server, select the file in the right pane of
the WS_FTP Pro window and then click
the Delete button. To confirm the deletion,
click Yes in the dialog box that appears.
If you use a Macintosh computer to create
your PHP pages, you can use the Fetch
FTP program to transfer your pages to a
Web hosting service. Fetch is available at
the www.fetchsoftworks.com Web site.
You can delete a connection you no
longer need. Click the connection in the
Configured Sites area of the Connection
dialog box and then click to delete
the connection. To confirm the deletion,
click Yes in the dialog box that appears.
Click the file or directory
you want to transfer to the
Web server.
Click to transfer
the file or directory to
the Web server.
I The file or directory
appears on the Web server.
Repeat steps 3 to 6 for
each file and directory you
want to transfer.
34
PHP
TRANSFER PAGES TO A WEB HOSTING SERVICE
I The WS_FTP Pro
window appears.
I This area displays the
directories and files stored
on the Web server.
Locate the directory you
want to transfer your Web
pages to. In many cases, the
directory is named "public."
Double-click the
directory to display the
contents of the directory.
I This area displays the
directories and files stored
on your computer.
Locate the directory
that contains the Web or
PHP page(s) you want to
transfer to the Web server.
Note: You can double-click
to move up one level in the
directory structure.
Double-click the
directory to display the
contents of the directory.
O
nce you have connected to a Web hosting service's
Web server, you can transfer information to the
server. You can transfer a single file, multiple files
or an entire directory to the Web server in one operation.
Before transferring your Web or PHP pages to a Web
server, you should make sure the filenames all have the
.html, .htm or .php extension and do not include spaces
or special characters, such as
*
or &. You should also
check with your Web hosting service to ensure that you
have used the correct name for your home page.
You must also locate the directory on the Web server you
want to transfer your files and directories to. This directory
is often named "public." If you do not know the name of
the directory, contact your Web hosting service. Your Web
hosting service may also stipulate where you can place
PHP files on the Web server.
If your connection to the Web server is idle for an extended
period of time, the server may automatically disconnect
you. This helps ensure that the Web server's resources are
available for other people who need to access the server.
If you later make changes to the Web or PHP pages stored
on your computer, you must transfer the updated pages
to the Web server. The updated Web or PHP pages will
replace the old pages on the server. When you transfer
updated pages, a message may appear, indicating that the
updated pages will replace the old pages.
Many Web and PHP pages work together and require other
pages in order to work correctly. When transferring files,
you should ensure that you also transfer any needed
support files.
TRANSFER PAGES TO A
WEB HOSTING SERVICE
GETTING STARTED WITH PHP 1
Click Close to end
the connection to the
Web server.
Click Exit to exit
the program.

S-ar putea să vă placă și