Make WordPress Fly With Virtual Server Hosting - WordCamp Sydney 2014
Make WordPress Fly with Virtual Server Hosting
WordCamp Sydney 2014
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?
How Shared Web Hosting Limits You
Throttling of Resources
Limited ability to tune & reconfigure services
No PHP Opcode caching
Might have MySQL query caching enabled, but likely overcommitted
Why Caching Plugins Are Not The Answer - 1
Two main categories of caching plugins:
–Page caching (e.g. WP Super Cache, Hyper Cache)
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
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.
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
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.
–Better WordPress Minify
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
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
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
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)
Common Virtual Private Server Types
–Based on containerization
–Efficient, but does not allow users to change OS kernel version or have dedicated swap space
–Usually offered at lower price
–Full ability to customise all aspects of VM configuration
–Allows dedicated swap space
–Some performance overhead
–Usually more expensive
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
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
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’
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
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
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
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
Who Provides Pure SSD Virtual Server Hosting?
Hosted in Australia:
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”.
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
PHP Opcode Caches - II
–Bundled with PHP 5.5
–Not as fast as Zend Opcache
+ Recognises identical copies of PHP files
+ Saves lots of RAM if you have multiple WordPress sites
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
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
Anything Else To Speed Things Up?
This speeds up site loading and reduces the amount of data transferred.
This will work on your current shared host as well!
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)
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
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:
Additional Tips & Configuration Notes:
–Will have configuration examples for PHP-FPM, Apache and MySQL
Questions and Comments: