Report this

What is the reason for this report?

[HELP] LEMP Server Timeout Error.

Posted on November 2, 2020

Hi,

I have a 4GB Raspberry Pi 4 and I have mounted a LEMP server, with a domain in Namecheap, following this guide: https://www.techcoil.com/blog/how-to-host-a-wordpress-website-on-a-raspberry-pi-with-raspbian-buster-lite-and-nginx/

Right now, we have a clean WordPress installation without installing additional plugins or themes.

The error we are having is that when trying to access the web, sometimes it gives a Timeout error, and at other times it works fine. It usually happens on the first connection, and once the main page loads, you can move through the menus and load quickly.

For testing, one way to check is with PageSpeed Insights, and it usually gives “FAILED_DOCUMENT_REQUEST” error or takes a long time to load “Speed Index”.

The website is https://dualbix.com

Any ideas?

Thank you.



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!

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.

Hi there @dualbix,

There are a few things which could be causing the problem:

  • The DNS change was made recently and you still need to wait for the DNS cache to clear over the Globe
  • There are some issues with Nginx and it is not running, in this case, I could suggest following the steps from this answer here on how to troubleshoot common Nginx problems:

https://www.digitalocean.com/community/questions/how-to-troubleshoot-common-nginx-issues-on-linux-server

  • Your firewall is blocking the traffic on port 80 and/or 443 - in this case, you need to make sure that the 2 ports are open

I can see that your WordPress installation is now up and running. Would you mind sharing here with the community how did you get this to work?

Regards, Bobby

The intermittent timeout and slow-loading issues you’re experiencing with your WordPress site on a Raspberry Pi 4 LEMP server could stem from various factors, particularly performance limitations and configuration. Here’s a comprehensive approach to troubleshoot and resolve these issues:

1. Check Server Resource Usage

Raspberry Pi 4 has limited resources (4GB RAM, ARM processor), and WordPress can be resource-intensive.

  • Monitor CPU and RAM: Use htop or top to check server load:
htop

Monitor Disk I/O: Use iotop to check if disk operations are causing delays:

sudo apt install iotop
sudo iotop

2. Optimize Nginx Configuration

Ensure your Nginx is optimized for low-resource environments:

  • Open your Nginx configuration file (/etc/nginx/nginx.conf) and set reasonable limits:
worker_processes auto;
worker_connections 1024;
keepalive_timeout 10;
client_max_body_size 64M;
server_tokens off;
gzip on;
gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
gzip_min_length 256;
  • Restart Nginx.

3. Tweak PHP-FPM Settings

WordPress heavily relies on PHP, and poorly configured PHP-FPM can cause timeouts.

  • Open /etc/php/7.x/fpm/pool.d/www.conf (adjust 7.x to match your PHP version):
sudo nano /etc/php/7.x/fpm/pool.d/www.conf
  • Update the following:
pm = dynamic
pm.max_children = 10
pm.start_servers = 3
pm.min_spare_servers = 2
pm.max_spare_servers = 4
  • These values are optimized for low-resource systems like Raspberry Pi.

  • Restart PHP-FPM:

sudo systemctl restart php7.x-fpm

4. Database Optimization

  • Enable Query Cache in MySQL/MariaDB: Edit /etc/mysql/mariadb.conf.d/50-server.cnf and add:
query_cache_size = 16M
query_cache_limit = 1M
query_cache_type = 1
  • Check for Slow Queries: Enable the slow query log and investigate:
SET GLOBAL slow_query_log = 'ON';
  • Optimize Tables: Run:
sudo mysqlcheck -o --all-databases

5. Enable Caching in WordPress

Caching can drastically reduce server load and improve response times.

  • Install a Caching Plugin: Consider lightweight caching plugins such as:
    • WP Super Cache
    • W3 Total Cache
  • Static File Cache: Configure Nginx to serve cached pages:
location / {
    try_files $uri $uri/ /index.php$is_args$args;
}

Check Logs for Clues

Review server logs for timeout errors or warnings:

  • Nginx Logs:
sudo tail -f /var/log/nginx/error.log
  • PHP-FPM Logs:
sudo tail -f /var/log/php7.x-fpm.log

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.