Server Setup - Apache Virtual Host

A guide to configuring an Apache Virtual Host to work with Materia

Production ready Apache configuration


Find and replace these strings as needed

<VirtualHost *:80>
    # Redirect all traffic to HTTPS
    Redirect "/" ""

<VirtualHost *:443>
    DocumentRoot /var/www/materia/public
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

    # Setup SSL
    SSLEngine on
    SSLCertificateFile /etc/ssl/certs/materia-selfsigned.crt
    SSLCertificateKeyFile /etc/ssl/private/materia-selfsigned.key

    # SET the FUELPHP environment
    SetEnv FUEL_ENV production

    # Block PHP execution by default
    php_value engine off

    # route 404 and 403 errors to FuelPHP
    ErrorDocument 404 /index.php?/404
    ErrorDocument 403 /index.php?/403

    # Main application directory
    <Directory /var/www/materia/public>
        # Add xsendfile for faster/efficient media downloads
        XSendFile On
        XSendFilePath /var/www/materia/fuel/packages/materia/media

        # Allow the fuelphp .htaccess file to do it's thing
        AllowOverride All

        # Allow for sizable widget uploads to the admin panel
        php_value upload_max_filesize "50M"
        Require all granted

    # turn on PHP for index.php
    <FilesMatch "^index.php">
            php_value engine on

    # hide/disable PHP for every script thats not index.php
    <FilesMatch "^(?!index).*(\.php)">
        # this isn't needed, but just to make it obvious...
        php_value engine off

        Require all denied

    # Static files
    <DirectoryMatch "^/var/www/materia/public/(widget|css|js|img)/">
        # allows symlinks to support zero downtime deploy mechanisms
        Options FollowSymLinks

        # block .htaccess files
        AllowOverride None

    # Block access to all dot files and directories
    <DirectoryMatch "^\.|\/\.">
        Require all denied