The LAMP stack is the "hello world" for deploying dynamic web applications. It's fast, flexible, and reliable, which means a developer or sysadmin won't go far in their career without interacting with the stack and its services.
LAMP is an acronym of the core services that make up the web application: Linux, Apache, MySQL, and PHP.
- Linux is the operating system running the whole stack.
- Apache is a web server that responds to HTTP requests from users and returns web pages.
- MySQL is a database that stores and returns information based on queries from the web application.
- PHP is a scripting language used to query the MySQL database and build new pages.
LAMP stacks are the foundation for tons of end-user applications, with Wordpress being the most popular.
You've already deployed a LAMP stack, either in testing or production. You want to monitor every service's performance and availability to ensure the best possible experience for your end-users. You might also be particularly interested in using a free, open-source monitoring tool.
Depending on your monitoring experience, you may not even know what metrics you're looking for, much less how to build dashboards using a query language. You need a robust monitoring experience that has the metrics you need without a ton of required setup.
In this tutorial, you'll set up robust LAMP stack monitoring with Netdata in just a few minutes. When you're done, you'll have one dashboard to monitor every part of your web application, including each essential LAMP stack service.
This dashboard updates every second with new metrics, and pairs those metrics up with preconfigured alarms to keep you informed of any errors or odd behavior.
To follow this tutorial, you need:
- A physical or virtual Linux system, which we'll call a node.
- A functional LAMP stack. There's plenty of tutorials for installing a LAMP stack, like this one from Digital Ocean.
- Optionally, a Netdata Cloud account, which you can use to view metrics from multiple nodes in one dashboard, and a whole lot more, for free.
If you don't have the free, open-source Netdata monitoring agent installed on your node yet, get started with a single kickstart command:
The Netdata Agent is now collecting metrics from your node every second. You don't need to jump into the dashboard yet,
but if you're curious, open your favorite browser and navigate to
NODE with the hostname or IP address of your system.
There's nothing you need to do to enable system monitoring and Linux monitoring with the Netdata Agent, which autodetects metrics from CPUs, memory, disks, networking devices, and Linux processes like systemd without any configuration. If you're using containers, Netdata automatically collects resource utilization metrics from each using the cgroups data collector.
Let's begin by configuring Apache to work with Netdata's Apache data collector.
Actually, there's nothing for you to do to enable Apache monitoring with Netdata.
Apache comes with
mod_status enabled by default these days, and Netdata is smart enough to look for metrics at that
endpoint without you configuring it. Netdata is already collecting
metrics, which is just part of your web server monitoring.
The Netdata Agent also comes with a web log
collector, which reads Apache's access
log file, procesess each line, and converts them into per-second metrics. On Debian systems, it reads the file at
At installation, the Netdata Agent adds itself to the
group, which gives the
netdata process the
right privileges to read Apache's log files. In other words, you don't need to do anything to enable Apache web log
Because your MySQL database is password-protected, you do need to tell MySQL to allow the
netdata user to connect to
without a password. Netdata's MySQL data
collector collects metrics in read-only
mode, without being able to alter or affect operations in any way.
First, log into the MySQL shell. Then, run the following three commands, one at a time:
sudo systemctl restart netdata, or the appropriate alternative for your
system, to collect dozens of metrics every second for robust MySQL monitoring.
Unlike Apache or MySQL, PHP isn't a service that you can monitor directly, unless you instrument a PHP-based application with StatsD.
Open your PHP-FPM configuration for editing, replacing
7.4 with your version of PHP:
Not sure what version of PHP you're using? Run
Find the line that reads
;pm.status_path = /status and remove the
; so it looks like this:
Next, add a new
/status endpoint to Apache. Open the Apache configuration file you're using for your LAMP stack.
Add the following to the end of the file, again replacing
7.4 with your version of PHP:
Save and close the file. Finally, restart the PHP-FPM, Apache, and Netdata processes.
As the Netdata Agent starts up again, it automatically connects to the new
127.0.0.1/status page and collects
per-second PHP-FPM metrics to get you started with PHP monitoring.
If the Netdata Agent isn't already open in your browser, open a new tab and navigate to
NODE with the hostname or IP address of your system.
If you signed up for Netdata Cloud earlier, you can also view the exact same LAMP stack metrics there, plus additional features, like drag-and-drop custom dashboards. Be sure to claim your node to start streaming metrics to your browser through Netdata Cloud.
Netdata automatically organizes all metrics and charts onto a single page for easy navigation. Peek at gauges to see
overall system performance, then scroll down to see more. Click-and-drag with your mouse to pan all charts back and
forth through different time intervals, or hold
SHIFT and use the scrollwheel (or two-finger scroll) to zoom in and
out. Check out our doc on interacting with charts for all the details.
The System Overview section, which you can also see in the right-hand menu, contains key hardware monitoring charts, including CPU utilization, memory page faults, network monitoring, and much more. The Applications section shows you exactly which Linux processes are using the most system resources.
Next, let's check out LAMP-specific metrics. You should see four relevant sections: Apache local, MySQL local, PHP-FPM local, and web log apache. Click on any of these to see metrics from each service in your LAMP stack.
Here's a quick reference for what charts you might want to focus on after setting up Netdata.
|Chart name / context||Type||Why?|
|System Load Average (||Hardware monitoring||A good baseline load average is |
|System RAM (||Hardware monitoring||Look at the |
|Uptime (||Apache monitoring||This chart should always be "climbing," indicating a continuous uptime. Investigate any drops back to |
|Requests By Type (||Apache monitoring||Check for increases in the |
|Queries (||MySQL monitoring||Queries is the total number of queries (queries per second, QPS). Check this chart for sudden spikes or drops, which indicate either increases in traffic/demand or bottlenecks in hardware performance.|
|Active Connections (||MySQL monitoring||If the |
|Performance (phpfpm_local.performance)||PHP monitoring||The |
The Netdata Agent comes with hundreds of pre-configured alarms to help you keep tabs on your system, including 19 alarms designed for smarter LAMP stack monitoring.
Click the 🔔 icon in the top navigation to see active alarms. The Active tabs shows any alarms currently triggered, while the All tab displays a list of every pre-configured alarm. The
You've now set up robust monitoring for your entire LAMP stack: Linux, Apache, MySQL, and PHP (-FPM, to be exact). These metrics will help you keep tabs on the performance and availability of your web application and all its essential services. The per-second metrics granularity means you have the most accurate information possible for troubleshooting any LAMP-related issues.
Another powerful way to monitor the availability of a LAMP stack is the
collector, which pings a web server at
a regular interval and tells you whether if and how quickly it's responding. The
response_match option also lets you
monitor when the web server's response isn't what you expect it to be, which might happen if PHP-FPM crashes, for
The best way to use the
httpcheck collector is from a separate node from the one running your LAMP stack, which is why
we're not covering it here, but it does work in a single-node setup. Just don't expect it to tell you if your whole
If you're planning on managing more than one node, or want to take advantage of advanced features, like finding the source of issues faster with Metric Correlations, sign up for a free Netdata Cloud account.