This guide provides complete step by step instructions for how to take a new VPS or dedicated server  running Debian Linux and install the following software:

  • Virtualmin
  • Nginx
  • APC
  • Wordpress
  • W3 Total Cache

As a result of following this tutorial, the reader will have a Wordpress installation running on the increasingly popular Nginx web server, along with the W3 Total Cache plugin and APC to help make pages load very fast.

It's important that the reader have the following skills:

  • Wordpress installation and configuration
  • Linux command line over SSH
  • VPS configuration

Step 1: Install Debian 6 on your VPS

Begin this tutorial by installing a fresh copy of Debian 6 on your VPS. The method of doing this varies depending on what VPS control panel your VPS host uses. It's usually pretty easy to do no matter what panel is used. 

If you need instructions on installing Debian 6 on your VPS and your host uses the popular SolusVM control panel, there are instructions on how to install Debian 6 using SolusVM here.

This tutorial is designed to work regardless of whether you have installed Debian 6 in the 32-bit or the 64-bit version, so install whichever one you want.

Step 2: Install Virtualmin

A screenshot showing the commands used to download and start the Virtualmin install script along with some script output.
This image shows the final output of the Virtualmin install script. You'll know it has finished if you see a command prompt. If the install is not successful, error messages will be shown here.

Once you have a fresh install of Debian 6, you can then install Virtualmin, an open source program that allows you to manage your server through a web interface. It's a lot like cPanel, Plesk, or Directadmin, in the sense that it allows you to configure the hosting of web sites through a web interface. Along with its companion program, Webmin, it also can do a lot more things. Virtualmin is installed in this tutorial to allow for a web interface for automatically creating virtual hosts with Nginx. It will also allow you to administer other things like DNS, email, and other services.

Here are the steps to install Virtualmin:

  1. Log in to your server by SSH as root
  2. Download the Virtualmin install script by running
     wget http://software.virtualmin.com/gpl/scripts/install.sh
  3. Now change the permissions of the install script to make it executable
    chmod 744 install.sh
  4. Run the installer by by running ./install.sh
  5. You'll be asked if you want to continue. Type y, then press Enter.

That's all you need to do to install Virtualmin (you'll still have to configure it later). The install script will do the rest. On a VPS with 2 GB of RAM the Virtualmin install usually takes less than 5 minutes. On a VPS with 128 MB of RAM, this could easily take up to an hour or more.

You'll know that the Virtualmin install script has finished when a Linux command prompt is displayed.

Step 3: Run the Virtualmin Post-Installation Wizard

When initially logging in to Virtualmin, you'll probably see an error message which can be safely ignored.
You need to log in to Virtualmin as root to complete the Post-Installation Wizard.
All of the defaults suggested by Virtualmin are suitable for purposes of this tutorial. To avoid having to accept each default individually, you can just click "Cancel" and all default settings will be used.

After the Virtualmin install script has completed, it's necessary to run the Virtualmin Post-Installation Wizard. The Post-Installation Wizard is run in a web browser.

  1. In a web browser, visit https://xxx.xxx.xxx.xxx:10000, replacing xxx.xxx.xxx.xxx with the real IP of your server.
  2. You'll most likely see an error message about your site's security certificate not being trusted. This is normal and you can proceed past this.
  3. Log in to Virtualmin using your root username and password.
  4. At the "Introduction" page of the Post-Installation Wizard, click the "Cancel" button to use all of the default settings for Virtualmin.

Step 4: Check and make adjustments to Virtualmin's configuration

After the Post-Installation wizard, you need to let Virtualmin recheck its configuration.

You should now see a message stating that:

"Virtualmin's configuration has not been checked since it was last updated. Click the button below to verify it now."

  1. Click the button that says "Re-check and refresh configuration"

Virtualmin will then re-check your configuration.

Error: "The ClamAV program clamscan does not appear to be working properly"

In some circumstances, you may notice the following error:

The ClamAV program clamscan does not appear to be working properly : 

LibClamAV Error: cli_loaddb(): No supported database files found in /var/lib/clamav/ ERROR: Can't open file or directory

If you see the above error message, follow the solution here and then continue on with the rest of this tutorial.

 

Set a root MySQL password

Virtualmin will tell you that you need to set a root MySQL password. To do so, click the linked text in the message which says "MySQL Database".
The MySQL password can be changed in the form on the "Change Administration Password" page.

Among the messages output when Virtualmin checks your configuration, there may be a message stating that:

