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

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

9.The recommended way of running MySQL is as a Windows service, as shown. If you accept the defaults as shown in the top half of the next dialog box, MySQL will always start automatically when you boot your computer and run silently in the background. (If MySQL has already been installed as a Windows service this section will be grayedout.) If, for any reason, you don’t want MySQL to start automatically, uncheck the Launch the MySQL Server automatically option. You can easily change this option later (see the later section “Starting and stopping MySQL manually on Windows”).

The lower half of the dialog box gives you the option to include the bin directory in your Windows PATH. This option enables you to interact directly with MySQL and its related utilities at the command line without the need to change directory every time. You won’t need to do this very often—if at all—but selecting this option makes life a little more convenient if the occasion ever arises. By the way, bin stands for binary; it has nothing to do with the Windows Recycle Bin. Click Next.

If you get a warning message like this, it means that MySQL is already installed as a Windows service. If you click Yes, the wizard will continue happily, but then fail at the final hurdle. (I know—I found out the hard way.) You must click No and choose a different name from the drop-down menu in the Service Name field.

10.A fresh installation of MySQL has no security settings, so anyone can tamper with your data. MySQL uses the name root to signify the main database administrator with unrestricted control over all aspects of the database. Choose a password that you can remember, and enter it in both boxes. Unless you access your development server from a different computer over a network, leave the Enable root access from remote machines check box unchecked.

46

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

Do not check Create An Anonymous Account. It will make your database very insecure.

If you are upgrading an existing version of Windows Essentials and want to keep your current root password, deselect the Modify Security Settings check box.

Click Next when you have finished.

2

11.At long last, everything is ready. Click Execute. If you have installed a software firewall, such as Norton Internet Security, it will probably warn you that MySQL is trying to connect to a DNS server. You must allow the connection; otherwise, MySQL will never work.

12.Assuming that all was okay, you should see this screen, which confirms that everything went smoothly. MySQL should now be running—even if you selected the option not to start automatically (the option applies only to automatic start on bootup).

47

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

13.If you want to change the configuration at a later date or remove MySQL as a Windows service, launch the Configuration Wizard from the Windows Start button by choosing Programs MySQL MySQL Server 5.0 MySQL Server Instance Config Wizard. You will be presented with the dialog box shown here.

This dialog box gives you the option to change the various settings by going through all the dialog boxes again or removing the server instance. This second option does not remove MySQL from your system, but it is intended for use if you no longer want Windows to start MySQL automatically each time you boot your computer. Unfortunately, it removes not only the automatic startup, but also the configuration file. The section “Starting and stopping MySQL manually on Windows” offers a less-radical solution.

Changing the default table type on Windows Essentials

The instructions in this section are required only if you selected Multifunctional Database in step 4 of “Configuring MySQL Windows Essentials.”

The Windows Configuration Wizard sets InnoDB as the default table storage engine for a multifunctional database. To work with blogging engines, you should reset the default to MyISAM. All it requires is a simple change to the MySQL configuration file: my.ini.

1.Use Windows Explorer to navigate to the folder in which MySQL was installed. The default is C:\Program Files\MySQL\MySQL Server 5.0.

2.Locate the file called my.ini, and double-click it. The file will open in Notepad, ready for editing.

3.Approximately 80 lines from the top you should find a line that reads as follows: default-storage-engine=INNODB

Change it to the following: default-storage-engine=MyISAM

48

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

4. Save the file and close it. To make the change effective, restart MySQL. MySQL will now create all new tables in the default MyISAM format. To use the InnoDB format for a database, you can change the table type in phpMyAdmin, the graphical interface for MySQL that you will install later in the chapter.

Starting and stopping MySQL manually on Windows

Most of the time, MySQL will be configured to start up automatically, and you can forget

2

about it entirely. There are times, however, when you need to know how to start or stop

 

MySQL manually—whether for maintenance, to conserve resources, or because you’re

 

paranoid about security (a physical firewall is probably a much better solution).

 

1.

Select Control Panel from the Windows Start menu. Double-click the Administrative

 

 

Tools icon and then double-click the Services icon in the window that opens.

 

2.

