Home > Articles > Home & Office Computing

  • Print
  • + Share This
This chapter is from the book

This chapter is from the book

Hosting WordPress Yourself

You can install the WordPress software on any computer with web server software installed, even if that computer has no permanent connection to the Internet. That means you could even use that old computer with the dial-up modem (or none at all) that has been gathering dust in your basement. Why would you want to have WordPress installed on your own computer? How would people read your blog if it wasn't connected to the Internet? We can think of at least four good reasons to install WordPress on your system—even if your "real" WordPress blog was hosted somewhere else, be it WordPress.com or at your own host:

  • You are an angry person and view blog posts as a way of venting steam. You want a place to tell your boss what you really think of him without threatening your career. Plus, you like the WordPress visual editor and don't need a full-blown, feature-rich web design tool to write.
  • You have been on WordPress.com for a while and want to see whether you can install the WordPress software yourself before committing to buying a domain name and a year's worth of hosting fees.
  • You are considering changing themes and adding plug-ins, and you want to test things out before going live on the Web.
  • You want to create new WordPress themes and plug-ins and don't want to upload your files to the Web each time you modify one character in the code.

In practical terms, you don't need a reason to give the install a try. With enough time, disk space, and bandwidth, you can do this. With an average high-speed Internet connection, you can complete all of these tasks—downloading and installing an Apache web server, a MySQL database, and WordPress—in about a half hour. We're here to help.

In this section, we'll install a web server on a Windows system and get you ready for the WordPress installation. We'll also show you how to edit the WordPress configuration file manually.

Installing a Test Web Server and MySQL Database

If you are running the Windows operating system (no matter the version), you need to download several applications to successfully run WordPress on your computer: That includes a web server application, the MySQL database, and the WordPress software. If you want to develop plug-ins, you also need the PHP scripting language.

The good news is that the cost of all this software is $0. Yes, that's right; it's free. Another piece of good news is that software developers have packaged the server app and database in a single download for Windows, so there's only one thing to install. The bad news is that you have to invest some time and effort to get it all running.

There are several packages of what is called the WAMP (Windows Apache MySQL and PHP/Perl) Stack available for download. We have had the best experience with XAMPP from the Apache Friends. The X takes the place of the underlying operating system—Windows, Linux, and Macintosh OS X. In this section, we show you how to install and configure XAMPP in Windows to prepare for your WordPress installation. The process in other operating systems should be similar, if not exactly the same.

  1. Download XAMPP from http://apachefriends.org/en/xampp.html.
  2. Install XAMPP by double-clicking on the downloaded file. At the end of the installation, a command-line shell will appear, and the install program will ask you some questions. Unless you know to do differently, accept the defaults.
  3. When the final menu comes up, select Start XAMPP Control Panel.
  4. Start the Apache and MySQL services by clicking the Svc check box next to each module (see Figure 11.20). You'll be asked to confirm each service start.
    Figure 11.20

    Figure 11.20 Start the Apache Web Server and MySQL database services in Windows through the XAMPP Control Panel.

  5. Start the Apache server by clicking the Start button associated with it. Windows Vista and Windows 7 users might see a User Account Control dialog box asking whether you really want to install this application. Click Yes. When it starts, the Control Panel will say it's running, and the Admin button will be active.
  6. Start MySQL the same way. The shell-like status window at the bottom of the Control Panel will also indicate that each service started.
  7. Open a browser and type http://localhost/xampp in the address bar. If Apache is running, you'll first be asked to define your language, and then (if you select English) the screen will look like Figure 11.21.
    Figure 11.21

    Figure 11.21 A successful configuration of Apache through XAMPP!

  8. Open phpMyAdmin to create and configure the database. Go back to the XAMPP Control Panel. Click Admin next to MySQL to launch phpMyAdmin, or click phpMyAdmin in the Tools section from the XAMPP admin page shown in Figure 11.21. This application serves as a graphical front end to the MySQL command-line administrative tool. It's written in the PHP scripting language, as is WordPress. The remaining steps should mirror the database creation steps in the earlier section "Preparing for the Five-Minute Hosted WordPress Installation."
  9. Go to the Privileges tab. Click Add a New User.
  10. In the User Name field, type WordPress (or some other name; see the earlier tip on database user naming). Under Host, use Local. Type a password or use Generate Password (for a more secure, if less memorable, password).
  11. Under Database for User, click Create Database with Same Name and Grant All Privileges, as shown in Figure 11.22. Scroll to the bottom and click the Go button. phpMyAdmin generates the appropriate MySQL commands and displays them under the phrase You Have Added a New User.
    Figure 11.22

    Figure 11.22 Set up the WordPress database from your browser with phpMyAdmin.

  12. Click the Databases tab, and you will see WordPress on the list of existing databases. Click the link to open the database.
  13. Click the Privileges tab to see the list of "Users Having Access to WordPress." Your WordPress user should have All Privileges, and Grant should say Yes, as shown in Figure 11.23. If this is not correct, click the Action box at the end of the row and make sure every database-related privilege box is checked. Scroll to the bottom of the page and click Go when you're finished.
    Figure 11.23

    Figure 11.23 Make sure your WordPress user has all privileges, including Grant, to your database.

  14. Close phpMyAdmin.

