Skip to main content
This example shows how to build a simple Laravel application backed by MariaDB and Redis. It uses Devbox Plugins for all 3 Nix packages to simplify configuration Example Repo

How to Run

  1. Install Devbox
  2. Create a new Laravel App by running devbox create --template laravel. This will create a new Laravel project in your current directory.
  3. Start your MariaDB and Redis services by running devbox services up.
    1. This step will also create an empty MariaDB Data Directory and initialize your database with the default settings
    2. This will also start the php-fpm service for serving your PHP project over fcgi. Learn more about PHP-FPM
  4. Create the laravel database by running devbox run db:create, and then run Laravel’s initial migrations using devbox run db:migrate
  5. You can now start the artisan server by running devbox run serve:dev. This will start the server on port 8000, which you can access at localhost:8000
  6. If you’re using Laravel on Devbox Cloud, you can test the app by appending /port/8000 to your Devbox Cloud URL
  7. For more details on building and developing your Laravel project, visit the Laravel Docs

How to Recreate this Example

Creating the Laravel Project

  1. Create a new project with devbox init
  2. Add the packages using the command below. Installing the packages with devbox add will ensure that the plugins are activated:
    devbox add mariadb@latest, [email protected], nodejs@18, redis@latest, php81Packages.composer@latest
    

3. Run `devbox shell` to start your shell. This will also initialize your database by running
   `initdb` in the init hook.

4. Create your laravel project by running:

composer create-project laravel/laravel tmpmv tmp/* tmp/.* .

### Setting up MariaDB[​](#setting-up-mariadb "Direct link to Setting up MariaDB")

To use MariaDB, you need to create the default Laravel database. You can do this by running the
following commands in your `devbox shell`:

Start the MariaDB servicedevbox services up mariadb -b# Create the databasemysql -u root -e “CREATE DATABASE laravel;”# Once you’re done, stop the MariaDB servicedevbox services stop mariadb


[Edit this page](https://github.com/jetify-com/devbox/tree/main/docs/app/docs/devbox-examples/stacks/laravel.md)
I