make wordpress fly with virtual server hosting - wordcamp sydney 2014
DESCRIPTION
Presentation slides from Vladimir Lasky's talk "Make WordPress Fly With Virtual Server Hosting", presented on Sunday 28th September at WordCamp Sydney 2014.TRANSCRIPT
1
Make WordPress Fly with Virtual Server Hosting
Vladimir Lasky
http://wpexpert.com.au/
WordCamp Sydney 2014
2
Is This For Me?
Sick of waiting for WP admin pages and edit screens to load
in your browser?
Tired of wrangling with page caches, object caches and
minifying plugins?
Running a database-intensive WordPress site, e.g. e-
commerce site?
Prepared to roll up your sleeves to get a better experience?
Brave enough to forego the “walled garden” of a cPanel in
exchange for true freedom and flexibility?
Then YES!
Shared Web Hosting
3
4
How Shared Web Hosting Limits You
Throttling of Resources
– Network bandwidth
– Running Processes
– Disk I/O
Limited ability to tune & reconfigure services
No PHP Opcode caching
Might have MySQL query caching enabled, but
likely overcommitted
5
Why Caching Plugins Are Not The Answer - 1
Two main categories of caching plugins:
– Page caching (e.g. WP Super Cache, Hyper Cache)
– Object Caching
These have cache invalidation overhead/delays
– When the underlying data changes, caches must be
explicitly purged or one must wait for expiry.
– Purging, rebuilding caches causes performance hit –
especially if the cached data is stored on disk
– Stale caches cause non-current information to be
displayed
– Frequently cause issues with plugins/dynamic pages
6
Why Caching Plugins Are Not The Answer - 2
They provide no help in speeding up the backend
(WordPress Admin) and usually do nothing for
users who are logged in.
7
What About Cloudflare?
A very popular Reverse-Proxy/CDN service
Some useful features, but you are dependent on
them
Have a “free” plan, but no guarantee it will stay
free
CDN based on object pull, so can have cache
invalidation issues
Doesn’t speed up backend (WordPress Admin)
More comments on CDNs later
8
What About Minifying Plugins?
These aggregate your site’s CSS and JS files and
compress them by removing white space, new
lines comments and block delimiters.
Examples:
– Better WordPress Minify
– Autoptimize
Somewhat reduce the total requests required to
load your site and the amount of data transferred
Good in theory, but in practice often break things
and require much tweaking to work right
9
Why Host WordPress on a VPS?
You can use PHP Opcode Caches, MySQL
Query Caches and other performance enhancers
that don’t have these issues
You have the full ability to customise and tune
services for performance
10
What is a VPS?
A Virtual Private Server (VPS) is your very own virtual machine
(VM) running in a datacentre.
The physical server or Virtual Server Host, will be running
multiple VMs simultaneously – yours and other clients of your
hosting provider, but only yours is visible to you.
Cost depends on desired specs – e.g. RAM, disk space, CPUs,
monthly data traffic
Start from as little as $5/month, but can be hundreds for
something hefty
11
How Do You Administer a VPS?
A Linux VPS is generally accessed via SSH
A Windows VPS is generally accessed via RDP
Usually there is a facility to view and control the virtual
console, e.g. if the VM hangs and needs to be reset or
reimaged.
You can install and run anything you want (subject to
provider’s Acceptable Use Policy)
12
Common Virtual Private Server Types
OpenVZ
– Based on containerization
– Efficient, but does not allow users to change OS kernel
version or have dedicated swap space
– Usually offered at lower price
Xen
– Full ability to customise all aspects of VM configuration
– Allows dedicated swap space
– Some performance overhead
– Usually more expensive
13
Why Hosting Control Panels Are Evil
Take over your system – very hard to get rid of or
change
Commercial ones cost money, e.g. $150/yr for
cPanel
Free ones could be abandoned at any time. Risk
of security holes.
Are rather inflexible – you have to wait for
updates to support/take advantage of new
features in other packages
14
The Plan
Host WordPress on a Pure SSD VPS with CentOS 6.5
x64. Dual CPUs and 2GB RAM is nice.
Install a PHP Opcode Cache and allocate 120MB RAM
– Choose Zend Optimizer if using PHP 5.5 w/single WordPress
installation
– If Multiple Sites or Older PHP, then XCache
In MySQL config file, enable the Query Cache and
allocate 32MB RAM. Make the key buffer/buffer pool
Configure Apache to launch PHP-FPM in FastCGI mode
and communicate using Unix Sockets
Configure WordPress to access MySQL using Unix
Sockets
15
Our Performance-Enhanced Configuration
Common Shared Hosting Configuration
16
17
Differences from a Default Installation
PHP operates as a standalone service (PHP-
FPM) instead of as an Apache module (mod_php)
Apache communicates with PHP-FPM using Unix
Sockets instead of TCP sockets
A PHP Opcode Cache is installed
The MySQL Query cache is enabled
WordPress DB_HOST in wp-config.php is set to
‘localhost’
18
Benefits of Our Approach
Not radically different from a default install
Excellent “bang for buck”
No cache invalidation problems
No plugin incompatibilities
Everyone sees the most current state of your site
Logged in users and people working in the
backend will enjoy a speed increase
19
Why CentOS?
Free Linux distribution 100% compatible with
Redhat Enterprise Linux – popular Linux
distribution designed for servers
Offered by the vast majority of hosting providers
Security patches are released speedily
Experts are abundant
20
Why Unix Sockets?
Less overhead – avoids all network layers below
transport
Lessens risk of ephemeral port exhaustion if site
is bombarded with requests (it does happen)
More secure – they only accept connections from
localhost
21
Why Pure SSD VPS Hosting?
HDDs respond to random I/O like busy elevator in
office block – big slowdown when lots of random
requests
SSDs like elevator that teleports to any floor –
cope far better with high, random I/O loads
All server files and databases stored on Solid
State Drives
Greatly improves efficiency, performance of
Shared and Virtual Server Hosting
Beware of “SSD-cached” storage – not as good
22
Who Provides Pure SSD Virtual Server Hosting?
Hosted Abroad: – Linode
– DigitalOcean
Hosted in Australia: – Exigent
– Crucial
– ServerMule
– VPSBlocks
More companies are introducing Pure SSD solutions
Australian Pure SSD VPS hosts more expensive and offer
lower data limits, but “there’s no place like home”.
23
PHP Opcode Caches - I
The only way to truly make WordPress run faster
WordPress is a PHP program
When PHP code is first executed, it is compiled
into bytecode and stored in shared memory
Future requests will avoid parsing and disk I/O
overhead
120MB is rough yardstick
24
PHP Opcode Caches - II
Zend Opcache
– Bundled with PHP 5.5
XCache
– Not as fast as Zend Opcache
+ Recognises identical copies of PHP files
+ Saves lots of RAM if you have multiple WordPress sites
25
MySQL Query Cache
WordPress and plugins sends many identical
SQL queries to the server each time a page loads
MySQL can be configured to cache the results,
avoiding the need to parse and execute the query
The Query Cache is automatically invalidated
whenever the database is updated
Transparent to WordPress and plugins
32-64MB is a useful size
26
Avoiding CDN Hassles
If you use a CDN for your images, videos or other
assets, ensure that it is configured to operate in
“Origin Push” mode
This means that WordPress will upload content to
the CDN whenever it is added or updated
This avoids cache invalidation issues
W3 Total Cache plugin supports Origin Push CDN
integration for several CDNs, e.g. Amazon,
MaxCDN
27
Anything Else To Speed Things Up?
Enable the Apache module mod_deflate to
compress HTML, text, CSS and JavaScript
source files before they are sent to the client.
This speeds up site loading and reduces the
amount of data transferred.
This will work on your current shared host as well!
28
Virtual Server Security Tips - 1
Long 20-character true random passwords (use
KeePass to generate and store them)
Regularly apply CentOS software/security updates
– Single command: “yum update -y”
Configure firewall using iptables, to only permit traffic
from authorised ports
Install Fail2ban, bfd or similar brute-force attack
prevention system
Appropriate WordPress Security measures (refer to
previous presentations)
29
Virtual Server Security Tips - 2
Be able to “abandon ship” - keep DNS/Email on
separate server, so you can relocate if your server is
ever compromised (p0wned)
Reminder - only UNIX domain sockets for comms
between Apache <-> PHP-FPM and WordPress <->
MySQL
Perform file transfer to/from server using SCP
(operates over SSH)
Alternatively, install Pure-FTPD w/SSL to support
FTPS
30
Too Much Hassle! Is There An Easier Way?
Get someone else to set it up and/or do periodic
maintenance
Many Virtual Host providers offer a Virtual Server
management service for an extra monthly fee
You can also contact SAGE-AU - Australia’s peak
body for System Administration Professionals.
They can help you find a local Aussie for casual
SysAdmin work:
– https://www.sage-au.org.au/contact-us
31
Conclusion
Additional Tips & Configuration Notes:
– http://wpexpert.com.au/wordcamp-sydney-2014
– Will have configuration examples for PHP-FPM, Apache and MySQL
Questions and Comments:
– http://wpexpert.com.au/contact-us/