Skip to main content

Laravel

To use our example repositories, you must create a Sevalla account. This article includes examples of how to set up Laravel applications to deploy on Sevalla’s Application Hosting from a GitHub repository.

Laravel

Watch our video that shows the easiest way to create and deploy a Laravel app on Sevalla.

  1. Laravel requires the APP_KEY environment variable to be set. You can generate an app key yourself locally, or you can use this online Laravel key generator.
  2. In Sevalla, click Applications > Add application > select Git repository > Public repository, and complete as follows:
  3. Enter a Name, choose a Location, choose a pod size within Resources, and click Create.
  4. Once the application is created, click Environment variables > Add environment variable, in Key 1, enter APP_KEY, and in Value 1, paste the key generated from Step 1, select Available during runtime and Available during build process, and click Save.
  5. Click Deployments > Deploy now > Deploy application.

Laravel is a regular PHP-based application, so during deployment, Sevalla automatically detects the Start command for the web process and installs dependencies including PHP extensions defined in your composer.json file. The app is available as soon as the deployment finishes, and a default Jigsaw page loads at your application’s URL.

Connect a database

If you want to connect your application to a database, start by creating a database in the same data center your application is in.

  1. Add a database.
  2. Connect the database to the application by adding an internal connection and selecting the Add environment variables… checkbox. This will automatically populate the environment variables from the database.
  3. Some of the variable names (keys) Laravel uses are different from the ones automatically created in Sevalla. Edit the variable keys as needed to match the variable names defined in Laravel’s database.php file. Below are the corresponding variable names (keys) for the database types Laravel supports.

Environment variables

MySQL and PostgreSQL

Automatically Generated KeyLaravel Key
DB_HOSTDB_HOST
DB_PORTDB_PORT
DB_NAMEDB_DATABASE
DB_USERDB_USERNAME
DB_PASSWORDDB_PASSWORD
DB_CONNECTION_URLDB_URL

Redis

Automatically Generated KeyLaravel Key
DB_HOSTREDIS_HOST
DB_PORTREDIS_PORT
DB_NAMEREDIS_DB
DB_USERREDIS_USERNAME
DB_PASSWORDREDIS_PASSWORD
DB_CONNECTION_URLREDIS_URL

Laravel APP_KEY

Laravel requires the APP_KEY environment variable to be set. If this key is not set, you will see a 500 error page served by Laravel. You can generate an app key yourself locally, or you can use the online Laravel key generator. Once you have a key, you can add it as an environment variable.

PHP extensions and versions

Nixpacks and Buildpacks install PHP extensions and PHP versions based on composer.json content. The following example adds ctype, iconv, and redis extensions for PHP 8.2:

{
"require": {
"php": ">=8.2",
"ext-ctype": "*",
"ext-iconv": "*",
"ext-redis": "*"
}
}

Web server setup

Start command

The default web process is heroku-php-apache2. This example includes an .htaccess file that reroutes all requests to public/index.php for Laravel. If needed, you can change this command when adding your application (Set up your processes) or on the application’s Processes page after deployment. You can use:

heroku-php-apache2 /public

or

php artisan serve --host 0.0.0.0 --port 8080

Laravel + Filament

Watch our video that shows how to create and deploy Laravel with Filament on Sevalla.