Within a single project, you can have one or more apps and each app can have multiple instances.
Instances are where the same code can be run with different configurations,
such as one for external communication and one for background processes.
Apps and instances use similar properties, with minor differences depending on the image type that you choose:
Not sure which image type to use? See choosing an image type.
A minimal application
To create a very basic app (for this example, using a single-runtime image), you need a few things:
- A unique name not shared by any other app in the project.
- The runtime
type defining what language it uses.
- A definition of how to handle requests from the outside
web.
The following example shows such a basic setup for Node.js:
Use multiple apps
You might have multiple apps you want to run from a single Git repository,
such as a RESTful web service and a front-end or a main website and a blog.
In such cases, you configure each app separately and define the relationships among them.
See the various ways to set up a multi-app project.
Connect to services
If you want to use one of the databases or other services Upsun provides,
set it up by following these steps:
- Configure the service based on the documentation for that service.
- Use the information from that service inside your app’s
relationships definition
to configure how your app communicates with the service.
Control the build and deploy process
Your app generally needs to undergo some steps to be turned from the code in your Git repository into a running app.
If you’re running a PHP or Node.js app, this starts with the build flavor,
which runs a default set of tasks.
Then any global dependencies can be installed.
Once these optional tasks are done, you can run hooks at various points in the process.
Hooks are places for your custom scripts to control how your app is built and deployed.
Once your app is built, it needs a defined way to communicate with the outside world.
Define its behavior with a web instance.
There you can set what command runs every time your app is restarted,
how dynamic requests are handled, and how to respond with static files.
Response compression
Response compression reduces payload sizes and generally increases your app’s response times.
Dynamic responses generated by your app aren’t compressed because of a general security issue.
While your app can compress its own response,
doing so when the response includes any user-specific information, including a session cookie,
opens up an attack vector over SSL/TLS connections.
For that reason, you generally shouldn’t compress generated responses.
Requests for static files that are served directly by Upsun are compressed automatically
using either gzip or Brotli compression if:
- The request headers for the file support gzip or Brotli compression.
- The file is served directly from disk by Upsun and not passed through your application.
- The file would be served with a cache expiration time in the future.
- The file type is one of: HTML, JavaScript, JSON, PDF, PostScript, SVG, CSS, CSV, plain text, or XML.
Also, if there is a request for a file and another file exists with the same name plus a .gz or .br extension,
the compressed file is served regardless of the original file type.
So a request for styles.css that accepts a gzipped file (according to the request headers)
automatically returns a styles.css.gz file if it exists.
This approach supports any file type and offers some CPU optimization, especially if the cache lifetime is short.
Comprehensive example
PHP specifics
Unlike other runtimes, most PHP applications do not have a start command. There is a daemon running configured to work automatically with the web server. More often than not there will be a single entry-point a “front-controller”. In the case of PHP the passthru property is a string with the location of the front-controller rather than a boolean.
The following example shows a setup for a PHP app with comments to explain the settings.