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, go to:
cd /etc/alloy
- Open the configuration file:
sudo nano config.alloy
- Paste Alloy configuration:
config.alloy (Note: Do not change the creds of Prometheus and Loki and remotecfg.)
Comment your GitHub profile, and I’ll share the config.alloy file.
sudo systemctl restart alloy.service
- Go to Grafana Cloud and confirm that Alloy is connected.
Step 2: Verify System Metrics in Grafana
- Go 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
sudo nano /etc/apache2/mods-available/status.conf
- Add the following (if not present):
<Location "/server-status">
SetHandler server-status
Require local
</Location>
sudo systemctl restart apache2.service
Step 4: Enable PHP-FPM Status & Ping Pages
sudo nano /etc/php/8.1/fpm/pool.d/www.conf
- Change / add the following:
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
sudo systemctl restart php8.1-fpm
- Check the
/run/php/ the file (php8.1-fpm.sock) is created or not.
4.2 Create php-fpm-status.conf
sudo nano /etc/apache2/conf-available/php-fpm-status.conf
<Location "/status">
SetHandler "proxy:unix:/run/php/php8.1-fpm.sock|fcgi://localhost"
</Location>
<Location "/ping">
SetHandler "proxy:unix:/run/php/php8.1-fpm.sock|fcgi://localhost"
</Location>
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*.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
[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
sudo systemctl restart alloy
Step 7: Verify PHP-FPM Metrics in Grafana
- Return to Grafana Cloud → Explore.
- Search for PHP-FPM metrics such as:
1. phpfpm_active_processes
2. phpfpm_requests_total
3. phpfpm_slow_requests
- Confirm that all Apache, System, PHP-FPM metrics are now visible.
Top comments (0)