Site icon Init HTML

Tối ưu PHP-FPM và MariaDB

Tối ưu PHP-FPM

Để tối ưu PHP-FPM, bạn hãy mở tập tin /etc/php.ini ra và tìm:

;session.save_path = "/tmp"

Thay thành:

session.save_path = "/var/lib/php/session"

Sau đó cấp quyền cho thư mục này:

chown -R nginx:nginx /var/lib/php/session

Tiếp tục mở tập tin /etc/php-fpm.d/www.conf, tìm:

pm = dynamic

Thay thành:

pm = ondemand

Tìm:

pm.max_children = 50

Thay thành:

pm.max_children = 5

Nếu bạn có VPS chỉ có từ 1 cho tới 3 CPU thì bạn nên thiết lập pm.max_children là 3. Còn nếu nhiều hơn thì nên đặt tối đa 15 chứ đừng để nhiều quá.

Tìm tiếp:

pm.max_spare_servers = 35

Thay thành:

pm.max_spare_servers = 5

Tìm tiếp:

pm.min_spare_servers = 5

Thay thành:

pm.min_spare_servers = 1

Sau đó khởi động lại PHP-FPM:

systemctl restart php-fpm.service

Tối ưu MariaDB

Mở tập tin /etc/my.cnf và đặt nội dung dưới vào cuối:

[mysqld]
key_buffer=1024M
join_buffer_size=8M
table_cache=4000
sort_buffer_size=8M
read_buffer_size=8M
read_rnd_buffer_size=8M
myisam_sort_buffer_size=128M
max_connections=800
query_cache_type=1
query_cache_limit=8M
query_cache_size=512M
tmp_table_size=40M
max_heap_table_size=40M
thread_cache_size=128
max_allowed_packet=1024M

Nhớ khởi động lại MariaDB:

systemctl restart mariadb.service

Chúc các bạn thành công!

Exit mobile version