Tagged: PHP

Complete Guide to Debug LOAD Issue in LAMP Stack [Linux/Apache/Mysql/PHP]

Problem Statement

There is php, apache , mysql based application, the stack is hosted on Linux.

This is a single server application, where PHP and apache are on an ubuntu-based Linux server and MySQL is on another server.

let’s suppose the application becomes unresponsive after a certain load. Now you want to RCA and optimize the bottleneck of the problem, the following will provide you a complete guide to debug LOAD issue in LAMP stack

LAMP Stack Component

To figure out the load issue, first, we need to figure out the dependent items of the stack, from where the problem may arise. We divide this into two parts, hardware, and software


  1. Linux server hosting apache2
  2. Linux server hosting MySQL


  1. Apache/Nginx webserver
  2. PHP processing [running as module/fpm/fastcgi]
  3. Mysql server

Root Cause Analysis [RCA]

Flow Of Analysis

Considering the situation where the site is becoming unresponsive,

the very first thing that is coming to consideration is, Hardware limitation

Monitor Hardware Component

Q1:- are the resources enough to handle so many requests?

To get the answer to this question, we analyze the system state. considering that we are on Linux OS [ubuntu], however, most *nix are same.

check for web server machine

  • If possible, put monitoring on CPU utilization. You can use htop/top command to check the process and load
  • Put monitoring on ram utilization. htop/top command can be used to check the log
  • In case of the machine become unresponsive, check for System logs [syslogs], mostly under var/log/syslog location
    • tail -f /var/log/syslog
  • Check the stale process using
    • strace or pmap <pid>
    • ls /proc/<pid>
    • cat /proc/<pid>/status
    • cat /proc/cpuinfo
    • cat /proc/meminfo
    • cat /proc/zoneinfo
    • cat /proc/mounts

htop/top is only helpful if you monitor during load as they shows current state of the system otherwise put the monitoring by using any tool.

There are various tool like cloud instances also provide resource monitoring as Cloudwatch in AWS, or, one can setup open source tool like nagios, zabbix, opennms or there are handy utilitites like, glance, atop, etc https://www.cyberciti.biz/tips/top-linux-monitoring-tools.html

There are 2 main factors to analyze

Apart from these 2, one can also check for another two factors. As most of the cloud systems provide a good bandwidth allocation and that can also be checked from Network monitoring and Most systems are equipped with SSD, so these are not the major factory but can play a vital role if your application highly depends on that, like you are using firebase data to read and write which need higher I/O or delivering large media file

check for the database server machine

If the database server is deployed on another machine, then, we need to follow the same steps as we covered in the earlier section to figure if the database server is enough or not.

In case, you are using AWS RDS service for the database, you can use AWS cloudwatch or RDS monitoring tool with CPU matrix or connection matrix to figure out the root cause.

Most of the cloud provider provides these type of system/instance/machine monitoring tool, where we check the hardware component dependency and bottleneck areas.

Now there may be two situations,

  1. Either server resources are NOT enough,
  2. Or server resources are available even at peak load.

Server resources are NOT enough


* Scale Up / Scale Out the resources [Vertical Scaling / Horizontal Scaling]

* Validate the request are legtimate, means there is no bocus request flooding your server to keep busy

If hardware is the bottleneck, we need to upgrade the resource either by following Vertical Scaling or Horizontal Scaling

Server resources are enough

If we are at this point, where resources are available like, servers are healthy and under the threshold limit, it means that hardware is not the bottleneck, we should check for the software level bottleneck.

Monitor Software Component

Q2: if the server resources are enough, then what might be the root cause of the unresponsive web app?

In a typical PHP website, the software stack includes.

Monitoring Apache Logs using Zabbix

Apart from monitoring server hardware and software key variable like CPU/Memory/Disk/Process, We also require monitoring of apache logs using Zabbix to monitor all from a…
Read More

How important it is to upgrade your AMP(Apache, PHP, Mysql) Stack?

Whenever we have a project/product to develop using LAMP stack, the following are the major factors in Platform stack version selection

  • Availability of software(PHP, MYSQL, APACHE)
  • Configuration/Setup of developer machines
  • Hosting server restriction
  • Skill set of employees

Let’s say you start an application today with the latest stable release of stack , then it will be outdated in a year or more as technology is updating regularly.

Q: – So the question is, is it necessary to update the product/ project or to guide your client about the required updates for that ?

My answer will be Yes.

Now you can question that do you understand the aftermath for this,

  • Upgradation requires the efforts
  • Effort includes Development effort, Testing Effort, Skillset of Resources
  • Effort create cost

So, are you sure you we should do the upgrades and guide our client for this.

I will again say , Yes.

Q: – So tell me Why it so necessary to upgrades while we can save the cost?

I will start with an example,

Think that you are a Civil Engineer, and you build the bridges. Let’s say you build a bridge, and ask yourself, is this one time job to build that bridge or owner need to maintain that half-yearly/yearly/bi-early/ so that it stay for long and secure.”

Mainly, There are two types of upgrades

  • Major :   It may require refactoring of application [Generally Call Upgrades]
  • Minor : In 90% of cases, minor updates does not break anything, that is an improvement or fixes of bugs of any software.[Generally called Updates]

So, Minor upgrades does not include a major cost, however, major upgrades may have major cost factor.

If you are concerned about the security or your application includes the payment, I will recommend that you must have your application stack up-to-date, However, My Practical experience will suggest you to do the upgrades once it is stable and you had the review/feedback from the market so that your have more visibility in advance before updating.

Q:- It may be that your application does not contain any payment information, so do you still need to update that?

Yes, it is advised to keep your application updated to keep it less vulnerable ( I am saying less as upgrades itself can’t prevent all the loopholes), To protect your user data and your valuables and it can save a lot money from ransomware or hackers.

So is this all about security ?

No this is more than security,

Up-gradation provides protection from existing loopholes, apart from that, It also helps you in optimisation the performance of your site.

Here is an example of bench marking of popular PHP framework laravel over various php version.https://dzone.com/articles/php-56-vs-php-7-performance-benchmarks-with-larave,

You can see that how much the up-gradation help in optimisation and resource utilisation that is also a cost saving for long term. So your cost of up-gradation can be covered from here while you utilise all the benefits of up gradation.

This is also not about PHP only. You must upgrade all the stack from time-time where it is OS , Apache Web server or Mysql.

Every Software has their END OF LIFE and upgrades cycle and it is different for each software. How ever One must deploy all the security and BUG Fixes patch time-time that does not require major effort and before the END OF LIFE of that software one must upgrade the software.

Following articles shows how  the cyber attacks cost the company  

Cybercrime will remain a large-scale concern for years to come. From 2019–2023E, approximately $5.2 trillion in global value will be at risk from cyberattacks, creating an ongoing challenge for corporations and investors alike https://www.weforum.org/agenda/2019/11/cost-cybercrime-cybersecurity/

Make sure to check the support from Vendor for your software.

PHP Support
  • Apache Httpd : Apache httpd 2.2 is End-of-Life since December 2017 and should not be used. Apache 2.4 should be utilised. https://httpd.apache.org/