Question

What is the best configuration for PHP7.0 with Nginx?

I have 1GB RAM. But with 5000 visits per day the PHP7.0-fpm service dies when it hits more than 80% CPU. I know there may be several things. But I would like to know what would be the best php configuration for a server only with 1GB RAM and 1CPU.


Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

How is your RAM usage? Look in dmesg for OOM (out of memory) messages. You might be using too much memory.

In your pool configuration, if “pm.max_requests” is 0 (I think this is the default), try using a value of 500. It respawns php-fpm processes after handling a certain number of requests and this way you can avoid memory leaks in 3rd party modules. Don’t forget to restart the php-fpm service.

@Tarrioin

The best configuration really depends on what type of site you’re running. Is this strictly a PHP site or is it database driven (i.e. WordPress, Joomla, Drupal, etc), or something else?

From the CLI, can you run top then hit SHIFT+M, then c, and finally e and post screenshot link so we can take a closer look at some general stats?

The arguments mentioned after top simply sort the process list and make it easier to read.

Also, when things begin to die, are you seeing anything logged? If you would, please post the output of:

tail -20 /var/log/nginx/error.log

Inside of /var/log you should also see a log for your specific PHP version. If you’ll run the same command as above for that log file as well, that’ll let us take a closer look at what’s happening with PHP as well.