Grafana Cloud Monitoring Setup (Apache + PHP-FPM + Alloy)
Source: Dev.to
Step 1: Install Grafana Alloy on EC2
- Go to Grafana Cloud → Collector → Configure.
- Create a new API token.
- Copy & paste the installation command provided by Grafana into your EC2 instance.
After installation, run:
cd /etc/alloy
Open the configuration file:
sudo nano config.alloy
- Paste the Alloy configuration (
config.alloy). (Do not change the credentials for Prometheus, Loki, and remotecfg.) - Comment your GitHub profile if you’d like to receive the
config.alloyfile.
Restart Alloy:
sudo systemctl restart alloy.service
Confirm that Alloy is connected in Grafana Cloud.
Step 2: Verify System Metrics in Grafana
- Navigate to Grafana Cloud → Fleet Management.
- Select the EC2 instance (identified by its IP).
- Use Explore to verify that CPU, memory, disk, and other system metrics are being received.
Step 3: Enable Apache mod_status
Edit status.conf:
sudo nano /etc/apache2/mods-available/status.conf
Add (if not present):
SetHandler server-status
Require local
Restart Apache:
sudo systemctl restart apache2.service
Step 4: Enable PHP‑FPM Status & Ping Pages
4.1 Update www.conf
sudo nano /etc/php/8.1/fpm/pool.d/www.conf
Add or modify the following directives:
listen.owner = www-data
listen.group = www-data
listen.mode = 0660
ping.path = /ping
pm.status_path = /status
listen = /run/php/php8.1-fpm.sock
Restart PHP‑FPM:
sudo systemctl restart php8.1-fpm
Verify that the socket file /run/php/php8.1-fpm.sock exists.
4.2 Create php-fpm-status.conf
sudo nano /etc/apache2/conf-available/php-fpm-status.conf
Paste:
SetHandler "proxy:unix:/run/php/php8.1-fpm.sock|fcgi://localhost"
SetHandler "proxy:unix:/run/php/php8.1-fpm.sock|fcgi://localhost"
Restart services:
sudo systemctl restart apache2
sudo systemctl restart php8.1-fpm
Step 5: Enable Required Apache Modules
sudo a2enmod proxy proxy_fcgi setenvif
sudo a2enconf php-fpm-status
sudo systemctl restart apache2
Step 6: Install PHP‑FPM Exporter
6.1 Download & Install Exporter
wget https://github.com/hipages/php-fpm_exporter/releases/download/v2.2.0/php-fpm_exporter_2.2.0_linux_amd64.tar.gz
tar -xvzf php-fpm_exporter_2.2.0_linux_amd64.tar.gz
sudo mv php-fpm_exporter /usr/local/bin/
6.2 Create Exporter User
sudo useradd --system --no-create-home --shell /usr/sbin/nologin phpfpm_exporter
sudo usermod -aG www-data phpfpm_exporter
6.3 Create Systemd Service
sudo nano /etc/systemd/system/php-fpm-exporter.service
Paste:
[Unit]
Description=PHP-FPM Prometheus Exporter
After=network.target
[Service]
User=phpfpm_exporter
Group=www-data
ExecStart=/usr/local/bin/php-fpm_exporter server \
--phpfpm.scrape-uri='unix:///run/php/php8.1-fpm.sock;/status' \
--web.listen-address=':9253'
Restart=always
RestartSec=5
[Install]
WantedBy=multi-user.target
6.4 Start the Service
sudo systemctl daemon-reload
sudo systemctl enable --now php-fpm-exporter
sudo systemctl status php-fpm-exporter
6.5 Test Metrics
curl http://127.0.0.1/status
curl http://127.0.0.1:9253/metrics
Restart Alloy to pick up the new exporter:
sudo systemctl restart alloy
Step 7: Verify PHP‑FPM Metrics in Grafana
- In Grafana Cloud → Explore, search for PHP‑FPM metrics such as:
phpfpm_active_processes
phpfpm_requests_total
phpfpm_slow_requests
- Confirm that Apache, system, and PHP‑FPM metrics are now visible.