In the Services panel, scroll down to find MySQL and highlight it by clicking once.

 

 

You can now use the video recorder–type icons at the top of the panel to stop or

 

 

start the server, as shown. The text links on the left of the panel do the same.

 

 

 

 

 

 

 

 

 

 

 

3.To change the automatic startup option, highlight MySQL in the Services panel, right-click to reveal a context menu, and choose Properties.

4.In the dialog box that opens, activate the Startup type drop-down menu and choose Automatic, Manual, or Disabled. Click OK. That’s all there is to it.

49

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

Using the MySQL monitor on Windows

Although most of your interaction with MySQL will be through your blogging engine or phpMyAdmin, it’s useful to know how to access MySQL the traditional way through the MySQL monitor (or the Command Line Client, as it’s called in Windows Essentials). It’s also a good way to test that your installation went without problems.

To start a session From the Windows Start button, select Programs MySQL MySQL Server 5.0 MySQL Command Line Client. This will open the Command Line Client and ask you for your password. Type in the root password that you chose in step 10 of the section “Configuring MySQL Windows Essentials” and press Enter. As long as the server is run- ning—and you typed your password correctly—you will see a welcome message similar to the one shown here.

If you get your password wrong, your computer will beep and close the window. If you find this happening repeatedly, even though you’re sure you typed in your password correctly, there are two likely explanations. The first is that your Caps Lock key is on—MySQL passwords are case-sensitive. The other is that the MySQL server isn’t running. Refer to the previous section on how to control MySQL manually before doing too much damage by banging your forehead on the keyboard.

Being unable to connect to MySQL because the server isn’t running is probably the most common beginner’s mistake. The MySQL server runs in the background, waiting for requests. Opening the Command Line Client does not start MySQL; it opens the MySQL monitor, which is a channel for you to send instructions to the server. Equally, closing the Command Line Client does not stop MySQL. The server continues running in the background until the computer is closed down or until you stop it manually.

 

at

the

will

Now

few

pages

 

50

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 on Mac OS X

After leafing through so many pages of Windows instructions, you might be surprised that

 

this section is considerably shorter. It’s shorter because Apache and Perl are preinstalled

 

on Mac OS X. PHP is also preinstalled, but the default version is not suitable for working

 

with the latest version of MySQL. Fortunately, an excellent Mac PKG file is available for

2

free download, which will provide you with a full-featured, up-to-date version of PHP 5.

Most of the setup is done through the familiar Mac interface, but you need to edit some configuration files. Although these are ordinary text files, they are normally hidden, so you can’t use TextEdit to work with them. Instead, you need a specialist text editor, such as BBEdit, which is capable of editing hidden files.

If you don’t own a suitable text editor, I suggest that you download a copy of TextWrangler from www.barebones.com/products/textwrangler/. TextWrangler is a cut-down version of BBEdit; it has fewer features, but is perfectly adequate for what’s required here—and it’s free. All the instructions have been tested on both BBEdit and TextWrangler.

These instructions have been tested on Mac OS X 10.3 and 10.4. They do not cover Mac OS X Server, which uses a different version of Apache, and comes with MySQL preinstalled. I have assumed that if you have the skill to run the server version of OS X, you should be able to handle the configuration without further assistance.

Using

that

web

server

and

other

need

to

priv-

ileges

 

51

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

Starting and stopping Apache

1. Open System Preferences and select Sharing in Internet & Network, as shown.

2.In the dialog box that opens, click the lock in the bottom-left corner, if necessary, to allow you to make changes, and enter your password when prompted. Highlight Personal Web Sharing on the Services tab, as shown in Figure 2-5, and then click the Start button on the right. A message will appear, informing you that personal web sharing is starting up. After it’s running, the label on the button changes to Stop. Use this button to stop and restart Apache whenever you install a new version of PHP or make any changes to the configuration files. Click the lock again, if you want to prevent accidental changes.

Figure 2-5. The Apache web server on a Mac is switched on and off in the Sharing section of System Preferences.

52

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.Open your favorite browser and type http://localhost/~username/ into the address bar, substituting your own Mac username for username. You should see a page like that shown in Figure 2-6, confirming that Apache is running. That’s all there is to it.