MySQL is installed and running, but does not have any root password set! This should be changed immediately in the MySQL Database module.

When you see the previous message, it means you need to set the MySQL root password. To set the MySQL root password, perform the following steps.

  1. Click the link in the message that has the text "MySQL Database" to be taken to the MySQL Database Module page.
  2. On the page titled "Change Administration Password", enter your desired MySQL root password into the form, twice, then click "Change Now".

You have finished setting a MySQL root password.

Allow Virtualmin to re-check the system configuration

Allow Virtualmin to re-check the configuration by first clicking on "System Settings", and then clicking "Re-Check Configuration".

When Virtualmin checked the configuration earlier, there were some other messages on the screen. To see them again, the configuration of Virtualmin should be checked once again:

  1. Expand the "System Settings" section in the sidebar menu.
  2. Click on "Re-Check Configuration"

Virtualmin will now re-check your system. There's probably nothing critical left to find, but if you're using an  OpenVZ VPS, then Virtualmin will probably alert you to the following networking related issue:

Default IP address is set to 127.0.0.2, but the detected external address is actually xxx.xxx.xxx.xxx. This is typically the result of being behind a NAT firewall, and should be corrected on the module configuration page.

If you see the above notification, you can resolve it by following the procedure on this page.

Ignore mount point errors and notifications about quotas on OpenVZ VPS

Also, if you are using an OpenVZ VPS, you may see a message stating that:

"The module could not find the mount point for your home directories filesystem /home. Quotas editing has been disabled."

Or you might instead see an error message like the following:

Quotas are not enabled on the filesystem / which contains home directories under /home and email files under /home. Quota editing has been disabled.

This is normal behavior on OpenVZ VPS and is not an indication of anything wrong. It's just that due to the nature of an OpenVZ vps, quotas aren't available.

You should also notice that Virtualmin reports at the bottom of the page that:

 .. your system is ready for use by Virtualmin.

You have finished installing and configuring Virtualmin. 

Step 5: Install Nginx and the Nginx plugin for Virtuatualmin

A screenshot showing the output resulting from installing Nginx and the Nginx module for Virtualmin.

You will now need to log in as root to a command line on your server to complete the next steps in which you will remove the Apache web server, install the Nginx web server, and install the Nginx module for Virtualmin.

  1. Turn off Apache by running /etc/init.d/apache2 stop
  2. Stop Apache from starting again by running update-rc.d -f apache2 remove
  3. Install the Nginx web server and APC by running apt-get install nginx php-apc
  4. Start Nginx by running /etc/init.d/nginx start
  5. Install the Nginx plugin for Virtuatualmin by running apt-get install webmin-virtualmin-nginx

There is another package named webmin-virtualmin-nginx-ssl which installs virtualmin support for SSL websites under Nginx. However, installation of the webmin-virtualmin-nginx-ssl package is left out of this guide as it is beyond the scope of this tutorial.

The Nginx web server is now be installed and running. Also the Nginx module for Virtualmin is installed.

Step 6: Configure the Nginx module for Virtualmin

Click on "System Settings" to reveal the sub-menu. Then click on "Features and Plugins".
On the "Features and Plugins" page, the order in which features are enabled or disabled is important; you must be careful not to disable a feature that has other features that depend on it.

