শেয়ার

Deployment on a VPS or dedicated server

On shared hosting one cron line runs everything. On your own server you can run the scheduler and workers as services, add probes in other regions and tune the database. This page is the reference setup.

Layout

/var/www/monitor/            the application (document root = this folder)
/var/www/monitor/includes/config.php   not in git, mode 640, owned by the web user
/var/www/monitor/storage/    logs, cache, spool  (writable)
/var/www/monitor/uploads/    logos, payment proofs (writable)

nginx + PHP-FPM

server {
    listen 443 ssl http2;
    server_name monitor.example.com;
    root /var/www/monitor;
    index index.php;

    ssl_certificate     /etc/letsencrypt/live/monitor.example.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/monitor.example.com/privkey.pem;

    location ~ ^/(includes|storage|cron|probe|agent|lang)/ { deny all; }
    location ~ /\.(ht|git) { deny all; }
    location = /installed.lock { deny all; }

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }
    location ~ \.php$ {
        include fastcgi_params;
        fastcgi_pass unix:/run/php/php8.2-fpm.sock;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param HTTP_AUTHORIZATION $http_authorization;
        fastcgi_read_timeout 120;
    }
    client_max_body_size 10m;
}

The HTTP_AUTHORIZATION line matters: the API, the probes and the agents send bearer tokens. install.php and db_update.php are opened directly, so leave .php files reachable; everything else goes through index.php.

Apache

The shipped .htaccess rewrites every missing path to index.php, blocks the private folders and passes the Authorization header to PHP. Enable mod_rewrite and AllowOverride All (or copy the rules into the vhost) and run PHP-FPM through mod_proxy_fcgi.

PHP-FPM

A pool for the web with pm.max_children sized to memory (each request needs about 30–60 MB), max_execution_time 60, memory_limit 256M, upload_max_filesize and post_max_size 10M. Workers and probes run from the CLI and ignore these.

Services: scheduler, workers, probe

On a VPS do not use cron/cron.php; run the parts as long-lived processes.

/etc/systemd/system/aim-scheduler.service:

[Unit]
Description=AllInOneMonitor scheduler
After=network-online.target mariadb.service
[Service]
User=www-data
WorkingDirectory=/var/www/monitor
ExecStart=/usr/bin/php cron/scheduler.php --daemon
Restart=always
RestartSec=5
[Install]
WantedBy=multi-user.target

/etc/systemd/system/aim-worker@.service (a template, N instances):

[Unit]
Description=AllInOneMonitor worker %i
After=network-online.target mariadb.service
[Service]
User=www-data
WorkingDirectory=/var/www/monitor
ExecStart=/usr/bin/php cron/worker.php --daemon
Restart=always
RestartSec=5
Nice=5
[Install]
WantedBy=multi-user.target
systemctl enable --now aim-scheduler
systemctl enable --now aim-worker@1 aim-worker@2 aim-worker@3

Each worker claims up to 25 jobs at a time, runs HTTP-type checks in parallel, exits by itself when its memory passes 256 MB (systemd restarts it), and records a heartbeat the health page reads. Start with one worker per 300–500 monitors at 1-minute intervals and add instances when pending in Admin → Queue grows. A worker can be dedicated to a queue: ExecStart=/usr/bin/php cron/worker.php --daemon --queue=notify,webhook keeps notifications flowing while check workers are busy.

Keep the hourly and daily housekeeping: the scheduler queues them as system jobs, so at least one worker without a --queue restriction must run.

A probe on the same host is not needed (the main server is the core location). For more regions install probes on small VPSes elsewhere with their own unit (see Probes); they need only outbound HTTPS to the application.

Where you prefer cron over daemons: * * * * * php /var/www/monitor/cron/scheduler.php and * * * * * php /var/www/monitor/cron/worker.php 55 (one 55-second burst per minute, several lines for several workers).

MariaDB tuning

  • innodb_buffer_pool_size: 50–70 % of the memory of a dedicated database server; the result and metric tables are what grows.
  • innodb_flush_log_at_trx_commit = 2 is acceptable for monitoring data and halves write latency.
  • max_connections ≥ web pool size + workers + probes × 2 + 20.
  • Keep sql_mode at the server default; the schema uses utf8mb4.
  • The big tables are monitor_results (one row per check per location) and server_metrics (one row per agent sample). Both are indexed by (monitor_id|server_id, time) and pruned in batches of 5,000 rows by the daily housekeeping according to each plan's retention, so no manual cleanup is needed.

Retention and partitioning. Raw rows older than the plan's history days are deleted every day; daily and hourly roll-ups are kept for two years. On installations with many thousands of monitors at short intervals, partitioning monitor_results and server_metrics by month (PARTITION BY RANGE (TO_DAYS(checked_at))) makes pruning instant; the application does not need to know about partitions.

HTTPS and reverse proxies

Serve the site over HTTPS only (Let's Encrypt). Behind Cloudflare or a reverse proxy, turn on trust proxy in Admin → Settings → Security so the visitor IP comes from X-Forwarded-For / CF-Connecting-IP (rate limits, login history and the audit log use it). Custom status-page domains need a certificate for each name on the edge.

Backups

Database + includes/config.php + uploads/ + storage/ — see Backup & recovery.

Zero-downtime update

  1. mysqldump the database and copy includes/config.php.
  2. Extract the new release into a new folder (/var/www/monitor-2.1.0), copy includes/config.php, uploads/ and storage/ into it.
  3. php db_update.php from the new folder (adds tables and columns; the old code keeps running on the old columns meanwhile).
  4. Point the web root symlink (or the vhost root) at the new folder and reload nginx (nginx -s reload); PHP-FPM picks the new files up at once (clear OPcache with opcache_reset() or reload FPM).
  5. systemctl restart aim-scheduler 'aim-worker@*' so the daemons load the new code.
  6. Probes with self-update on fetch the new check library on their next heartbeat; restart them to activate it.
  7. Keep the old folder until Admin → System health looks right, then remove it.

Scaling out further

  • Checks: more workers on the main host, then probes in other regions (each probe pulls only its own location's jobs). A probe can be placed next to a customer's data centre for an "internal" location when private targets are allowed for that organisation.
  • Notifications: a worker with --queue=notify,webhook.
  • Database: a replica for reporting is not used by the application; grow the primary.
  • Web: stateless PHP behind a load balancer works because sessions are in PHP's session store — point session.save_path of every node at a shared Redis/Memcached or a shared directory.
এই পেজটি কি সহায়ক ছিল?

একটি ক্লিক আমাদের এই ডকস উন্নত করতে সাহায্য করে।

এই পেজ শেয়ার করুনসাধারণ লিংক - কোনো ট্র্যাকার নেই, ক্লিক না করা পর্যন্ত কিছু লোড হয় না।