LAMP Stack Resilience: How to Keep a Linux Web Server Alive Under Load

Keeping a LAMP server alive under load means fixing the actual failure first: slow queries, runaway Apache children, exhausted PHP-FPM workers, or a full disk. Cap MySQL memory, split the database off the web box when you can, and monitor with vmstat and modstatus before changing any config.
Part of the complete web development guide.
On this page
- Start With the Failure You Actually Have
- Separate the Web Layer From the Database
- Use PHP-FPM, Not mod_php
- Make the Database Boring
- Automate Backups You’ve Actually Restored
- Watch the Right Things
- Test Failure on Purpose
- FAQ
- Do I really need to split the web and database servers?
- Is LAMP still a good choice in 2026?
- How often should I review slow query logs?
Most LAMP stacks don’t fall over because of a traffic spike. They fall over because of a slow query, a PHP process stuck on a dead socket, or a disk that filled up at 3am. The stack itself is fine. The failure modes are what nobody planned for. Here’s how I actually keep LAMP boxes running, based on years of building and maintaining them for small businesses and agencies around Long Island.
Start With the Failure You Actually Have
Before touching config files, figure out what kills your server. On a typical LAMP box, it’s almost always one of these:
- MySQL connections pile up because a query got slow and PHP is holding the connection open.
- Apache spawns too many children and the box starts swapping until the OOM killer shows up.
- PHP-FPM workers exhaust and requests queue behind a single stuck script.
- Disk fills from logs or uploads, and then everything fails at once.
Each one has a different fix. Guessing wastes time. Watch your stack for a week with vmstat, mysqldumpslow, and Apache’s mod_status before you change anything.
Separate the Web Layer From the Database
The single biggest resilience win on a LAMP stack is not running everything on one box. If Apache, PHP, and MySQL share a machine, a runaway query takes down your web server too. Even on a budget, splitting them helps.
If you can’t split them, at least cap the damage. Set a hard memory limit on MySQL so it can’t eat the box:
[mysqld]
innodb_buffer_pool_size = 1G
max_connections = 100
tmp_table_size = 64M
max_heap_table_size = 64M
Then set Apache or PHP-FPM so the total process count times average memory use stays under your RAM ceiling. On a 4GB box, that’s usually 20 to 30 PHP-FPM children, not 100.
Use PHP-FPM, Not mod_php
If you’re still running mod_php in 2026, you’re giving up process isolation and graceful restarts for no reason. PHP-FPM lets you reload code without dropping connections and lets you set per-pool limits.
[www]
pm = dynamic
pm.max_children = 25
pm.start_servers = 5
pm.min_spare_servers = 5
pm.max_spare_servers = 10
pm.max_requests = 500
; Kill any request that runs longer than 30 seconds
request_terminate_timeout = 30s
That request_terminate_timeout line matters more than people think. One slow external API call can pin a worker forever. Cutting it loose after 30 seconds keeps the pool moving.
Make the Database Boring
Slow queries are the number one cause of LAMP outages I’ve seen. Fix them before they fix you.
Turn on the slow query log with a low threshold, review it weekly, and add indexes where they belong. Don’t add indexes blindly; a bad index on a write-heavy table is its own problem.
[mysqld]
slow_query_log = 1
slow_query_log_file = /var/log/mysql/slow.log
long_query_time = 1
log_queries_not_using_indexes = 0
For read-heavy sites, a replica is cheap insurance. Point reporting queries and cron jobs at the replica so they never compete with customer traffic on the primary.
Automate Backups You’ve Actually Restored
A backup you’ve never tested is a wish, not a backup. Set up a nightly dump, ship it off the box, and restore it to a scratch server once a month. I use mysqldump for small databases and xtrabackup for anything over a few gigabytes.
mysqldump --single-transaction --quick --routines
--databases appdb | gzip > /backups/appdb-$(date +%F).sql.gz
Then check the file size in your monitoring. A backup that suddenly shrinks by 90% usually means the dump failed silently.
Watch the Right Things
You don’t need a huge observability stack. You need to know when things go wrong before your users do. At minimum, alert on:
- Load average trending up over 5 minutes
- Free memory dropping below 10%
- Disk usage above 85%
- MySQL
Threads_connectedclimbing past 80% ofmax_connections - HTTP 5xx rate on the front end
If you build custom applications on top of this stack, the same resilience rules apply: a clean deploy process, a rollback plan, and monitoring that actually fires. That’s part of how I approach custom web development for clients here on Long Island, and it’s not glamorous work, but it’s the difference between a two-minute blip and a two-hour outage.
Test Failure on Purpose
Once a quarter, do something uncomfortable: kill MySQL during a load test, fill the disk to 90%, or take the primary database offline for 60 seconds. Watch what happens. Fix what breaks. The first time you do this, something will surprise you. Better to find out on a Tuesday afternoon than during your busiest sales day.
FAQ
Do I really need to split the web and database servers?
For a small site, no. For anything with real traffic or a database that grows past a few gigabytes, yes. The split prevents one failure from taking down everything, and it makes scaling each layer independently possible later.
Is LAMP still a good choice in 2026?
Yes, if you know it. LAMP is stable, well-documented, and cheap to run. It’s not the fastest stack for every workload, but for content sites, custom apps, and small business platforms, it’s still a solid, boring choice that works.
How often should I review slow query logs?
Weekly for busy sites, monthly for quieter ones. Don’t wait for an outage. A query that takes 400ms today becomes a 4-second query when the table triples in size.


