Build high performance wordpress site using Nginx + Varnish

Highlight: Ubuntu + Nginx + PHP-FPM + Varnish for WordPress site

The current site is hosted on CentOS 6 using Apache in home lab server, so you may experience slowness due to network limitation. When I was using Apache Bench tool to test the site performance, it can only server 10 requests per second. I’ve tried using Memcache and APC, the performance gain is minimum. After use Varnish in front of Apache server, the site can server over 10,000 requests per second. Here, I am going to setup another test server using Nginx + Varnish to compare with current setup. With Nginx only, it can serve 60 requests per second. That’s 6 times faster than Apache without any cache program. Now, let’s see how much performance Nginx can gain by using Varnish compare to Apache.

Varnish in realtime

Continue reading

Use APC(Alternative PHP Cache) for WordPress on VPS

W3 Total Cache support many page cache methods. For VPS or Dedicated server, it’s better to use Opcode than disk.  The Alternative PHP Cache will be built into PHP6, so it’s a good to try it now.

“APC is a free, open, and robust framework for caching and optimizing PHP intermediate code.”

On CentOS, you can install it though:

# pecl install apc

Or manually install it

# wget
# tar -xvzf APC-*.tgz
# cd APC-*
# phpize
# ./configure
# make
# make install

I’ve see the following error when to install APC through pecl. To solve the problem, just install pcre-devel package first

# yum install pcre-devel
//Error message
/root/tmp/pear/APC/apc.c:369: error: expected specifier-qualifier-list before 'pcre' /root/tmp/pear/APC/apc.c: In function 'apc_regex_compile_array': /root/tmp/pear/APC/apc.c:430: error: 'apc_regex' has no member named 'preg' /root/tmp/pear/APC/apc.c:430: error: 'apc_regex' has no member named 'preg' /root/tmp/pear/APC/apc.c:431: error: 'apc_regex' has no member named 'nreg' /root/tmp/pear/APC/apc.c:431: error: 'apc_regex' has no member named 'nreg' /root/tmp/pear/APC/apc.c: In function 'apc_regex_match_array':

Display Chinese Characters in WordPress

By default, Chinese characters do not work in WordPress if you didn’t originally setup your WordPress to handle it. To display or compose Chinese in your blog, you can change the WordPress database Collations to utf8_unicode_ci for all tables. If you have phpMyAdmin, you can manually change them one by one. However, it will take long time to fix all of them. Here is an easy way to change all Collations using script.

1. Create a file as: alter_mysql_tables.php

2. Copy and paste the following lines to the file and modify it using your own database connection

Download File: [download id="1"]
3. Save the file and upload to your ftp.
4. Run the script in browser:
5. That’s all!

WordPress Permalinks

By default, WordPress uses URL with question mark and its post ID.  After enable Pretty Permalinks, all the posts give 404 error. At first, I thought it’s .htaccess problem, however this file was updated automatically after applied the changes. After searching Wordpress documents, I found that it also requires FollowSymLinks option and AllowOverride FileInfo directives in Apache configuration file. I never knew this since shared hosting server has those options enabled by default. On VPS server, I have to configure by myself.

vi /etc/httpd/conf/httpd.conf

# Each directory to which Apache has access can be configured with respect
# to which services and features are allowed and/or disabled in that
# directory (and its subdirectories).
Continue reading

WordPress plugin upgrade on Linode VPS

After migrating WordPress from shared hosting to Linode VPS,  I noticed that it needs FTP login to install or upgrade plugins/themes from the Dashboard. This really bothers me since I am too lazy to do this manually.  I thought there should be a solution in Google, however after two days of research, I just couldn’t find one that I can use.  Suddenly, I read someone in Linode forum said he fixed the problem on Debian box by changing the ownership to www-data. So, I realized that I can do the same on my CentOS

cd /var/www/
chown -R apache.apache public_html

* This command will change the ownership of all files/folders recursively under current directory to apache.

WordPress error:

Connection Information

To perform the requested action, WordPress needs to access to your web server. Please enter your FTP credentials to proceed. If you do not remember your credentials, you should contact your web host.