5.3.4. Speed up and optimize your VPS (basic tips)

Site optimization (including its scripts and pages) is the top priority. It is recommended that you start with this.

This option involves not only fine-tuning the software included in the standard installation (Apache web server, MySQL, PHP), but also installing various performance enhancers and modifying the software configuration. The most popular options are:

  • Disabling unused services — by default (especially if you're using pre-installed software), quite a few services (daemons) are running that your site may not use at all. You should disable them — this will free up some server resources.
  • Installing Nginx — It is installed in front of Apache and handles static files, reducing the load on the server and increasing the speed at which these files are served.
  • Installing a PHP accelerator (such as OPcache) — once installed, this service caches pre-compiled bytecode, thereby speeding up the execution of PHP scripts and reducing the overall load on the server.
  • Installing Memcache(d) — this allows you to cache data in the server's RAM rather than on disk. Exactly what and how to cache depends on the site's scripts. Typically, caching is configured for the most frequent MySQL queries, intermediate results of PHP script execution, and sometimes pre-rendered pages. It is useful because, by utilizing very fast RAM, data is written to or retrieved from memory almost instantly.
  • Switching PHP to FastCGI mode or using PHP-FPM — this significantly reduces the load on the server and allows it to run more stably.
  • Installing the PageSpeed module — this module, developed by Google, does not so much reduce server load as it optimizes the data served to site visitors, thereby speeding up the site's performance. However, configuring this module requires particular care when setting up the rules, as incorrect configuration can lead to various errors.

Another option, which is specifically listed separately — completely abandoning the use of the Apache web server (which is slow and resource-intensive) and replacing it with the nginx+PHP-FPM stack. This is very fast and cost-effective, but requires fairly advanced skills to configure such a solution properly.

The final solution is to increase the server's capacity.

Provided that a server with adequate specifications was selected for the site from the outset, this is truly a last resort. It should only be used in the most extreme cases, when all other options have been exhausted.

Unlike previous methods, which require a one-time optimization effort (whether paid for or done in-house) and allow you to "forget" about the problem for a long time, buying a more powerful server isn't even a solution — it's self-deception. It's treating the symptoms, not the underlying problem. Sooner or later, site traffic will grow, content will increase, and you'll have to spend even more money on a new, even faster server. Implementing optimization measures, however, will not only reduce costs (even if you have to pay for the services of optimization specialists) but also result in better site performance than simply increasing server capacity.

Content