# Want to setup a Skeleton/Boilerplate project quickly?
Head over to the [flightphp/skeleton](https://github.com/flightphp/skeleton) repo to get started!
# Requirements
Flight requires `PHP 7.4` or greater.
# License
Flight is released under the [MIT](http://docs.flightphp.com/license) license.
# Installation
**1\. Download the files.**
If you're using [Composer](https://getcomposer.org), you can run the following
command:
```bash
composer require flightphp/core
```
OR you can [download](https://github.com/flightphp/core/archive/master.zip)
them directly and extract them to your web directory.
**2\. Configure your webserver.**
For *Apache*, edit your `.htaccess` file with the following:
```
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php [QSA,L]
```
> **Note**: If you need to use flight in a subdirectory add the line
> `RewriteBase /subdir/` just after `RewriteEngine On`.
> **Note**: If you want to protect all server files, like a db or env file.
> Put this in your `.htaccess` file:
```
RewriteEngine On
RewriteRule ^(.*)$ index.php
```
For *Nginx*, add the following to your server declaration:
```
server {
location / {
try_files $uri $uri/ /index.php;
}
}
```
**3\. Create your `index.php` file.**
First include the framework.
```php
require 'flight/Flight.php';
```
If you're using Composer, run the autoloader instead.
```php
require 'vendor/autoload.php';
```
Then define a route and assign a function to handle the request.
```php
Flight::route('/', function () {
echo 'hello world!';
});
```
Finally, start the framework.
```php
Flight::start();
```
## Skeleton App
Additionally you could install a skeleton app. Go to [flightphp/skeleton](https://github.com/flightphp/skeleton) for instructions on how to get started!
# Routing
Routing in Flight is done by matching a URL pattern with a callback function.
You can also install a skeleton app. Go to [flightphp/skeleton](https://github.com/flightphp/skeleton) for instructions on how to get started!
```php
Flight::route('/', function () {
echo 'hello world!';
});
```
The callback can be any object that is callable. So you can use a regular function:
# Documentation
```php
function hello() {
echo 'hello world!';
}
Flight::route('/', 'hello');
```
Or a class method:
```php
class Greeting {
static function hello() {
echo 'hello world!';
}
}
Flight::route('/', [Greeting::class, 'hello']);
```
Or an object method:
```php
class Greeting {
private $name;
We have our own documentation website that is built with Flight (naturally). Learn more about the framework at [docs.flightphp.com](https://docs.flightphp.com).
function __construct() {
$this->name = 'John Doe';
}
# Community
function hello() {
echo "Hello, $this->name!";
}
}
$greeting = new Greeting;
Flight::route('/', [$greeting, 'hello']);
```
Routes are matched in the order they are defined. The first route to match a
request will be invoked.
# Configuration
You can customize certain behaviors of Flight by setting configuration values
through the `set` method.
```php
Flight::set('flight.log_errors', true);
```
The following is a list of all the available configuration settings:
- **flight.base_url** - Override the base url of the request. (default: null)
- **flight.case_sensitive** - Case sensitive matching for URLs. (default: false)
- **flight.handle_errors** - Allow Flight to handle all errors internally. (default: true)
- **flight.log_errors** - Log errors to the web server's error log file. (default: false)
Flight::lastModified(int $time) // Performs last modified HTTP caching.
Flight::json(mixed $data, int $code = 200, bool $encode = true, string $charset = 'utf8', int $option) // Sends a JSON response.
Flight::jsonp(mixed $data, string $param = 'jsonp', int $code = 200, bool $encode = true, string $charset = 'utf8', int $option) // Sends a JSONP response.
```
**Note:** PHP 7.4 is supported because at the current time of writing (2024) PHP 7.4 is the default version for some LTS Linux distributions. Forcing a move to PHP >8 would cause a lot of heartburn for those users. The framework also supports PHP >8.
Any custom methods added with `map` and `register` can also be filtered.
# License
# More detailed information
We have our own documentation website that is being run by Flight. Please check the remaining documentation on our website.
[Learn more](https://docs.flightphp.com/learn)
Flight is released under the [MIT](http://docs.flightphp.com/license) license.