How to speed up and optimize WordPress on Linux VPS

It doesn’t matter if you run a small blog or website, if high traffic is based on WordPress, WordPress optimization should be one of the top priorities. Page loading speed is so important today that even Google’s ranking algorithm has been adapted to this. Plus, a slow site means fewer visitors, which is the main reason you should be concerned. In this post, we will give a quick overview of some of the key optimization techniques that could help you get your WordPress site and Linux VPS up to speed.

WordPress optimization techniques will be limited to the hosting service you are using. If you are using shared hosting, then you will have little control over your server setup and you will not be able to perform advanced optimization techniques. Please note that many VPS providers will not give you full control (root access) to your VPS. That is why we always recommend using our Linux VPS hostingwhich runs on SSD drives to get your WordPress website up and running quickly. If you get a VPS from us, you will have full control (root access) over the server to perform server side optimization. We recommend switching from general to VPS as soon as possible. You will see many improvements in your site’s performance, even by switching to a VPS alone, without any further optimization.

LEMP (Linux, Nginx, MySQL / MariaDB and PHP)

Using a solid stack of software like LEMP will certainly help you get the best out of your WordPress installation. The LEMP stack consists of Nginx, which is used to run some of the busiest sites on the Internet. This will greatly improve the performance of your WordPress site and server. If you don’t have LEMP installed on your WordPress server, go ahead and install Nginx, MySQL and PHP-FPM using our guide. You can find more performance tips, WordPress and Nginx improvements here. Running the latest software is very important too, so make sure all your WordPress, Nginx, and other server software is up to date. Upgrading PHP to PHP 7 will be very helpful too, as PHP 7 is considered twice as fast as PHP 5.6. Also, according to some criteria, PHP 7 uses 30% less memory and serves more than 3 requests.

Reducing server load by disabling unused services running on it will have a huge impact on the performance of your site. The server will handle more traffic without disrupting some important services such as database servers.

Caching

Caching is very important if you want to speed up your WordPress site. By implementing some good caching techniques, you can improve performance by several hundred times. We’ll look at some of the more efficient caching techniques.

Server side caching

Adding caching like OPcache to your PHP will improve performance significantly. This is a very simple method as OPcache comes with PHP core by default. Just make sure your PHP version is higher than 5.5, although we recommend using PHP 7 with WordPress.

Caching plugins

For caching, your posts and pages in WordPress are converted to static files. Installing a caching plugin in WordPress is pretty easy, just like any caching plugin in WordPress. However, you may have to take care of the configuration after installation. Almost all caching plugins provide user documentation, so you can easily learn how to tune the plugin for maximum performance. You can check our tutorial for w3 total cache here.

The category of caching plugins for WordPress can be found at https://wordpress.org/plugins/tags/caching

Browser caching

Another caching method that you can implement for your WordPress site is to use browser caching. Browser caching means that the client’s web browser will download and store active files such as CSS, JS, and images in local storage for a certain amount of time, which can reduce the number of requests for each page and significantly reduce server load. To enable browser caching just add the lines below to your .htaccess file:

## EXPIRES CACHING ##
<IfModule mod_expires.c>
  ExpiresActive On
  ExpiresByType image/jpg "access 1 year"
  ExpiresByType image/jpeg "access 1 year"
  ExpiresByType image/gif "access 1 year"
  ExpiresByType image/png "access 1 year"
  ExpiresByType text/css "access 1 month"
  ExpiresByType text/html "access 1 month"
  ExpiresByType application/pdf "access 1 month"
  ExpiresByType text/x-javascript "access 1 month"
  ExpiresByType application/x-shockwave-flash "access 1 month"
  ExpiresByType image/x-icon "access 1 year"
  ExpiresDefault "access 1 month"
</IfModule>
## EXPIRES CACHING ##

If you are using Nginx instead of Apache as your web server, add the following lines in the server block for your domain name:

location ~*  .(jpg|jpeg|png|gif|ico|css|js)$ {
  expires 365d;
}

Other WordPress optimization techniques

Many of the methods we mentioned earlier cannot be performed if you are on shared hosting as server side optimization requires special access to the hosting environment. You can do the following optimizations even on shared hosting.

