Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:

Blog Design Solutions (2006)

.pdf
Скачиваний:
28
Добавлен:
17.08.2013
Размер:
38.67 Mб
Скачать

B L O G D E S I G N S O L U T I O N S

6.Select the option labeled for All Users, on Port 80, as a Service. Apache will run in the background, and you don’t need to worry about starting it. Click Next.

If you already have a web server, such as IIS or PWS running on port 80, you must select the option labeled only for the Current User, on Port 8080, when started Manually. You can change the option to start Apache automatically later.

7.The next dialog box asks you to select the setup type. Select the Typical option, and click Next to continue.

8.You are then given an opportunity to change where Apache will be installed. The default location, C:\Program Files\Apache Group, is fine. Click Next. The final dialog box gives you an opportunity to go back and change any of your options. Assuming that you’re happy, click Install to finish the Apache installation.

9.The process is quite quick, but don’t be alarmed if you see a Command Prompt window open and close several times while the program is being installed. This is perfectly normal. If a software firewall is installed, such as Norton Internet Security (NIS), you will probably see a warning message like the one shown here.

Although NIS recommends blocking all connections, accepting this recommendation will prevent Apache from working correctly. Select the option to allow all connections, or—if you’re feeling particularly cautious—create your own security rules manually. Manual settings will depend on your individual setup.

26

C R E AT I N G A L O C A L T E S T E N V I R O N M E N T F O R Y O U R B L O G

10.If you’re running a local network, Windows might also attempt to block Apache. If you see a dialog box similar to the one shown here, choose the Unblock option.

2

11.Unless you chose the option in step 6 to run Apache on port 8080, open a browser and type http://localhost/ into the address bar. If all has gone well, you should see the test page shown in Figure 2-3.

Figure 2-3. Confirmation that Apache is running successfully on Windows

If you chose the option to start Apache 2 on port 8080, you need to start

Apache first, as described in the next section, and then use the address

http://localhost:8080/.

27

B L O G D E S I G N S O L U T I O N S

12.If you get an error message, it probably means that the Apache server is not running. Start up the server, as described in the next section, and try again. If you still get problems, check C:\Program Files\Apache Group\Apache2\logs\error.log.

Starting and stopping Apache on Windows

Apache 2.0 places a tiny icon (it looks like a red feather with a white circle) in the tray (or notification area) at the right end of the Windows taskbar. This is the Apache Service Monitor, which shows you at a glance whether Apache is running. If it’s running, there is a green, right-facing arrow in the white circle. When Apache has stopped, the arrow turns to a red dot (see screenshots alongside).

Click once on the icon, and you will be presented with a context menu, as shown in the screenshot. This menu provides a quick way of starting, stopping, and restarting Apache.

Changing startup preferences or disabling Apache

It’s very easy to change the way Apache starts. If you want to switch between automatic and manual startup, or if you want to disable Apache temporarily, use the following instructions:

1.Open the Windows Services panel by selecting Start Control PanelAdministrative Tools Services.

2.When the Windows Services panel opens, highlight Apache2, rightclick, and select Properties.

3.From the Startup type drop-down menu (see the screenshot alongside), select Automatic, Manual, or Disabled. If you want to start or stop Apache at the same time, click the appropriate Service status button before clicking OK.

The Apache Services Monitor will display in the taskbar tray every time your computer starts, even if you switch to manual operation or disable Apache.

28

C R E AT I N G A L O C A L T E S T E N V I R O N M E N T F O R Y O U R B L O G

Setting up PHP on Windows

These instructions are for a completely new installation of PHP. If PHP has never been installed on your computer, simply follow the instructions.

However, if you have an old installation of PHP, you must first remove any PHP-related files from your main Windows folder (C:\WINDOWS or C:\WINNT, depending on your system) and

the system32 subfolder. Changing the contents of the Windows system folders is not to be 2 undertaken lightly, so I suggest that you cut and paste them to a temporary folder, instead

of just deleting them,. Then, if anything goes wrong, you can easily restore them.

The PHP files you need to remove are php.ini (in the main Windows folder), and php4ts.dll or php5ts.dll in the system32 subfolder. You should also remove any other PHP-related DLL files from the system32 subfolder. They are easy to recognize because they all begin with php. If there’s a copy of libmysql.dll in your Windows system folder, remove that, too.

These instructions are based on PHP 5.1.1, which is the stable version at the time of this writing. The release of PHP 5.1 in late November 2005 introduced PHP Data Objects (PDO), which greatly simplify communication with databases. That’s the good news. The bad news is that hosting companies are notoriously slow to upgrade to major new versions of PHP. Until there is sufficiently widespread support for PDO, the blogging solutions presented in this book will continue to rely on MySQL-specific database functions. Consequently, there will be no further discussion of PDO in this book.

select the Windows binaries ZIP file for the hosting company is still running PHP 4,

.x zip package. It’s about 8.6MB. I suggest you’re likely to run into problems if 4. The blogging packages should all run

of PHP and MySQL. If for any reason they them because they’re likely to break whenupgrades.

PHP download page, a Windows installer of you will be tempted to use it. Resist the runs PHP in a very restricted way and is

. The method I am about to show you system or web server, so in the unlikely

be removed completely safely.

29

B L O G D E S I G N S O L U T I O N S