This part can be tricky. In Virtualmin, you will disable some unneeded features and enable some needed ones. What makes this difficult is that some features depend on other features, so you're going to have to disable or enable features in a certain order, or else you'll get error messages and have to start again. 

  1. In a web browser, log in to Virtualmin as root (Remember that the web address to log in at is xxx.xxx.xxx.xxx, where xxx.xxx.xxx.xxx should be replaced by your server's IP address).
  2. In the sidebar menu, expand the "System Settings" menu item. Then click on "Features and Plugins"
  3. From the list of Virtualmin Features and Plugins, un-check the check-boxes next to the names of all of  following plugins if they are listed (Note that some of the plugins listed below may not be listed on your system. Just make sure to un-check any of the ones below that are listed) :
    • Webalizer reporting
    • SSL website
    • AWstats reporting
    • DAV Login
    • mailman
    • Protected web directories
  4. Click the "Save" button.
  5. In the sidebar menu, expand the "System Settings" menu item. Then click on "Features and Plugins"
  6. From the list of Virtualmin Features and Plugins, un-check the check-box next to the name of the following plugin:
    • Apache Website
  7. Click the "Save" button.
  8. In the sidebar menu, expand the "System Settings" menu item. Then click on "Features and Plugins"
  9. From the list of Virtualmin Features and Plugins, check the check-box next to the name of the following plugin:
    • Nginx website
  10. Click the "Save" button.

In the previous steps, you disabled some features related to serving web sites with Apache on Virtualmin, and you've enabled the module required to use Nginx with Virtualmin.

Verify that the Nginx Virtualmin module is set up properly

Clicking "Refresh system information" gives you up to date information about your system.
In the "Status" section of the "System Information" page, you should see that the Nginx Webserver is running.

Next, check if the Nginx Virtualmin module is setup properly.

  1. Click the "Refresh system information" link at the top of the page
  2. Expand the "Status" section link towards the bottom of the page and you should see that "Nginx Webserver" is listed as a service being managed by Virtualmin.

If you see "Nginx Webserver" listed in the "Status" section of Virtualmin's "System Information" page, that means you've completed installing Nginx and you have successfully configured the Nginx plugin for Virtualmin. Virtualmin is now ready to host domains with Nginx.

Step 7: Create a virtual server

To create a virtual server, or to "host a domain", in Virtualmin, click the "Create Virtual Server" link located near the top of the sidebar menu of Virtualmin.
  1. From the main Virtualmin "System Information" page (you can get there from the "System Information" link in the sidebar menu), click the "Create Virtual Server" link.

Enter the information for your virtual server

Entering your domain name, a description of your site, and a password is all that's required when you create a virtual server.
After you click the "Create Server" button, Virtualmin will display information in your browser about what steps it has done in creating your server. Once you see the text, "Saving server details .. .. done", your server install will be complete.
Once installed, your server's domain name will appear in the drop down list at the top of the left column menu.

You will see a page where you can enter information about the virtual server you will create.

Make sure that whatever domain you intend to use is correctly configured so that it's nameservers (DNS) point to the server which you are using while following these instructions.

  1. Enter the domain name or subdomain name you want to host in the "Domain name" field. 
  2. Enter a description in the "Description" field.
  3. In the "Administration password" field, enter the password you will use for this server.
  4. Click the "Create Server" button.

An important note about usernames, passwords, and databases

When you click the "Create Server" button, Virtualmin will create a Linux user and a Linux group for your server. The names for the user and group are chosen automatically based on the domain name that you entered in the "Domain name" field.

An example

For example, if the domain "superwordpresswebsite.com" was entered in the "Domain name" field, then a Linux user and a Linux group would be created by Virtualmin, both having the name "superwordpresswebsite".

Database Name

A Mysql Database will also be created by Virtualmin. The name of the database will be the same as the Linux username and the Linux group created.

Database Username and 16 character limit

Virtualmin will create a database user which will have access to the aforementioned database. Generally, the database user name will be identical to the Linux username created by Virtualmin. The only exception to this rule is when the username is longer than 16 characters (MySQL has a 16 character limit on usernames). In such a case, where the automatically generated username would be longer than 16 characters, only the first 16 characters of the name are used for the MySQL database username.

Passwords

The Linux user password and the MySQL database password are the same as the password that was entered into the"Administration password" field of the form. 

 Before proceeding to follow the rest of this tutorial, make sure you:

 

  • Understand and know what the Linux username and password is for your virtual server
  • Know that the name of the MySQL database created for your virtual server is the same as the Linux username created for your server.
  • Know the MySQL username for your virtual server is the same as the Linux username for your server, unless the username is more than 16 characters long, in which case your virtual servers' MySQL server will be truncated at 16.
  • Your virtual server's MySQL password is the same as the password for the Linux user for your server. 

Step 8: Install Wordpress

Log in to the server using the virtual server's Linux account. Logging in as root during this step will result in file permissions problems later.
Move into the public_html directory where Wordpress will be installed.

For the next steps, you need to be logged in to a terminal as the Linux user corresponding with your virtual server. 

Do not complete these next steps as root!

  1. Log in through SSH as the non-root user that corresponds to your virtual server.
  2. Navigate to your virtual server's public_html directory by running the command cd ~/public_html

Download and extract Wordpress

Wordpress is downloaded with 'wget'.
Wordpress is extracted from the archive into a directory called 'wordpress'.
The Wordpress install files are then copied from the 'wordpress' directory to the current directory (public_html).

Now that you're in the public_html directory, you can download a fresh copy of Wordpress, extract the archive, and copy it to your public_html directory.

  1. Download Wordpress by running wget wordpress.org/latest.tar.gz
  2. Extract the package with tar -xzvf latest.tar.gz
  3. Copy all of the extracted files into the public_html directory where they are web accessible with cp -Rf wordpress/* ./

Visit your web site in a browser to start the Wordpress install

The Wordpress install script will first tell you that there doesn't seem to be a wp-config.php file. It will offer to create a configuration file for you.

You should already be familiar with the Wordpress web-based install wizard.

 

  1. Access your web site in a browser
  2. You should see a page stating that "There doesn't seem to be a wp-config.php file. I need this before we can get started." 
  3. Click the button that says "Create a Configuration File"
The Wordpress configuration script will tell you what information you need to create a configuration file.

You'll see a page which tells you what information you will need to proceed with the install. You will need your Database name, Database username, Database password, Database host and Table prefix.

Recall that earlier the proper database name, database username, and database password for your Wordpress site was discussed.

  1. When you have the correct information pertaining to the database configuration for your Wordpress site, click the button that says "Let's go!"

The image here shows an instance where the MySQL username is not the same as the database name due to MySQL's default username length limit of 16 characters

Before you continue, it is important that you know the correct MySQL username, password, and database name for your virtual server.

  • The MySQL database name for your virtual server is the same as your virtual server username.
  • Your MySQL username is the same as your virtual server username, except in cases where your virtual server username exceeds 16 characters, in which case your MySQL username is the first 16 characters of your virtual server username.
  • Your MySQL password is the same as the password you chose when you created your virtual server
  1. Now enter your database name, MySQL username, and MySQL password into the form.
  2. Leave the default values for "Database Host" and "Table Prefix".
  3. Click the "Submit" button.

Remember that MySQL passwords cannot exceed 16 characters.

If you've made it to this page, it means that Wordpress can successfully communicate with your database. Click "Run the install".
  1. Click the "Run the install" button.
Almost done.
  1. Enter your Site Title, Username, Password (Twice), Your E-Mail, and check or un-check the checkbox next to the text which says "Allow search engines to index this site.".
  2. Click the button that says "Install Wordpress".
Click "Log In" to be taken to the log in page.
  1. Click the "Log In" button.
Enter your username and password, then click "Log In"
  1. Enter your Wordpress Username and Password into the form
  2. Click the "Log In" button.

Step 9: Install the Nginx Helper plugin

The "Nginx helper" plugin is simply listed as "Nginx" in the search results.
Activate the "Nginx helper" plugin from the "Installed Plugins" page.
Uncheck the checkbox next to the "Enable Cache Purge" option.

Once you're logged in, you'll need to install "nginx helper". Nginx helper is a plugin that makes it possible to have nice permalinks with Nginx.

  1. From the Wordpress Dashboard, go to "Plugins->Add New"
  2. In the search form, enter nginx helper
  3. Click the "Search Plugins" button.
  4. Click on the "Install Now" link under the first search result titled "Nginx" in the plugin search results.
  5. When asked "Are you sure you want to install this plugin?", click "OK"
  6. Click on the link that says "Activate Plugin"
  7. Click the "Settings" link underneath the name of the Nginx Helper plugin.
  8. Uncheck the checkbox next to "Enable Cache Purge"
  9. Click the "Save" button.

Step 10: Set up permalinks

Setting up permalinks in Wordpress.

Now you can set up your permalinks.

  1. From the Wordpress Dashboard, go to "Settings->Permalinks"
  2. Check the radio button next to "Post name"
  3. Click the "Save Changes" button.

Permalinks won't actually work at this point. There is still more configuration needed to get Nginx working with permalinks.

Step 11: Install the W3 Total Cache plugin

Among other things, the W3 total cache plugin makes Wordpress sites faster by caching the normal PHP generated pages and posts as static HTML files. Pages cached in this way can be served directly by the web server, eliminating the time needed for processing with PHP.

Among the list of plugins returned by the search function, W3 Total Cache should be listed first.
Once the "W3 Total Cache" plugin has been installed, click "Activate Plugin"
A new menu item, titled "Performance", will appear in the Wordpress backend.

Install W3 Total Cache by following normal Wordpress plugin procedures.

  1. Go to "Plugins->Add New"
  2. Using the Search function, search for "w3 total cache"
  3. "W3 Total Cache" should be first in the list of plugins returned.
  4. Underneath the name of the plugin, "W3 Total Cache", click the text which says "Install Now"
  5. Click "Ok" when asked "Are you sure you want to install this plugin?"
  6. Once the "W3 Total Cache" plugin is successfully installed, click the link which says "Activate Plugin"

Configure W3 Total Cache

Click the "Performance" link to be taken to the settings page for the W3 Total Cache plugin.
The W3 Total Cache main configuration page. Any errors you see can be safely ignored at this point.

After the "W3 Total Cache" plugin is activated, there will be a new menu section called "Performance" located in the Wordpress Dashboard at the bottom of the left sidebar menu. This "Performance" menu section is where all settings pertaining to "W3 Total Cache" can be found.

  1. Click on the "Performance" link on the sidebar to be taken to a page where you can configure W3 Total Cache.
Enable the Page Cache and select "Disk Enhanced" as the Page Cache Method.

The performance settings of W3 Total Cache aren't all enabled by default. They need to be configured here.

  1. Scroll down to the section titled "Page Cache". You should see that the check-box next to "Enable" is checked. Also, you should notice that "Disk: Enhanced" is selected from a drop-down menu as the "Page Cache Method". If these settings are not set, set them now.
Enable the "Database Cache" with the "Opcode: Alternative PHP Cache (APC)" chosen as the caching method to use.

Now, scroll down to the section labeled "Database Cache"

  1. Enable the "Database Cache" by checking the checkbox next to "Enable"
  2. For the "Database Cache Method", choose "Opcode: Alternative PHP Cache (APC)" from the drop down list.
Enable the Object Cache and selecting the Object Cache Method.
  1. Scroll down to the "Object Cache" section
  2. Enable "Object Cache" by checking the corresponding checkbox.
  3. Select "Opcode: Alternative PHP Cache (APC)" from the dropdown list as the "Object Cache Method" to use.
The "Nginx server configuration file path" is where the W3 Total Cache plugin will automatically create an Nginx configuration file that works with the W3 Total Cache plugin.
  1. Scroll down to the section titled "Miscellaneous"
  2. In the form next to "Nginx server configuration file path", enter the full path to your public_html directory followed by nginx.conf
  3. Click any one of the buttons on the page that says "Save all settings"

In this step, you're letting the W3 Total Cache plugin know where to create an Nginx configuration file for your site.

Click "Deploy".
  1. On the resulting page, click the "Deploy" button.

At this point, you can ignore a message you might see stating that:

It appears Page Cache URL rewriting is not working. If using apache, verify that the server configuration allows .htaccess or if using nginx verify all configuration files are included in the configuration.

Step 12: Edit Nginx Configuration

The Nginx Webserver module for Virtualmin allows you to configure many aspects of Nginx's operation
From the Nginx Webserver module, click "Edit Configuration Files"
Select the correct file to edit from the drop-down list. The correct file will have the name of your server in it.
  1. Log in to Virtualmin as root
  2. Click the "System Information" link (located at the bottom of the left sidebar menu) if you are not already at the "System Information" page.
  3. In the "Status" section, look for "Nginx Webserver". If "Nginx Webserver" does not appear in the "Status" section, click on the "Refresh system information" link at the top of the page.
  4. Click on the "Nginx Webserver" link located in the "Status" section to be taken to the Nginx Webserver module page.
  5. Click "Edit Configuration Files"
  6. In the drop down list next to where it says "Editing configuration file", select the configuration file for your site (The file you need to choose has your site name in the file name. In my case it's "/etc/nginx/sites-available/wordpressandnginx.tk")
The four lines of the location directive.
  1. Near the bottom of the configuration file for your server, look for the following lines which will be referred to as "the location directive":
	location ~ \.php$ {
try_files $uri =404;
fastcgi_pass localhost:9000;
}
The nginx.conf file generated by W3 Total Cache is included before the location directive.
  1. Immediately before the location directive, and on a new line, add the following line:
	include /home/wordpressandnginx/public_html/nginx.conf; 
Three more lines are placed after the location directive.
  1. Immediately after the location directive lines, on a new blank line, add the following lines:
	if (!-e $request_filename) {
rewrite ^.*$ /index.php last;
}
Click "Save" to save the configuration
  1. Click the "Save" button to save the edited configuration.
Changes made to Nginx configuration files are not made active until the "Apply Nginx Configuration" button is clicked.
  1. Click the "Apply Nginx Configuration" button to apply the configuration changes you made.

Installation & Configuration Finished

This concludes the instructions of this tutorial.

You should now have a fully configured setup of Wordpress running on the Nginx webserver, with caching enabled by the W3 Total Cache plugin and APC. Virtualmin is also installed to provide a GUI based administration interface for your server.

Related Pages