|
| 1 | +# Laravel |
| 2 | + |
| 3 | +Laravel is a powerful web application framework built with PHP. It's a great choice for building web applications and APIs. |
| 4 | + |
| 5 | +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 |
| 6 | + |
| 7 | +[](https://devbox.sh/github.com/jetpack-io/devbox/?folder=examples/stacks/laravel) |
| 8 | + |
| 9 | +## How to Run |
| 10 | + |
| 11 | +1. Install [Devbox](https://www.jetpack.io/devbox/docs/installing_devbox/) |
| 12 | + |
| 13 | +1. Create a new Laravel App by running `devbox create --template laravel`. This will create a new Laravel project in your current directory. |
| 14 | + |
| 15 | +1. Start your MariaDB and Redis services by running `devbox services up`. |
| 16 | + 1. This step will also create an empty MariaDB Data Directory and initialize your database with the default settings |
| 17 | + 2. This will also start the php-fpm service for serving your PHP project over fcgi. Learn more about [PHP-FPM](https://www.php.net/manual/en/install.fpm.php) |
| 18 | + |
| 19 | +1. Create the laravel database by running `devbox run db:create`, and then run Laravel's initial migrations using `devbox run db:migrate` |
| 20 | + |
| 21 | +1. 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` |
| 22 | + |
| 23 | +1. If you're using Laravel on Devbox Cloud, you can test the app by appending `/port/8000` to your Devbox Cloud URL |
| 24 | + |
| 25 | +1. For more details on building and developing your Laravel project, visit the [Laravel Docs](https://laravel.com/docs/10.x) |
| 26 | + |
| 27 | + |
| 28 | +## How to Recreate this Example |
| 29 | + |
| 30 | +### Creating the Laravel Project |
| 31 | + |
| 32 | +1. Create a new project with `devbox init` |
| 33 | + |
| 34 | +2. Add the packages using the command below. Installing the packages with `devbox add` will ensure that the plugins are activated: |
| 35 | + |
| 36 | + ```bash |
| 37 | + devbox add mariadb@latest, [email protected], nodejs@18, redis@latest, php81Packages.composer@latest |
| 38 | + ``` |
| 39 | + |
| 40 | +3. Run `devbox shell` to start your shell. This will also initialize your database by running `initdb` in the init hook. |
| 41 | + |
| 42 | +4. Create your laravel project by running: |
| 43 | + |
| 44 | + ```bash |
| 45 | + composer create-project laravel/laravel tmp |
| 46 | +
|
| 47 | + mv tmp/* tmp/.* . |
| 48 | + ``` |
| 49 | + |
| 50 | +### Setting up MariaDB |
| 51 | + |
| 52 | +To use MariaDB, you need to create the default Laravel database. You can do this by running the following commands in your `devbox shell`: |
| 53 | + |
| 54 | +```bash |
| 55 | +# Start the MariaDB service |
| 56 | +devbox services up mariadb -b |
| 57 | +
|
| 58 | +# Create the database |
| 59 | +mysql -u root -e "CREATE DATABASE laravel;" |
| 60 | +
|
| 61 | +# Once you're done, stop the MariaDB service |
| 62 | +devbox services stop mariadb |
| 63 | +``` |
0 commit comments