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.
- 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. - In Sevalla, click Applications > Add application > select Git repository > Public repository, and complete as follows:
- Repository URL: https://github.com/kinsta/hello-world-laravel
- Branch: main
- Enter a Name, choose a Location, choose a pod size within Resources, and click Create.
- 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. - 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.
- Add a database.
- 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.
- 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 Key | Laravel Key |
---|---|
DB_HOST | DB_HOST |
DB_PORT | DB_PORT |
DB_NAME | DB_DATABASE |
DB_USER | DB_USERNAME |
DB_PASSWORD | DB_PASSWORD |
DB_CONNECTION_URL | DB_URL |
Redis
Automatically Generated Key | Laravel Key |
---|---|
DB_HOST | REDIS_HOST |
DB_PORT | REDIS_PORT |
DB_NAME | REDIS_DB |
DB_USER | REDIS_USERNAME |
DB_PASSWORD | REDIS_PASSWORD |
DB_CONNECTION_URL | REDIS_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.