Saltar al contenido principal

๐ŸŸ  Apache

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


๐Ÿ“‹ Requisitos Previosโ€‹

  • 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โ€‹

MarcadorReemplazar Con
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
aviso

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

๐Ÿ› ๏ธ Solucion de Problemasโ€‹

"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)