Laravel
Laravel is a powerful web application framework built with PHP. It's a great choice for building web applications and APIs.
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
How to Run
-
Install Devbox
-
Create a new Laravel App by running
devbox create --template laravel
. This will create a new Laravel project in your current directory. -
Start your MariaDB and Redis services by running
devbox services up
.- This step will also create an empty MariaDB Data Directory and initialize your database with the default settings
- This will also start the php-fpm service for serving your PHP project over fcgi. Learn more about PHP-FPM
-
Create the laravel database by running
devbox run db:create
, and then run Laravel's initial migrations usingdevbox run db:migrate
-
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 atlocalhost:8000
-
If you're using Laravel on Devbox Cloud, you can test the app by appending
/port/8000
to your Devbox Cloud URL -
For more details on building and developing your Laravel project, visit the Laravel Docs
How to Recreate this Example
Creating the Laravel Project
-
Create a new project with
devbox init
-
Add the packages using the command below. Installing the packages with
devbox add
will ensure that the plugins are activated:devbox add mariadb@latest, php@8.1, nodejs@18, redis@latest, php81Packages.composer@latest
-
Run
devbox shell
to start your shell. This will also initialize your database by runninginitdb
in the init hook. -
Create your laravel project by running:
composer create-project laravel/laravel tmp
mv tmp/* tmp/.* .
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 service
devbox services up mariadb -b
# Create the database
mysql -u root -e "CREATE DATABASE laravel;"
# Once you're done, stop the MariaDB service
devbox services stop mariadb