📜 ⬆️ ⬇️

VPS Optimization Checklist for PHP / Mysql / Nginx

How to ensure better performance of a VPS server that runs on Nginx + PHP + Mysql? This article provides a checklist of the main settings that will significantly optimize server performance. Setup takes no more than 10 minutes and does not require anything other than editing configuration files.

Configuration examples are given for the Debian 7 operating system and the VPS server with 1 processor and 512MB of RAM.

Nginx


Settings are made in the /etc/nginx/nginx.conf file, as well as in the virtual host settings (usually in the / etc / nginx / sites-enabled folder)

Number of workers

The number of nginx workers must match the number of cores:
')
worker_processes 1; 


Cache-control headers

Setting the Cache-Control headers will significantly unload your server from repeated calls to files that do not change (or rarely change, for example, css / js / jpg / png / gif):

 location ~* \.(css|js|png|gif|jpg)$ { expires max; } 


Access log

We do not need extra disk operations because of logging; we disable:

 access_log off; 


Unix sockets

Enable unix sockets for working with PHP:

 location ~ \.php$ { fastcgi_split_path_info ^(.+\.php)(/.+)$; fastcgi_pass unix:/var/run/php5-fpm.sock; #    php-fpm, .  fastcgi_index index.php; include fastcgi_params; } 


Php


Settings are made in the configuration file fpm php-fpm.conf , which in our case is located here /etc/php5/fpm/pool.d/www.conf .

Unix sockets

Make sure that php-fpm works with unix sockets, not tcp:

 listen = /var/run/php5-fpm.sock 


APC

Install the extension APC - internal PHP cache, which will significantly save resources for the PHP parser:

 apt-get install php-apc 


MySQL setup


All MySQL settings are made in the my.cnf file, which is usually located here /etc/my.cnf .

key_buffer

If you use only MyISAM tables, set this value to 30% ... 40% of all available RAM on the server:

 key_buffer = 128M 


innodb_buffer_pool_size

If you use only InnoDB tables, set this value to the maximum possible (80% of available memory). In our case we install:

 innodb_buffer_pool_size = 350M 


Attention , you can install such knowledge only by significantly reducing the key key value . Those. Between these two settings you need to make a choice, which depends on the type of tables used (MyISAM or InnoDB).

innodb_flush_log_at_trx_commit

Significant write acceleration for innoDB tables can be achieved by setting this parameter to 0, when the write buffer will be flushed to disk not after each operation, but once a second:

 innodb_flush_log_at_trx_commit = 0 


innodb_flush_method

Setting this option to O_DIRECT avoids double caching (it turns off the operational cache for MySQL data files):

 innodb_flush_method = O_DIRECT 


thread_cache_size

This option determines the size of the cache for threads created. It is selected experimentally, but it is better to increase the starting knowledge to 16:

 thread_cache_size = 16 


query_cache_size

Turn on MySQL internal cache:

 query_cache_size = 16 


The value should be increased as necessary. Do not forget that the cache stops working efficiently on tables that are frequently updated.

Summary


As a summary - a short list with the most important settings highlighted:



Sources


These articles contain a more detailed description of these settings, as well as additional methods for optimizing the server side.

Source: https://habr.com/ru/post/221803/


All Articles