When you click the download link, you will be presented with a list of mirror sites. Choose the one closest to your location and download the ZIP file to a temporary folder on your hard disk.

2.Unzip the contents of the ZIP file to a new folder called C:\php5. Check that the new folder contains about 30 files and several folders at the top level, as shown here. The path to php5apache2.dll should be C:\php5\php5apache2.dll.

If you choose a location different from C:\php5, you need to substitute the name of your new folder in all later steps. You should avoid locating the PHP files in a folder that contains spaces in either its name or pathname because it can create problems with the Apache configuration.

30

C R E AT I N G A L O C A L T E S T E N V I R O N M E N T F O R Y O U R B L O G

3.In the php5 folder, locate the file called php.ini-dist, make a copy of it, and rename the copy php.ini. As soon as you rename the file, its associated icon in Windows Explorer will change, as shown alongside, indicating that it’s an INI file that Windows will use to configure PHP each time you start up your web server.

4.Open php.ini in any text editor. Notepad will do, but it’s better to use a dedicated

script editor—such as TextPad (www.textpad.com) or a program such as

2

Dreamweaver that displays line numbers—because finding the relevant sections will be a lot easier.

Lines that begin with a semicolon (;) are treated as comments in php.ini, so make sure any changes you make in the following steps are to configuration settings and not to comments.

5.

6.

7.

8.

31

B L O G D E S I G N S O L U T I O N S

Adding PHP to your Windows startup procedure

be added to your Windows startup

32

C R E AT I N G A L O C A L T E S T E N V I R O N M E N T F O R Y O U R B L O G

3.A smaller dialog box opens. Click inside the Variable value field and move your cursor to the end of the existing value. Type a semicolon fol-

lowed by the name of the PHP folder you created in step 2 of the

previous section (C:\php5). As 2 shown in the screenshot, there

should be no spaces between the existing value or in the new pathname.

4.Click OK. With the Environment Variables dialog box still open, click

New in the System variables pane. Another small dialog box opens, in which you enter the details of the new system variable. In the Variable name field, type PHPRC. In the Variable value field, enter the path of the PHP folder (C:\php5).

5.Click OK to close all the dialog boxes. The next time you restart your computer, Windows will now know where to find all the necessary files to run PHP. You still need to make some changes to the Apache configuration file, so continue with the next section before restarting your computer.

Configuring Apache to work with PHP

Now that all the configuration settings have been made for PHP, you need to make some adjustments to the main configuration file for Apache.

Note that all the pathnames in the Apache configuration file use forward slashes instead of the Windows convention of backward slashes. So, c:\php5 becomes c:/php5. Any pathor filenames that contain spaces must be enclosed in quotes.

1.

33

B L O G D E S I G N S O L U T I O N S

2.Scroll down until you find a long list of items that begin with LoadModule (many of them will be commented out). At the end of the list, add the following on a new line, as shown:

LoadModule php5_module c:/php5/php5apache2.dll

The pathname assumes that you installed PHP in c:\php5. Change it accordingly if you used a different installation folder, and don’t forget to use forward slashes in the pathname. Enclose the path in quotes if there are spaces in any of the folder names.

3. Scroll down again until you find the section shown in the following screenshot.

When working with PHP and/or CGI scripts, Apache automatically looks for all web pages in the server root (or DocumentRoot as Apache calls it). This is so it can process (or parse) the scripts and send the right information to both the database and the browser. The two lines indicated by an arrow (lines 230 and 255 in the screenshot) are where you specify the location of the server root. In a browser this becomes the equivalent of http://localhost/.

34

C R E AT I N G A L O C A L T E S T E N V I R O N M E N T F O R Y O U R B L O G

Because this folder is where all your web files will be stored, it’s not a good idea to

 

keep them in the same place as your vital program files. So whenever I set up a new

 

computer, I always create a dedicated folder called htdocs at the top level of my C

 

drive, and I put all my websites in subfolders of htdocs. I chose that name because

 

it’s the traditional name used by Apache for the server root folder. You can use

 

whatever name you like, but I suggest you do the same. Change both lines to indi-

 

cate the same location, like this:

2

DocumentRoot "C:/htdocs"

 

#

 

# Omitted section

 

#

 

<Directory "C:/htdocs">

 

4.Scroll down a bit further until you come to the following command (around line 323):

DirectoryIndex index.html index.html.var

This setting tells web servers what to display by default if a URL doesn’t end with a filename, but contains only a folder name or the domain name (for instance, www.friendsofed.com). Apache will choose the first available page from a spaceseparated list. The whole purpose of this book is to work with PHP, so you need to add index.php.

DirectoryIndex index.html index.html.var index.php

The rather strange-looking index.html.var is used in a specialized feature known as content negotiation, which can automatically serve up different language versions of the same page by detecting the default language of the computer’s operating system. I don’t recommend its use, but if you’re curious, see http://httpd.apache.org/docs-2.0/content-negotiation.html.

5.Close to the end of httpd.conf, you’ll find a section that includes several commands that begin with AddType. Add the following line in that section on a line of its own, as shown:

AddType application/x-httpd-php .php

6.Save and close httpd.conf.

7.You now need to create a test file in the folder you designated as server root in step 3. Open Notepad and enter the following line of code:

<?php phpinfo(); ?>

35