Used to get a new project started quickly
Full Laravel | Laravel + Vite |
---|---|
Recommended folder structure:
|
Recommended folder structure:
|
Note: when using Vite, it is recommended to change the NginX ports for HTTP & HTTPS to something like 8080/8443 so that your UI (through Vite) can run on port 80/443. All API calls to Laravel would then use the 8080/8443 ports
-
Download this repo as a ZIP, or create a new GitHub repository using this as a template
-
From your terminal, enter into the root folder for this repo/project (ex: "my-project")
-
Rename example.env to .env
mv example.env .env
-
Create your laravel app. Recommended to create it in a folder called "web" (for full laravel) or "api" (when also using Vite)
- Note you will need to have composer installed (
brew install composer
) and PHP (brew install php
). If you really do not want to install composer (or Brew) locally, you could execute everything from within the PHP-FPM container which has Composer installed, but will require a few extra steps for moving the contents of the created project to the root, since the root will already be mapped to "web" when you boot your container - or temporarily change the root web folder on php container using the .env file. - Full Laravel:
./my-project$ composer create-project laravel/laravel web
- Laravel + Vite:
./my-project$ composer create-project laravel/laravel api
./my-project$ yarn create vite web --template vue
you could alternatively use--template vue-ts
for typescript support
- Note you will need to have composer installed (
-
In the .env file at the root of your project, rename the COMPOSE_PROJECT_NAME to something short that makes senese for your app.
- This becomes the prefix for docker images/names and is a good thing to do to avoid reusing the same image/instance for multiple projects.
- Important especially when installing different plugins/mods/packages to the image that are specific to a project.
-
If using Laravel + Vite: In the .env file at the root of your project, update the value of
APP_CODE_PATH_HOST
to be "./api/" instead of "./web/" -
Boot your project:
docker-compose up -d
- Initial boot may take several minutes as it will need to build each image.
-
In the .env file within your web folder:
- modify the DATABASE values to match the MySQL values within your root .env file. For development, I typically use root/root for the username, pass. Database host will be "mysql" unless you renamed it within your docker-compose.
- Modify the REDIS host to be "redis" unless you named it something else within your docker-compose.
- Modify the SMTP values to match that of the Mailhog docker container. Host = mailhog; port = 1025.
- Set values for PUSHER_APP_<id/key/secret>. For local dev, these can be arbitrary values. Set the BROADCAST_DRIVER value to "pusher"
- Set the following values to "redis": SESSION_DRIVER, CACHE_DRIVER, QUEUE_CONNECTION,
-
Open another terminal tab, as you will (most likely) want to have 2 things running at once (both in the php container):
- Terminal 1:
- run
docker-compose exec php bash
- Once inside the php docker container, run:
composer install
php artisan migrate
- Use this terminal to run other commands such as
php artisan .....
- run
- Terminal 2:
- For Full Laravel:
- run
docker-compose exec php bash
- Once iniside the php docker container, run:
npm install
npm run watch
- This will keep the npm process running, watching for changes to your application and automatically recompiling. Editing certain root files (like webpack, etc) may require you to stop this command and re-run it.
- Let this terminal stay open and running in the background
- Once iniside the php docker container, run:
- run
- For Laravel + Vite:
- run
yarn dev --https
- run
- For Full Laravel:
- Terminal 1:
You can simplify some
To make the most of this, I recommend the following packages:
Note - if you are not using this, you should remove/comment the Queue container from your docker-compose file
Follow directions on the Laravel Horizon docs page.
composer require laravel/horizon
Note - if you are not using this, you should remove/comment the Websocket container from your docker-compose file
Follow directions from the Beyondcode Websockets docs page
composer require beyondcode/laravel-websocket
If using the Meili Search docker container:
composer require laravel/scout
composer require meilisearch/meilisearch-php
To keep the .env file and the example env file in sync:
composer require poseidonphp/laravel-env-sync
- Read command help for how to use this package*