Now that you have the web server and database configured, all you need is a fresh copy of WordPress. Download the latest version of WordPress at http://wordpress.org/download and extract it to the XAMPP\htdocs folder.

Editing the WordPress Configuration File

Now the real fun begins. When we configured WordPress on a separate host, we used the WordPress online form. This time, we'll get our hands dirty editing the raw configuration file.

You'll need to open a text editor, such as Notepad, to edit the WordPress configuration file. Be sure you use a text editor, and not a word processor, like OpenOffice Writer or Microsoft Word. Word processors add formatting codes and assorted characters that will confuse your web server and WordPress when it tries to figure out what your configuration choices are. Web servers look for plain text, and you should deliver it to them.

But first, go to Windows Explorer and locate the sample. If you followed the instructions in this chapter, this file should be located at C:\XAMPP\htdocs\WordPress\wp-config-sample.php. Yes, this is a PHP code file, but don't panic. There's not much you need to do here because the comments included in the file are easy to understand. Besides, if you do get confused, we're here to help.

Before you do anything else, click File, Save As to remove the text "sample" from the filename. Save the file as wp-config.php. That way, in the unlikely event something goes wrong, you will always have the sample to return to.

The first section of this file allows WordPress to communicate with the database you've just created. The section should look like this:

/** The name of the database for WordPress */
define('DB_NAME', 'putyourdbnamehere');

/** MySQL database username */
define('DB_USER', 'usernamehere');

/** MySQL database password */
define('DB_PASSWORD', 'yourpasswordhere');

/** MySQL hostname */
define('DB_HOST', 'localhost');

/** Database Charset to use in creating database tables. */
define('DB_CHARSET', 'utf8');

/** The Database Collate type. Don't change this if in doubt. */
define('DB_COLLATE', '');

There are but a few lines to edit in this section:

  • Where it says putyourdbnamehere, replace it with the name of your database (wordpress). Make sure the name is inside the quotation marks; otherwise, it won't work.
  • Where it says usernamehere, replace it with the username you entered in step 10 from the preceding section (which should be the same as the name of the database).
  • Where it says yourpasswordhere, replace it with the password you entered in step 10 from the preceding section.
  • Confirm that the DB_HOST line points to localhost. If it does, don't change it.

The last two items can usually be ignored. DB_CHARSET and DB_COLLATE relate to the character set used by the database. Unless you are using Cyrillic or Asian-language characters, leave these lines at the default settings.

The Authentication Unique Keys section of the configuration file is optional but can help secure your installation. Setting these keys makes it much harder for anyone bent on cracking your blog to steal your login information, and you don't need to remember the contents. This section looks like this:

* Authentication Unique Keys.
 *
 * Change these to different unique phrases!
 * You can generate these using the {@link https://api.wordpress.org/secret-key/1.1/ WordPress.org secret-key service}
 * You can change these at any point in time to invalidate all existing cookies. This will force all users to have to log in again.
 *
 * @since 2.6.0
 */
define('AUTH_KEY', 'put your unique phrase here');
define('SECURE_AUTH_KEY', 'put your unique phrase here');
define('LOGGED_IN_KEY', 'put your unique phrase here');
define('NONCE_KEY', 'put your unique phrase here');
/**#@-*/

At the top of the section, you'll see a link to the WordPress Secret Key service. Copy this address (http://api.wordpress.org/secret-key/1.1/) into your browser, and you'll see four highly secure keys generated for you and you alone. Copy all four lines and paste them back into this section of the wp-config file, replacing the default lines that ask you to put your unique phrase here.

The WordPress Database Table Prefix section exists for those who want to produce multiple blogs from this database. If that's you, WordPress needs to be able to differentiate this blog from your other blogs. It does this by creating separate database tables for each blog. We recommend using wp_ blogname as the identifying table prefix. Your hosting company might also have a recommendation on how to handle the Table Prefix. The section looks like this:

* WordPress Database Table prefix.
  *
  * You can have multiple installations in one database if you give each a unique
  * prefix. Only numbers, letters, and underscores please!
  */
 $table_prefix  = 'wp_';

The last section of the configuration file to worry about is the Localized Language section. This defaults to English; if you want to blog in another language, visit http://codex.wordpress.org/WordPress_in_Your_Language for information on how to set up WordPress in many languages. (That's 64 languages, as of this writing.)

* WordPress Localized Language, defaults to English.
  *
  * Change this to localize WordPress.  A corresponding MO file for the chosen
  * language must be installed to wp-content/languages. For example, install
  * de.mo to wp-content/languages and set WPLANG to 'de' to enable German
  * language support.
  */
 define ('WPLANG', '');

As the creators of wp-config-sample tell you, "That's all, stop editing! Happy blogging!" Save the file again. The hard work is done, and it's time to run the famous five-minute installation, as described earlier in this chapter in "The Five-Minute Hosted WordPress Installation" section.

  • + Share This
  • 🔖 Save To Your Account