-
Notifications
You must be signed in to change notification settings - Fork 0
Setting Up Your First App
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
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.
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
Create a config.php
file inside the config
folder and paste these lines in it:
<?php
use chsxf\MFX\Config;
return new Config([
]);
For now, we will keep the configuration file empty and add options in the following steps.
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');
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 +FollowSymLinks -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 /
withRewriteBase /path/to/your/website/subfolder
- Replace
RewriteRule . /entrypoint.php [L]
withRewriteRule . /path/to/your/website/subfolder/entrypoint.php [L]
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:
404 Not Found
If not, you've missed something.
Getting Started | Framework Reference | API Reference | MFX is released under the MIT license