Add GZIP compression

Gzip compression is necessary in order to reduce the size of the data that is sent from your server. Enabling Gzip compression is pretty easy, just add the lines below to your .htaccess file:

<IfModule mod_deflate.c>
  # Compress HTML, CSS, JavaScript, Text, XML and fonts
  AddOutputFilterByType DEFLATE application/javascript
  AddOutputFilterByType DEFLATE application/rss+xml
  AddOutputFilterByType DEFLATE application/vnd.ms-fontobject
  AddOutputFilterByType DEFLATE application/x-font
  AddOutputFilterByType DEFLATE application/x-font-opentype
  AddOutputFilterByType DEFLATE application/x-font-otf
  AddOutputFilterByType DEFLATE application/x-font-truetype
  AddOutputFilterByType DEFLATE application/x-font-ttf
  AddOutputFilterByType DEFLATE application/x-javascript
  AddOutputFilterByType DEFLATE application/xhtml+xml
  AddOutputFilterByType DEFLATE application/xml
  AddOutputFilterByType DEFLATE font/opentype
  AddOutputFilterByType DEFLATE font/otf
  AddOutputFilterByType DEFLATE font/ttf
  AddOutputFilterByType DEFLATE image/svg+xml
  AddOutputFilterByType DEFLATE image/x-icon
  AddOutputFilterByType DEFLATE text/css
  AddOutputFilterByType DEFLATE text/html
  AddOutputFilterByType DEFLATE text/javascript
  AddOutputFilterByType DEFLATE text/plain
  AddOutputFilterByType DEFLATE text/xml

  # Remove browser bugs (only needed for really old browsers)
  BrowserMatch ^Mozilla/4 gzip-only-text/html
  BrowserMatch ^Mozilla/4.0[678] no-gzip
  BrowserMatch bMSIE !no-gzip !gzip-only-text/html
  Header append Vary User-Agent
</IfModule>

In case you are using Nginx, add the following lines in your Nginx configuration file:

gzip on;
gzip_comp_level 2;
gzip_http_version 1.0;
gzip_proxied any;
gzip_min_length 1100;
gzip_buffers 16 8k;
gzip_types text/plain text/html text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript;

# Disable for IE < 6 because there are some known problems
gzip_disable "MSIE [1-6].(?!.*SV1)";

# Add a vary header for downstream proxies to avoid sending cached gzipped files to IE6
gzip_vary on;

Use only required plugins

Using plugins in WordPress is essential, but you should be aware that using unnecessary plugins and plugins that are not being encoded in a rational way can affect the performance of your site. Thus, our recommendation is to install and enable the WordPress plugins that you really need for your project, and also to make sure these plugins don’t slow down your site.

Use good themes

If you are using a well-coded theme for your WordPress site, you are more likely to have a fast loading website. Some theme designers tend to include features that affect performance. There are so many well-coded WordPress themes out there, both free and paid. You just need to do some quick research, and you will most likely choose a theme that will help you speed up your WordPress site’s load time. If you have time, you can read interesting articles about themes in WordPress.

Image optimization

Yes, images are essential. But, think about how bad images can affect your site’s loading speed. Unoptimized and large images will load slowly, which can lead to the fact that the visitor leaves the site. To save time, bandwidth and improve search engine rankings, you need to take care of the graphics displayed on your site. Use image optimization with some of the WordPress plugins developed for this reason, such as WP Smush

If you have problems with graphics that are already optimized, try to consider the need to change the rendering. Maybe you can reduce the number of images by replacing them with text.

Minify CSS and JavaScript files

Minifying CSS files can be good, especially if you are unable to combine them into a single optimized file. The same goes for JS files. Chances are, there are many plugins that can help you with this, including our previously mentioned W3 Total Cache plugin.

Content delivery network

Sometimes the geographic distance between the server where your site is hosted and your site visitors can affect your loading speed. A common solution to this problem is to use a Content Delivery Network or CDN. Using a CDN service you can offload static files as well as images so that your website visitors can have a better experience. This will reduce the load on the server and will significantly improve the site’s performance.

Best wishes to you! If you have questions or ideas on site performance, write in the comments.

Sidebar