Categories
How-To

Optimize PHP-FPM on Low Memory Nginx Servers

Are you running PHP-FPM on low memory Nginx servers and your services are crashing frequently?

The simplest way to resolve this problem is to upgrade your server, but not when you have a tight budget.

Databases usually take up a large portion of your memory but limiting memory usage may cause problems. However, if your website has low traffic, you will be able to limit your server’s memory usage without affecting performance.

In this article, I will show you how you can optimize PHP-FPM to reduce its memory usage without affecting performance.

What is PHP-FPM?

PHP-FPM is a PHP FastCGI Process Manager. It is feature-rich alternative to run PHP scripts.

To install PHP-FPM, run the following line.

$ sudo yum install php-fpm

The default settings uses more memory than required. Thus, it is necessary to configure to optimize and improve performance.

Let’s Begin

Open PHP-FPM configuration file with your preferred editor.

$ sudo vi /etc/php-fpm.d/www.conf

Look for the line to set how many child processes the process manager will spawn, at around line 61, and set it to ondemand.

...
; Note: This value is mandatory
pm = ondemand

Save and restart PHP-FPM.

$ sudo systemctl restart php-fpm

Now, your server should not run out of memory.

Performance is important for SEO as it will affect your website’s loading speed. Although you have low traffic to your website, you should not forgo SEO over performance, or vice versa.

When you optimize PHP-FPM, you will be able to improve both performance and SEO.

Also, you can install free SSL certificates on your Nginx server to increase your SEO score and for better security.

Hope this article helped you learned how to optimize PHP-FPM on low memory Nginx servers.

If you liked this article, please do share this article with your friends and family.