2

Figure 2-6. Confirmation that Apache is running successfully on Mac OS X

Sometimes, Macs seem to develop a personality of their own. If you have a local network, you might discover that the localhost part of the URL changes to something like deathstar.local or whatever you have called your computer. I have two Macs, one called “Power Book” and the other called “David Powers’ Mac Mini.” These rather uninspired names translate to power-book.local and david- powers-mac-mini.local (illegal characters, such as apostrophes, are removed, and spaces are replaced by hyphens). The advantage is that I can access sites on my PowerBook from the Mac Mini and vice versa. However, for testing on the same machine, localhost is much shorter to type. After you use localhost a few times, your Mac will probably give up trying to be so clever and accept the shorter version. You can also use 127.0.0.1 as a synonym for localhost.

53

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

Where to locate your web files

As the message in Figure 2-6 indicates, the place to store all your web files, including any blogs that you decide to test, is in the Sites folder in your home folder. You need to keep them there not only for the sake of tidiness but also because Apache needs to process (or parse) PHP and CGI scripts before it can display the output in your browser. Unlike ordinary web pages, you can’t just double-click them in Finder and expect them to pop up in Safari or your default browser. To view a page that uses PHP and/or CGI on your local computer, you must enter the correct URL in the browser address bar in the same way as you access a site on the Internet.

The address for the top level of your Sites folder is http://localhost/~username/. Any subfolders are accessed by adding the folder name to the end of the URL. If you plan to test each of the blogging engines in the rest of this book, it’s a good idea to create a subfolder for each one in Sites.

If you’re the only person using the computer, you might prefer to locate all your files in

Macintosh HD:Library:WebServer:Documents. It works exactly the same way, but instead of needing to include a tilde (~) followed by your username in the URL every time, you use just http://localhost/ as the address. If you test it now, you will see the same screen as shown in Figure 2-4. It makes no difference whether you use the central location or your own Sites folder. Just choose whichever is more convenient for you.

Using PHP on Mac OS X

Although Mac OS X comes with PHP preinstalled, it’s a very cut-back version and is not automatically enabled. What’s more, enabling it is nowhere near as straightforward as switching on Apache. To make matters even worse, the engine underlying Mac OS X is Unix, and without a solid understanding of Unix, installing PHP the traditional way can turn into a nightmare if anything unexpected happens.

Now the good news. The Mac PHP community owes a great debt of gratitude to a software engineer called Marc Liyanage, who creates precompiled packages for all major upgrades of PHP. The only drawback is that these packages involve a large download (about 28MB). Even if you have a slow Internet connection, the large download is worth it. You get a fullfeatured version of PHP that works “straight out of the box.” If you run into problems, there’s a searchable support forum on Marc’s website, on which answers tend to be fast and accurate. It should be your first port of call in case of installation problems.

PHP relies heavily on the availability of external code libraries. It is essential that you have installed all the latest Apple system software updates before proceeding.

54

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

Downloading and installing a precompiled PHP package

1. Marc Liyanage creates different packages for Apache 1.3 and Apache 2. The default installation in Mac OS X at the time of this writing is Apache 1.3, but it’s important to check whether it’s the same in your case. In Finder, open the Utilities folder in

Applications and launch Terminal.

2

2. A window like the one shown here opens.

It doesn’t look very impressive, but if you’ve ever worked on a Windows or DOS computer, it should be familiar as the Command Prompt, and it performs the same function. All instructions to the computer are inserted as written commands at what’s known as the shell prompt. This is the final line in the screenshot and it looks something like this:

Vigor19:~ davidpowers$

The first part (before the colon) is the name of your Macintosh hard disk. The tilde (~) is the Unix shorthand for your home directory (or folder). It should be followed by your username and a dollar sign. As you navigate around the hard disk, your location is indicated in place of ~. All commands in Terminal are followed by Return.

3. To find out which version of Apache is running on your Mac, type the following command:

httpd -v

After pressing Return, you should see a window similar to the one shown here.

This window tells you the version of Apache and the date it was built. You need the first two numbers of the server version—in this case, 1.3—to ensure that you download the correct PHP package.

55