Requirements and setup


Requirements

Monti has a few basic requirements:

Setup

Once the development environment is ready you can proceed with the setup.

Method 1: Step 1 - Clone repository

First you need to download the latest version of the project from GitHub and place the folder in the server root. If you use GIT you can clone the repository using the git clone command, alternatively you can download the files directly.

Terminal
git clone https://github.com/dariodelogu/monti-framework
Cloning of the master branch is NOT RECOMMENDED as it is under development and unstable

Method 1: Step 2 - Install dependencies

Once the installation is complete, you will need to install the packages and their dependencies using composer with the following command:

Terminal
cd /my/path/to/monti-framework
composer install

The "vendor" folder will be created, inside which there will be the code for all additional packages.

The code contained in the vendor folder must not be modified for any reason, any changes could be lost in case of updates (composer update). If you need to customize the code you can create a class that extends the original class of the package you want to modify

Method 2: As composer package

To install Monti as a composer package, go to the destination folder (create it if it doesn't exist), and run:

Terminal
cd my/setup/folder
composer create-project dariodelogu/monti-framework

The "monti-framework" folder will be created, and all the necessary files will be downloaded and all dependencies installed. To choose a different name for the folder, you can modify the command as follows:

Terminal
composer create-project dariodelogu/monti-framework another-name
The code contained in the vendor folder must not be modified for any reason, any changes could be lost in case of updates (composer update). If you need to customize the code you can create a class that extends the original class of the package you want to modify

Folders structure

The following is the minimum recommended project structure:

monti-framework
├── config
├── logs
├── public
└── src
├── views
└── routes.php

File Description
config Folder containing all the configuration files. For more information, see the Config section.
public Folder where you can place all your public files (images, CSS, JS, icons, etc.)
src/views Folder where your project's views are searched. For more information, see the MVC section.
src/routes.php File containing the project's route declarations. For more information, see the Routing section.

.env file

The .env file is where you can set environment variables for the framework. Variables are in the key=value format and only string values are allowed. Once setup is complete, you'll see the .env.sample file, before continuing, you'll need to rename the file to .env. When opening the file you'll see the TESTING=true variable. The TESTING variable, if set to false, hides framework and PHP error messages and related information, which is recommended for production/live environments.

Set and get environment variables

The \App\System\Env class is the tool that allows you to interact with environment variables. Env contains all the variables declared in the .env file, plus all the values of the $_SERVER superglobal variable.

// Get a value
\App\System\Env::get("VAR_NAME");
\App\System\Env::get("HTTP_REFERER"); // From $_SERVER superglobal

// Set a value
\App\System\Env::set("VAR_NAME", "some_value");

You can pass a default value as the second parameter to the Env::get() method. This value will be returned if the desired variable does not exist. If omitted, and the variable does not exist, null will be returned.

\App\System\Env::get("UNDEFINED_KEY"); // null
\App\System\Env::get("UNDEFINED_KEY", "default_value"); // "default_value"

Hosts configuration

Next you will need to create a host configuration that points to the project you just created.

Hosts configuration changes based on the HTTP server you choose to install, read the official documentation of the HTTP server you chose to find out how to create hosts configurations.

Apache2 VHost

monti.loc.conf
<VirtualHost *:80>
	ServerName monti.loc
	# Defines monti root
	DocumentRoot /path/to/monti/public
	# Document root directives
	<Directory "/path/to/monti/public">
		Options -Indexes +FollowSymLinks
		AllowOverride All
		Require all granted
	</Directory>
</VirtualHost>

You will also need to create a .htaccess file in the root/public folder, which is necessary for the routing system.

public/htaccess
Options -MultiViews -Indexes

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{SCRIPT_FILENAME} !-f
    RewriteCond %{SCRIPT_FILENAME} !-d
    RewriteCond %{SCRIPT_FILENAME} !-l
    RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>

nginx

monti.loc.conf
server {
    listen 80;
    server_name monti.loc;
    # Defines monti root
    root /path/to/monti/public;
    index index.php;

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        include fastcgi_params;
        # e.g. for linux systems
        fastcgi_pass unix:/run/php/php8.4-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    }

    location ~* \.(ico|css|js|gif|jpg|jpeg|png|svg|woff|woff2|ttf|eot|map)$ {
        try_files $uri /index.php?$query_string;
        access_log off;
    }
}

Replace "/path/to/Monti" with the actual path in your device.

DNS and hosts file (only for dev env)

As a final step you will need to register a DNS to the "monti.loc" domain.

What is a DNS?

People access information online by typing a domain into their browser. All devices on the internet connect and communicate with each other using IP addresses. The Domain Name System (DNS) is a registry in which, for each domain, there is associated the IP of the server where it is hosted. DNS translates domain names into IP addresses so that the device can reach the requested resources.

hosts file

As for the development environment, you will need one more additional step: registering the DNS in the hosts file.

The hosts file is a text document that works similar to DNS. The location of the hosts file varies depending on the operating system:

  • Windows: C:\Windows\System32\drivers\etc\hosts;
  • Mac OSX: /private/etc/hosts;
  • Linux: /etc/hosts;

You can open the hosts file with the text editor of your choice, but remember to provide administrator privileges. Once the file is open, insert the following string as last entry:

hosts
127.0.0.1 monti.loc

As explained above we have associated a domain with an IP address. Now visiting http://monti.loc in a browser you should see the welcome page.

What happens when you visit "monti.loc" is that the domain will be converted to 127.0.0.1 and Monti will respond with the project associated with that domain.

Production checklist

A short list of things worth checking before taking a Monti project live:

  • set TESTING=false in .env: as explained above, this hides PHP and framework error details from visitors, which you don't want exposed in production;
  • make sure logs/ is writable by the webserver process, since that's where Monti logs warnings and errors;
  • make sure cache/ is writable too: it's where cache/providers.php gets regenerated every time composer install or composer update runs, and it's how Monti discovers installed modules, see the Modules documentation for details;
  • on the server, run composer install --no-dev, to skip development-only dependencies;
  • run the setup() method of every installed module that needs it, at least once. See the Modules documentation for details;
  • check that config/connections.php, and any other configuration file holding credentials, contains your production values;
  • review the hosts configuration for your production domain: the Apache2/nginx examples above are meant for local development.