Setting Up Your First App - chsxf/mfx GitHub Wiki

Folder Structure

At this point, your repository, if empty prior to the addition of the framework, should look like this:

📁 vendor
  📄 autoload.php
  📁 chsxf
  📁 composer
  ... and other things

Adding the App Folders

App files, constituting the "application layer" of any website based on MFX, are located in their own folders. Add two folders named application and config at the root level.

Note

Your webserver should serve your website from the application folder directly. This will make other folders like vendor or config unreachable.

You should end up with this folder structure:

📁 application
📁 config
📁 vendor
  📄 autoload.php
  📁 chsxf
  📁 composer
  ... and other things

Note

The application folder can be renamed to suit your needs as you see fit.

Adding Starter Files

You will need three files to be able to start working on your website:

  • A configuration file
  • A PHP entry point file
  • A .htaccess file to setup URL rewriting with Apache

Configuration File

Create a config.php file inside the config folder and paste these lines in it:

<?php
use chsxf\MFX\Config;

Config::load([

]);

For now, we will keep the configuration file empty and add options in the following steps.

Entry Point File

Usually, PHP entry point files are named index.php. In order to obfuscate things, the default entry point file is called entrypoint.php with MFX.

Create an entrypoint.php file inside the application folder and paste these lines in it:

<?php
use chsxf\MFX\Framework;

require_once('../vendor/autoload.php');
Framework::init('../config/config.php');

Apache's .htaccess File

As stated earlier, MFX relies a lot on URL rewriting. So we have to setup Apache accordingly.

Create a .htaccess file inside the application folder and paste these lines in it:

<IfModule mod_rewrite.c>
RewriteEngine On

RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)_\d{10,}\.(js|xml|css|swf|png|jpg|gif)$ $1.$2 [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /entrypoint.php [L]
</IfModule>

DirectoryIndex entrypoint.php
Options -Indexes

This file will also prevent potential acccess to resources like your Composer files, your Twig files, or your potential README file for the website, all of which could potentially be used as important information by attackers.

Warning

The .htaccess file above is designed for setups with virtual hosts targetting the root folder directly. If your local development setup in placed in a sub-folder of your webserver (for example, http://localhost/my-website-subfolder/), you have to adapt the file as follow:

  • Replace RewriteBase / with RewriteBase /path/to/your/website/subfolder
  • Replace RewriteRule . /entrypoint.php [L] with RewriteRule . /path/to/your/website/subfolder/entrypoint.php [L]

Resulting Folder Structure

At this point, your repository should look like this:

📁 application
  📄 .htaccess
  📄 entrypoint.php
📁 config
  📄 config.php
📁 vendor
  📄 autoload.php
  📁 chsxf
  📁 composer
  ... and other things

Now try to access your website, you should get this result:

200 OK

If not, you've missed something.

Next Step

Building Your First Route

⚠️ **GitHub.com Fallback** ⚠️