إنتقل إلى المحتوى الرئيسي

🟠 Apache

Apache is one of the most widely used web servers. Monitron SaaS works perfectly with Apache 2.4+ when configured correctly.


📋 المتطلبات الأساسية

  • Apache 2.4+ installed
  • mod_rewrite enabled
  • mod_ssl enabled (for HTTPS)
  • PHP 8.2+ as mod_php or via PHP-FPM

🔧 Enable Required Modules

sudo a2enmod rewrite
sudo a2enmod ssl
sudo a2enmod headers
sudo systemctl restart apache2

📝 VirtualHost Configuration

Create a new VirtualHost:

sudo nano /etc/apache2/sites-available/monitron.conf

Paste this configuration:

<VirtualHost *:80>
ServerName your-domain.com
Redirect permanent / https://your-domain.com/
</VirtualHost>

<VirtualHost *:443>
ServerName your-domain.com

# ─── Document Root ────────────────────────────────────
# 🚨 IMPORTANT: Point to the /public directory!
DocumentRoot /var/www/monitron/public

# ─── SSL Configuration ────────────────────────────────
SSLEngine on
SSLCertificateFile /etc/letsencrypt/live/your-domain.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/your-domain.com/privkey.pem

# ─── Directory Settings ───────────────────────────────
<Directory /var/www/monitron/public>
AllowOverride All
Require all granted
Options -Indexes +FollowSymLinks

# Laravel URL rewriting
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
</Directory>

# ─── Block Access to Sensitive Files ──────────────────
<FilesMatch "^\.env">
Require all denied
</FilesMatch>

# ─── Security Headers ─────────────────────────────────
Header always set X-Frame-Options "SAMEORIGIN"
Header always set X-Content-Type-Options "nosniff"
Header always set X-XSS-Protection "1; mode=block"
Header always set Referrer-Policy "strict-origin-when-cross-origin"

# ─── Logging ──────────────────────────────────────────
ErrorLog ${APACHE_LOG_DIR}/monitron-error.log
CustomLog ${APACHE_LOG_DIR}/monitron-access.log combined

# ─── PHP Timeout for AI requests ─────────────────────
<IfModule mod_php.c>
php_value max_execution_time 120
php_value upload_max_filesize 100M
php_value post_max_size 100M
</IfModule>
</VirtualHost>

🔧 Step-by-Step Setup

1. Replace Placeholders

العنصر النائباستبدل بـ
your-domain.comYour actual domain
/var/www/monitronYour installation path
SSL certificate pathsYour actual paths

2. Enable the Site

# Enable the site
sudo a2ensite monitron.conf

# Disable the default site (optional)
sudo a2dissite 000-default.conf

# Test configuration
sudo apachectl configtest

# Restart Apache
sudo systemctl restart apache2

🔒 SSL with Let's Encrypt

sudo apt install certbot python3-certbot-apache
sudo certbot --apache -d your-domain.com
sudo certbot renew --dry-run

📝 The .htaccess File

Monitron includes a .htaccess file in the public/ directory. It handles:

  • URL rewriting (pretty URLs)
  • HTTP to HTTPS redirect
  • Security headers
  • CORS headers
تحذير

Make sure AllowOverride All is set! Without it, Apache ignores .htaccess files and you'll get 404 errors on all pages except the homepage.


🐘 Using PHP-FPM Instead of mod_php

PHP-FPM is faster than mod_php for most workloads. To use it:

# Disable mod_php
sudo a2dismod php8.3

# Enable PHP-FPM proxy
sudo a2enmod proxy_fcgi setenvif
sudo a2enconf php8.3-fpm

# Restart
sudo systemctl restart apache2

🛠️ استكشاف الأخطاء وإصلاحها

"Not Found" on all pages except homepage

mod_rewrite isn't enabled or AllowOverride isn't set:

sudo a2enmod rewrite
# And make sure AllowOverride All is in your VirtualHost
sudo systemctl restart apache2

500 Internal Server Error

Check the Apache error log:

tail -50 /var/log/apache2/monitron-error.log

Common causes:

  • Missing .htaccess file in public/
  • Wrong file permissions
  • PHP error (check storage/logs/laravel.log)