Install WordPress onto Nginx
This guide assumes that you are using the Ionized VPS template provided to IonVz customers which comes with Nginx, PHP-FPM, MySQL, phpMyAdmin pre-configured. The guide should still be useful to pre-existing Nginx installations using version 0.8.x or higher.
Creating the DatabaseUsing phpMyAdmin or mysql via shell/SSH create a database.Example:
# mysql -u DatabaseUser -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 52
Server version: 5.1.45-1~bpo50+1 (Debian)
 
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
 
mysql> create database MyNewBlog;
Query OK, 1 row affected (0.00 sec)
 
mysql> exit
Bye
#
If you wish to assign a new user to your new database (as its ill-advised to use your root mysql login for wordpress) refer to the MySQL Reference on GRANT.Example:
1
2
CREATE USER 'wpuser'@'localhost' IDENTIFIED BY 'mypass';
GRANT ALL ON MyNewBlog.* TO 'wpuser'@'localhost';
Uploading FilesThe fastest way to get WordPress uploaded to your server is to use shell and the wget command. On WordPress.org find the download link for tar.gz and copy it. Then log into your VPS via SSH:
root@ionvz:/# cd /opt/html/example.com
root@ionvz:/opt/html/example.com# wget http://wordpress.org/latest.tar.gz
--2010-12-12 20:45:50--  http://wordpress.org/latest.tar.gz
Resolving wordpress.org... 72.233.56.138, 72.233.56.139
Connecting to wordpress.org|72.233.56.138|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [application/x-gzip]
Saving to: `latest.tar.gz'
 
    [         <=>                         ] 2,689,163   1.29M/s   in 2.0s    
 
2010-12-12 20:45:52 (1.29 MB/s) - `latest.tar.gz' saved [2689163]
 
root@ionvz:/opt/html/example.com# tar zxf ./latest.tar.gz
root@ionvz:/opt/html/example.com# ls
latest.tar.gz  wordpress
root@ionvz:/opt/html/example.com# mv ./wordpress/* ./
root@ionvz:/opt/html/example.com# rm -Rf ./latest.tar.gz ./wordpress
root@ionvz:/opt/html/example.com# ls
index.php	 wp-blog-header.php    wp-includes	  wp-register.php
license.txt	 wp-comments-post.php  wp-links-opml.php  wp-rss.php
readme.html	 wp-commentsrss2.php   wp-load.php	  wp-rss2.php
wp-activate.php  wp-config-sample.php  wp-login.php	  wp-settings.php
wp-admin	 wp-content	       wp-mail.php	  wp-signup.php
wp-app.php	 wp-cron.php	       wp-pass.php	  wp-trackback.php
wp-atom.php	 wp-feed.php	       wp-rdf.php	  xmlrpc.php
root@ionvz:/opt/html/example.com#
Once the files are uploaded, copy the wp-sample-config.php to wp-config.php and edit it's content to the correct database settings (normally you just need to change the username, password and database name). Once saved upload the new wp-config.php to the site. Visit your new website, you should be prompted with an installation dialog (if this is a new domain on nginx, you may need to restart nginx for the configuration to take effect).Getting Permalinks WorkingYou may have already noticed, .htaccess files do not work with Nginx (they are after all an httpd feature). If you are using Nginx 0.7.26+ the best way to get permalinks working is to simply add a try_files directive to your nginx configuration.
1
2
3
4
5
6
7
8
9
10
11
12
13
server {
	server_name example.com www.example.com;
	root /opt/html/example.com;
 
	location / {
		try_files $uri $uri/ /index.php;
	}
 
	location \.php {
		fastcgi_pass   127.0.0.1:9000;
		include fastcgi-params;
	}
}
Once configured you'll want to restart Nginx:
#/etc/init.d/nginx restart
Getting the most out of WP-Super-CacheIf there is one thing that Nginx does extremely well, it is serving static content. However with the above permalink configuration wp-super-cache will only work in half-on mode (meaning php serves up the cache). To get Nginx working optimally, we'll need a new set of configuration and the help of gzip precompression module. Customers with the Nginx template should already have this module, for those who do not will need compile Nginx with the --with-http_gzip_static_module option.WP-Super-Cache will complain about the possibility that mod_rewrite is not installed, this is normal as it is not able to detect Nginx's capabilities. It helps to create a .htaccess and let it write to it if you wish to get rid of the secondary warning message.Here is a new server block with wp-super-cache in mind:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
server {
	server_name example.com www.example.com;
	root /opt/html/example.com;
 
	location / {
		gzip_static on;
		gzip_disable        "MSIE [1-6]\.";
 
		default_type text/html;
 
		if (-f $request_filename) { break; }
 
		set $supercache_file '';
		set $supercache_uri $request_uri;
 
		if ($request_method = POST) { set $supercache_uri ''; }
		if ($query_string) { set $supercache_uri ''; }
		if ($http_cookie ~* "comment_author_|wordpress|wp-postpass_" ) { 
			set $supercache_uri ''; 
		}
		if ($supercache_uri ~ ^(.+)$) { 
			set $supercache_file /wp-content/cache/supercache/$http_host/$1index.html; 
		}
		if (-f $document_root$supercache_file) { rewrite ^ $supercache_file break; }
 
		if (!-e $request_filename) { rewrite . /index.php last; }
	}
 
	location \.php {
		fastcgi_pass   127.0.0.1:9000;
		include fastcgi-params;
	}
}
When the "Compress pages" option of WP-Super-Cache is enabled, it will create both a static html file and a .html.gz compressed file to match. The Nginx gzip precompression module will serve the gzipped content to browser that support gzip encoding (the configuration above disables it for Internet Explorer 6 and earlier).The above rules first checks to see if the file exists, then looks for an existing cached file in the cache folder. If it exists and the request was not a submission, comment, post, or a user logged in, it will serve the cached file directly bypassing PHP. If not it will simply goto the root index.php like it normally would. The results is a substantial performance boost of your website and lower memory usage as PHP is not being accessed for every request. I prefer to use the preload option of the plugin, however that may not be desirable if you update your content often.Error PagesIf for some reason you get an Nginx error page for pages not found, you may have fastcgi_intercept_errors turned on, you can either turn it off at the location where it is set, or insert the directive into your server { } block.
fastcgi_intercept_errors off;
Turning it off will allow you to see the normal wordpress error page.


Leave a Reply

Name
(* required)
Email Address
( * required - will not be published)
Web Site
Comment
(* required)