Install WordPress on WEMP (Windows, nginx, MySQL and PHP)

Install WordPress on WEMPNowadays, even desktop computers are powerful enough to run server software. For blog theme designers and plugin developers, this really benefits them because they finally can install an experimental server to play with.

WAMP system by far is the most popular blogging server for desktop computers. It takes advantage of Windows, Apache, MySQL and PHP which are also used in production environment, but more commonly run in Linux and UNIX setup.

While Apache is able to adopt to almost every situation, it is not ideal for servers with lower memory. Desktop computers which are going to be used as weblog server could make use of extra memory because the owners still run various applications on top of those workstations.

The idea behind this tutorial is to produce efficient blog server setup.

Not only can you claim back your precious computer memory, but it also results in a faster and more responsive windows blog server.

The whole setup takes advantage of open source blog server software. Nginx itself is licensed under BSD-like license, which basically means you can do whatever you want with it as long as you keep the copyright notice intact.

I am not a lawyer, so don’t take my words in the previous paragraph for legal decision.

WEMP in Summary

Nginx (pronounced Engine X) is a HTTP server and mail proxy. As of this writing, the stable version is version 0.6.32. Despite its version number, it actually is very stable even for production server with a few thousands of requests per second.

WordPress.com uses a few instances of nginx to serve about 1.2Gbit/sec or around 8,000 – 9,000 requests/second.

Does that sound good enough?

By the way, add to the fact that the CPU usage is also very efficient compare to other web server software especially Apache.

Through several tests, I was sold. Currently, I’ve been using nginx for most of my Virtual Private Server (VPS) with no problems at all. If it is good enough for production server, it should be for desktop computer.

And yes, you can install it quite easily.

(The other components are just like the usual WAMP setup with MySQL and PHP under Windows.)

System Requirements

My experimental machine is run on Windows Vista. The WEMP setup doesn’t requires anything specific. If you are want to try this under Windows XP, the process should be exactly the same and it should also work flawlessly there.

As to memory requirements, it is hard to predict. When starting the server software for the first time, they may consume less memory but as you run it for a while and it has quite some data in the database, they will need more memory.

mysqld requires only a bit more than 1MB when started the first time (no database but the internal data). php-cgi occupies around 5MB at first.

However, after running WordPress for some time…

  • nginx still occupies a bit more than 2MB. You’re going to like this, aren’t you?
  • PHP running in FastCGI is about 6.5MB.
  • MySQLd takes around 11MB.

The total memory consumption is ~ 20MB. Of course, that depends on how you optimize MySQL or how much data do you have in the database. The point is, you probably have known about PHP and MySQL, but isn’t the figure for nginx encouraging?

WEMP Memory Consumption

Compare this to Apache. Memory consumption of 50 – 300MB per process is not unheard of, and in fact it is quite common. Note that I’m not comparing apple to apple, but you don’t need all the additional features in Apache. Another thing worth considering is CPU load.

Nginx is currently my favorite setup, although because of portability issue for FastCGI, it is not able to run Movable Type.

Getting Started with WEMP Installation

nginx LogoI presume that the “W” part, which is Windows, is already done. Unless you are viewing this page through another computer, chances are you have already had a Windows installation on your desktop computer or laptop.

So let’s go ahead and proceed with nginx. This web server software is so stable that you can run the latest development version without any problem, but just to be on the safe side, you should download the latest stable version of nginx.

Installation of nginx is very simple. Just launch the installation program after download and proceed through the wizard. You don’t have a lot of options to choose, just standard options to create icons on your desktop and quick launch taskbar. Nothing can be simpler.

Note: During the installation, you will be given basic information on how to start and stop the nginx service. You will test it out in the next section.

The standard location for nginx installation under Win32 is C:\nginx.

Configuring and Running nginx

Right off the bat after the installation, you will find two batch scripts to start and stop nginx. They are located in C:\nginx\conf. These two batch files are also linked from C:\nginx.

start-nginx.bat is used to start nginx while the stop-nginx.bat batch file is to stop the service. Later you will edit these two batch files to start and stop MySQL and PHP from one place.

Note these are the same scripts that you use when you run the Start nginx or Stop nginx commands from Start Menu.

If you are ready to get started, run the Start nginx from StartAll Programsnginx.

A dialog box asking if you want to make exception on Windows Firewall shows up. If you want to access nginx from computers outside of the machine it is installed on, you should choose Unblock. Otherwise, selecting Keep blocking still allows you to access the web server via your own machine — through the loopback interface.

This may not appear if you don’t turn the Windows Firewall option on though.

Allowing nginx in Windows Firewall

You can change this by going to Windows Firewall and locate nginx under the Exceptions tab.

Now try to load the test page up in the browser by typing:

