Tips to optimise your Linux server for WordPress
No matter whether you are running a small blog or a high-traffic WordPress-based website, optimising your server for WordPress should be one of your top priorities. Page speed is so important nowadays that even Google’s ranking algorithm has adapted to this. Also, a slow site means less visitors and that’s the main reason why you should be concerned. In this post, we are going to make a summary of some of the key optimization techniques that could help you get the best performance out of your Linux for WordPress server
Use a CDN like Cloudflare
Advantage: A content delivery network (CDN) sits between your origin server and your visitors, caching copies of your web pages and/or static assets at PoPs (Points of Presence) operated by the CDN provider, all over the world. Once an image, for example, has been cached, it can be served to visitors from the PoP with the lowest latency to their location, saving valuable milliseconds in page load times. Although not always the case, this is usually the access point geographically closest to the visitor.
How it’s done: The webmaster must register with a CDN service such as CloudFlare and modify their DNS records pointing to the CDN service.
Update your php version
Advantage: Many WordPress websites are running outdated versions of PHP that have reached end of life, e.g. PHP 5.6. This has become such a concern for open source maintainers that the latest versions of WP will warn you in the control panel if you are running a version of PHP older than 7.0. Obsolete versions of PHP don’t work as well as the latest versions and may include unpatched security vulnerabilities, making your WordPress site more prone to being compromised by a hacker.
For example, PHP 7.3 can handle three times more requests per second than PHP 5.6, which makes a big difference in page load times. The time to first byte (TTFB) is 44% faster between PHP 7.2 and 7.3. Therefore, it is highly recommended to always use the latest version of PHP.
How to do it: It depends on how PHP is currently installed on your WordPress server. On most servers, PHP is usually installed via a control panel that allows you to change its version easily and quickly.
Use in Apache - php-fpm
Advantage: On Apache servers, PHP runs as an Apache module in a mode called mod_php.
In short, FPM is much more efficient in terms of resource usage when handling multiple connections, and obviously the MPM’s (worker and event) both support HTTP/2, which mod_php never will.
How to do it: Install the php-fpm packages corresponding to your PHP version, enable and start the php-fpm service. Modify your Apache VirtualHosts to point PHP requests to FastCGI which runs on port 9000 by default, and update httpd.conf to use the worker instead of the MPM prefork.
Install memcache/Redis/ APCu
Advantage: An object cache (also known as a database cache) speeds up WordPress by reducing the number of queries PHP has to make to the MySQL server by caching the results of those queries in a database such as APCu, Memcached or Redis. They all work by practically using RAM to cache frequently used database queries, rather than having to run them repeatedly against the database server.