> ## Documentation Index
> Fetch the complete documentation index at: https://developer.upsun.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Create a basic PHP app with a front controller

> Start with a basic PHP app with a front controller for dynamic requests.

To handle dynamic requests to your PHP app, you might want to use a [front controller](https://en.wikipedia.org/wiki/Front_controller).
The following example shows how for such an app you might start defining [your web server](https://developer.upsun.com/docs/configure-apps/image-properties/web.md).

## Define a document root

Start by defining your document root (where all your publicly visible pages are).


&#x20;   applications:
&#x20;     myapp:
&#x20;       type: 'php:\{\{version:php:latest}}'
&#x20;       source:
&#x20;         root: "/"
&#x20;       web:
&#x20;         locations:
&#x20;           '/':
&#x20;             root: 'public'
&#x20;&#x20;

## Define a front controller

Define where all requests that don't match a file in the document root are sent.


&#x20;   applications:
&#x20;     myapp:
&#x20;       type: 'php:\{\{version:php:latest}}'
&#x20;       source:
&#x20;         root: "/"
&#x20;       web:
&#x20;         locations:
&#x20;           '/':
&#x20;             root: 'public'
&#x20;             passthru: '/index.php'
&#x20;             index:
&#x20;               \- index.php
&#x20;&#x20;

In this case, `/index.php` acts as a front controller and handles dynamic requests.

Because it handles dynamic requests, you want to ensure that scripts are enabled
and responses aren't cached.


&#x20;   applications:
&#x20;     myapp:
&#x20;       type: 'php:\{\{version:php:latest}}'
&#x20;       source:
&#x20;         root: "/"
&#x20;       web:
&#x20;         locations:
&#x20;           '/':
&#x20;             ...
&#x20;             scripts: true
&#x20;             \# No caching for static files.
&#x20;             \# (Dynamic pages use whatever cache headers are generated by the program.)
&#x20;             expires: -1
&#x20;&#x20;

## Define rules

You might want to define specific rules for the location.
For example, you might want to allow all kinds of files except mp4 files.


&#x20;   applications:
&#x20;     myapp:
&#x20;       type: 'php:\{\{version:php:latest}}'
&#x20;       source:
&#x20;         root: "/"
&#x20;       web:
&#x20;         locations:
&#x20;           '/':
&#x20;             ...
&#x20;             \# Allow all file types generally
&#x20;             allow: true
&#x20;             rules:
&#x20;               \# Disallow .mp4 files specifically.
&#x20;               \\.mp4\$:
&#x20;                 allow: false
&#x20;&#x20;

## Set different rules for specific locations

You might want to set specific rules for specific locations.
For example, you might have files in your `/public/images` directory that are served at `/images`.
You could define a specific cache time for them and limit them to only static image files.


&#x20;   applications:
&#x20;     myapp:
&#x20;       type: 'php:\{\{version:php:latest}}'
&#x20;       source:
&#x20;         root: "/"
&#x20;       web:
&#x20;         locations:
&#x20;           '/':
&#x20;               ...
&#x20;           \# Set a 5 min expiration time for static files in this location.
&#x20;           \# Missing files are sent to front controller
&#x20;           \# through the '/' location above.
&#x20;           '/images':
&#x20;             expires: 300
&#x20;             passthru: true
&#x20;             \# Do not execute PHP scripts from this location and do not
&#x20;             \# deliver their source code (for enhanced security).
&#x20;             scripts: false
&#x20;             allow: false
&#x20;             rules:
&#x20;               \# Only allow static image files in this location
&#x20;               '\\.(jpe?g|png|gif|svgz?|ico|bmp)\$':
&#x20;                 allow: true
&#x20;&#x20;

## Complete example


&#x20;   applications:
&#x20;     myapp:
&#x20;       type: 'php:\{\{version:php:latest}}'
&#x20;       source:
&#x20;         root: "/"
&#x20;       web:
&#x20;         locations:
&#x20;           '/':
&#x20;             root: 'public'
&#x20;             passthru: '/index.php'
&#x20;             index:
&#x20;               \- index.php
&#x20;             scripts: true
&#x20;             \# No caching for static files.
&#x20;             \# (Dynamic pages use whatever cache headers are generated by the program.)
&#x20;             expires: -1
&#x20;             \# Allow all file types generally
&#x20;             allow: true
&#x20;             rules:
&#x20;               \# Disallow .mp4 files specifically.
&#x20;               \\.mp4\$:
&#x20;                 allow: false
&#x20;           \# Set a 5 min expiration time for static files in this location.
&#x20;           \# Missing files are sent to front controller
&#x20;           \# through the '/' location above.
&#x20;           '/images':
&#x20;             expires: 300
&#x20;             passthru: true
&#x20;             \# Do not execute PHP scripts from this location and do not
&#x20;             \# deliver their source code (for enhanced security).
&#x20;             scripts: false
&#x20;             allow: false
&#x20;             rules:
&#x20;               \# Only allow static image files in this location
&#x20;               '\\.(jpe?g|png|gif|svgz?|ico|bmp)\$':
&#x20;                 allow: true
&#x20;&#x20;


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.