http://localhost

in the address bar of your browser. A screen similar to the following should appear right before you.

Welcome Screen in nginx

If you see it, your installation is successful. You can now change the configuration file, which full path is C:\nginx\conf\nginx.conf. The other files in the same directory are used by the configuration file as necessary (if activated within the configuration).

You should put the web documents in C:\nginx\html. Later when installing WordPress, you will load WordPress files in this directory.

Stopping nginx is as easy. Just run Stop nginx program from the Start Menu, or run the batch file directly.

Configure nginx to Interact with PHP

As of now, you have not yet installed PHP, but because both nginx and PHP run independently in this setup, you can configure the web server first.

PHP will be running in FastCGI mode, so all you need is to ask nginx to send request to process PHP files to PHP listening on a TCP port on localhost. Unlike LightTPD, nginx doesn’t support CGI directly so FastCGI is the only option.

There is nothing to lose though as this setup is more flexible. For instance, if I happen to have a desktop and laptop on the same local network, I could install the PHP running in FastCGI mode on my laptop. The nginx and MySQL could just reside on the desktop.

It certainly make it even lighter

In order to do this, you need to edit the configuration file in C:\nginx\conf\nginx.conf.

  1. Open the file in WordPad. The configuration file is in UNIX text file format, so you will have a problem with it in Notepad. Once you save it in WordPad, you may open the file in Notepad because the process converts the file format to native Windows. Just make sure you open and save the file as text instead of Rich Text Format (RTF).
  2. Scroll down to the location that says pass the PHP scripts to FastCGI server listening on …. Remove the hash signs (‘#’) for that block and modify it to read as follow before saving.
location ~ \.php$ {
  root           html;
  fastcgi_pass   127.0.0.1:10000;
  fastcgi_index  index.php;
  fastcgi_param  SCRIPT_FILENAME  /nginx/html$fastcgi_script_name;
  include        fastcgi_params;
}

You also have to tell nginx to look for index.php in a directory as default file. Look for the root location block and add index.php so it looks like the following.

location / {
  root   /nginx/html;
  index  index.php index.html index.htm;
}

This is important to avoid having to enter full path to a PHP file or getting the 403 permission denied message (http://localhost/wp-admin/ works instead of only http://localhost/wp-admin/index.php. You also need to modify root to full path, but omitting the drive letter.

Running and Stopping nginx, MySQL and PHP FastCGI with Batch File

In previous section, you have tested Engine X, and if that works you are now ready for this step. The WEMP system consists of three main server components. To start and stop them can be a problem if you are constantly testing for different configuration.

By editing the batch file used to start nginx so it starts and stops all the servers as well, you save some time. It is also flexible enough that you may stop it immediately as you finish with your work and need to free more memory for other things.

While it is possible to run MySQL as Windows server, I prefer the batch script executable approach for the above reason.

Here is the content of start-nginx.bat after editing:

1
2
3
4
5
6
7
8
9
@ECHO OFF
ECHO Starting PHP FastCGI...
RunHiddenConsole.exe C:\Program Files\PHP\php-cgi.exe -b 127.0.0.1:10000
ECHO Starting nginx...
c:\nginx\nginx.exe
ECHO Starting MySQL...
RunHiddenConsole.exe "C:\Program Files\MySQL\MySQL Server 5.0\bin\mysqld-nt" --defaults-file="C:\Program Files\MySQL\MySQL Server 5.0\my.ini"
SLEEP 1
EXIT

Copy and paste the text above and overwrite the start-nginx.bat in C:\nginx\conf. Alternatively download start-nginx.bat here.

The script to stop nginx, mysqld and php-cgi is stop-nginx.bat. You also need to overwrite this one or edit existing one from nginx.

1
2
3
4
5
6
7
8
9
10
11
12
@ECHO OFF
ECHO Stopping MySQL...
process -k mysqld-nt.exe >nul
ECHO Stopping nginx...
process -k nginx.exe >nul
process -k nginx.exe >nul
process -k nginx.exe >nul
process -k nginx.exe >nul
ECHO Stopping PHP FastCGI...
process -k php-cgi.exe >nul
SLEEP 1
EXIT

Again copy, paste and overwrite the file with the text above or download stop-nginx.bat here.

With those scripts, you will be able to run and stop nginx, myslqd and php-cgi from one place.

Don’t run the batch file yet. You need to install PHP and MYSQL first… which the following steps are exactly about.

Installing PHP on Windows

PHP LogoPHP installation is pretty simple. Just go to PHP download page and download PHP x.x.x installer. The PHP version used for this demonstration is 5.2.6.

Run the installer executable program, and choose Other CGI when asked for the type of server you will be running. As we are going to run PHP independently in FastCGI mode, that is the option you should choose.

Install PHP as Other CGI

You should seriously consider adding PHP path to your system PATH variable so you can enter php or php-cgi command from any directory in the command prompt to run PHP.

While you can choose the whole extensions, I recommend against it. You can always run the installation package again to add extensions later as you need them.

For now, here are the list of PHP extensions you should seriously consider:

  • Curl
  • GD2
  • MySQL

Recommended PHP Extensions

Then proceed with the installation. By default PHP will be installed in C:\Program Files\PHP.

Running PHP in FastCGI Mode Under Windows

Some people use third party program, such as Spawn-CGI.exe from lighttpd package, but I can’t seem to get it running. However, it is not necessary either.

php-cgi.exe now runs well in FastCGI mode without any third party software. Open a command prompt window and run php-cgi -h to see full options.

Making php-cgi to listen to a <host>:<port> pair is easy. The following command will do it.

php-cgi -b 127.0.0.1:10000

The line instructs php-cgi to bind to localhost, which has an IP of 127.0.0.1 — it is inaccessible outside of your machine — and on port 10,000. This has to match the nginx configuration above.

Now it is much more convenient if you are able to run this without opening a command prompt, isn’t it? Here is a solution.

If you want to get rid of the command prompt window when php-cgi is running, you should download RunHiddenConsole.zip and unzip the executable file in C:\nginx\conf. This program will execute php-cgi, run it in the background but hide the command prompt window so it doesn’t clutter your desktop. (You will use it twice to run php-cgi and mysqld — the latter if you choose not to run it as a Windows service).

Installing MySQL on Windows

MySQL LogoMySQL is the database engine used by WordPress and countless other database-powered applications. That sounds more complex than the above two programs, but really it is the most simple to install of all.

All you have to do is answer questions and choose the right options. This is unlike nginx and PHP installations above.

Now you can relax… all the hard work has been done so far.

First off, you need to download a version of MySQL for Windows. If you’ve never installed this before, the easiest way is to download a package with executable setup file.

For demonstration purpose, it would be Windows Essential (x86).

Save to your desktop and run it once download is finished. Let’s go through the entire installation process step by step.

First, pick Typical installation option.

Install MySQL with Typical Option

This will install the MySQL server and client programs but not the C include files. You don’t need them unless you are developing an application that uses MySQL as the database backend.

Once the files are installed, you will be prompted to Configure the MySQL Server now. Let the checkbox checked before proceeding to the next step.

Configure MySQL Upon Installation on Windows

The next screen allows you to choose between Detailed Configuration or Standard Configuration. Pick the former, just for the sake of curiosity about what options are available to us. Don’t worry, if you don’t know what an option is, you can always leave it as is.

Detailed MySQL Configuration

When asked to choose the server type, the choice in this example is obvious. This setup is for experimenting with various WordPress themes and plugins, so low memory consumption is preferable. Choose Developer Machine. The other option will allow more concurrent connections running at the same time, which wastes more memory.

It doesn’t matter which one do you choose in the next step, but in this case, the choice is Multifunctional Database.

Multifunctional Database Option in MySQL

Following the option above, you will see a screen that prompts you for InnoDB Tablespace Settings. Choose the directory where you want the file to be placed.

MySQLl Tablespace Settings

The next step shows a screen where you can customize the number of concurrent connections allowed by MySQL. Although it is safe to choose Manual Setting and set it to 15 or even lower, I leave this to 20.

MySQL Decision Support

MySQL is capable of accepting connections through named pipes or TCP/IP networking. The latter is a more common setup, and more flexible too as you may migrate the MySQL server to another machine and still connect over the network, so leave all the settings as is. Enable TCP/IP Networking and Enable Strict Mode and leave Port Number: 3306 as the standard port.

Because you don’t need to make this MySQL database server to serve data outside of your own desktop computer, it is not necessary to add exception to the Windows Firewall for this port. While running the batch file later, if Windows asks you if you want to unblock this, feel free to choose Keep Blocking, unless you want to allow remote connections.

MySQL TCP/IP and Strict Mode

Next, you may set the character set for this database server. For English and other West European language, the Standard Character Set option is good to go.

MySQL Charset

You may want to Install As Windows Service. The Launch the MySQL Server automatically allows you to run MySQL as you start Windows.

This is certainly an option, although you could also run it along with the batch file above so you have the capability to start and stop it on demand from one place. Starting and stopping Windows service is not hard, but it needs more clicks separately.

If you choose to run it via the batch file above, uncheck the Install as Windows Service option.

Include Bin Directory in Windows PATH is a good idea so you can run mysql from anywhere in the command line.

MySQL as Service and Add to PATH

It is recommended that you enter the root password so access to the data is protected. You will need this to manage MySQL data. If you don’t need other people from remote machines to access this database server, leave the Enable root access from remote machines option unchecked.

MySQL Security Settings

That’s it. Now you have installed EMP on your Windows system.

Check to Make Sure WEMP Runs Properly

Now is the time to run Start nginx or the start-nginx.bat batch file. It first starts, php-cgi, binds to the loopback interface (localhost, IP 127.0.0.1). Next it runs nginx, followed by mysqld. Again, this is the same script that you run if you pick Start nginx from the Start Menu.

You can check if all the servers run properly by using Windows Task Manager (right click on the taskbar and pick Task Manager). Look for nginx.exe, mysqld-nt.exe and php-cgi.exe on the list. Sort by Image Name first to make it easy to locate program names.

Note: There will be two instances of nginx.exe, one master process and the other one is the worker process. Don’t worry about it, it is just how it was designed to be.

If you see them all, for redundancy, check if all the servers are accepting connections in the right TCP/IP ports.

Run the following command in a command prompt windows:

netstat -ban -p tcp

Basically, it tells netstat to:

  • -b: displays the executable involved in creating each connection or listening port.
  • -a: displays all connections and listening ports.
  • -n: displays address and port numbers in numerical form.
  • -p tcp: shows connections for TCP protocol only.

Among the result you should see the following:

  • Port 80 – System. For one reason or another it doesn’t shows as nginx.exe, but you can confirm it as such.
  • Port 3306 is occupied by mysqld-nt.exe, which is exactly the MySQL server you were starting just now.
  • Port 10000 – php-cgi.exe. Instead of 0.0.0.0 (all IP address in the system, this is specific only to loopback address (127.0.0.1). The PHP is now running in FastCGI mode, ready to accept connection.

For a full test you need something that access the web server, calling PHP script and connect to MySQL database.

Because WordPress does exactly this, let’s proceed by installing it on your WEMP setup.

Installing WordPress on WEMP System

WordPress installation should be easy by now with everything already in place. First of all, you need to prepare a database for WordPress.

You may choose to install PhpMyAdmin for MySQL database management but for simplicity let’s just dive into MySQL’s command line interface.

  1. Open a Command Prompt.
  2. If you enable MySQL in the PATH, you should be able to type in mysql -u root -p directly and get a password prompt. Enter the password you’ve set earlier when you install MySQL.
  3. At the MySQL command line interface, create the database and grant access to a specific user. It is recommended that you always create a user who has access only to one working database for security reason.

create database wp;
grant all on wp.* to 'wpuser'@'localhost' identified by 'yourpass';

The first command create the database wp. The second command grant all privileges to the user wpuser connected via localhost with the password yourpass. Of course, change your password — or any other variables — as necessary.

Use the exit command to get out of the MySQL command line interface, in case you don’t know how to do it.

You’re set!

Now download and unpack the newest version of WordPress. Put the files in C:\nginx\html. Rename the directory if you so choose. Put all the files inside the wordpress directory in root if you want the blog to be installed on the root directory.

Now open a browser window and access the files. If you put the wordpress directory in the document root and rename it to blog, type the following into the browser’s address bar:

http://localhost/blog/

A screen like the following appears:

Create WordPress Configuration wp-config.php

See, you don’t even have to copy the wp-config-sample.php to wp-config.php and edit the content to reflect your database configuration. WordPress will prompt you for the information with this wizard.

The next screen should be obvious. Please read if you are not familiar with WordPress installation. When finished, proceed to the next step, which is a screen where you could enter your database information.

WordPress Database Configuration

WordPress will test the database connection and if all is going fine, you will be prompted once again to run install.

The famous installation process involves entering your blog title and email address. That’s it!

Upon successful installation, you will see a success screen with your user name and password.

Important: Because most likely you don’t have a mail service in your desktop, you won’t get new blog creation message along with the admin’s username and password. Make sure that you jot down the details before you close the window or hit the Login button.

Try to login with the provided user name and password, and immediately change the password to something memorable. It doesn’t have to be secure because only you are able to access it.

If you’ve successfully reached this far, and you see the WordPress Dashboard after logging in, you can be sure everything is working well. Congratulations.

Now go play around with your newly installed WEMP and WordPress!

Return to How to Make a Server — Building High Performance Server.

Return to Blog Tips for a Better Blog — Blog Building University.


Blog Building University features tips, techniques and strategies on starting and growing your moneymaking / business blog. Subscribe to get fresh content delivered to you daily!

Blog Building University Full Content Feed

Comments

6 Responses to “Install WordPress on WEMP (Windows, nginx, MySQL and PHP)”

Blogging is Web Publishing 2.0.
BlogBuildingU.com solves your web publishing puzzles, one piece at a time.