Skip to content

serversideup/spin-template-laravel-basic

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Spin Header

πŸ† Official "Laravel Basic" Template by Spin

This is the official Spin template for Laravel that helps you get up and running with:

  • Latest version of Laravel
  • SQLite

Looking for more features?

We have a "Spin Pro Laravel Template" that includes more features for Laravel Pros:

Feature Spin Basic Laravel Template Spin Pro Laravel Template
Price Free $199/once (lifetime access)
Automated Deployments with GitHub Actions ❌ βœ…
Local Development SSL ❌ βœ… (Trusted)
Tunnel Support ❌ βœ…
SMTP Trapping ❌ βœ… (Mailpit)
Vite over HTTPS ❌ βœ…
Databases SQLite βœ… MariaDB, MySQL, PostgreSQL, SQLite
Redis ❌ βœ…
Laravel Horizon ❌ βœ…
Laravel Reverb ❌ βœ…
Laravel Queues ❌ βœ…
Mailpit over HTTPS ❌ βœ…
Node Package Manager yarn yarn or npm
Support βœ… Discord, GitHub Discussions βœ… Private Community Support

If you're interested in the Pro version, you visit https://getspin.pro for more information.

Default configuration

To use this template, you must have Spin installed.

spin new laravel my-laravel-app

By default, this template is configured to work with spin deploy out of the box. If you prefer to use CI/CD to deploy your files (which is a good idea for larger teams), you'll need to make additional changes (see the "Advanced Configuration" section below).

Before running spin deploy, ensure you've complete the following:

  1. ALL steps from "Required Changes Before Using This Template" section have been completed
  2. You've customized and have a valid .spin.yml file
  3. You've customized and have a valid .spin-inventory.yml
  4. Your server is online and has been provisioned with spin provision

Once the steps above are complete, you can run spin deploy to deploy your application:

spin deploy <environment-name>

🌎 Default Development URLs

πŸ‘‰ Required Changes Before Using This Template

Caution

You need to make changes before using this template.

Create an .env.production file

By default, this template is configured to use spin deploy which defaults to the production environment. You need to create an .env.production file in the root of your project.

cp .env.example .env.production

Configure your .env.production file with the appropriate values for your production environment. Ensure APP_URL is set correctly. Spin will use the domain from that variable as the production URL by default.

Set your production URL

Almost everyone wants to run HTTPS with a valid certificate in production for free and it's totally possible to do this with Let's Encrypt. You'll need to let Let's Encrypt which domain know what domain you are using.

Warning

You must have your DNS configured correctly (with your provider like CloudFlare, NameCheap, etc) AND your server accessible to the outside world BEFORE running a deployment. When Let's Encrypt validates you own the domain name, it will attempt to connect to your server over HTTP from the outside world using the HTTP-01 challenge. If your server is not accessible during this process, they will not issue a certificate.

# File to update:
# docker-compose.prod.yml

      labels:
        - "traefik.enable=true"
        - "traefik.http.routers.my-php-app.rule=Host(`${SPIN_APP_DOMAIN}`)"

By default, if you're using spin deploy it will use the APP_URL from your .env.<environment> file to generate the SPIN_APP_DOMAIN. You can also be explicit and change ${SPIN_APP_DOMAIN} to myapp.example.com.

Set your email contact for Let's Encrypt certificates

Let's encrypt requires an email address to issue certificates. You can set this in the Traefik configuration for production.

# File to update:
# .infrastructure/conf/traefik/prod/traefik.yml

certificatesResolvers:
  letsencryptresolver:
    acme:
      email: "changeme@example.com"

Change changeme@example.com to a valid email address. This email address will be used by Let's Encrypt to send you notifications about your certificates.

Determine if you want to use the "AUTORUN" feature

By default, we have Laravel Automations configured to run with the serversideup/php Docker image.

If you do not want this behavior, you can remove the AUTORUN_ENABLED environment variable from the php service in the docker-compose.prod.yml file.

# File to update:
# docker-compose.prod.yml

  php:
    image: ${SPIN_IMAGE_DOCKERFILE}
    environment:
      - AUTORUN_ENABLED: "true" # πŸ‘ˆ Remove this line if you don't want Laravel Automations

⚑️ Initializing in an existing project

If you're using an existing project with SQLite, you will need to move your database to a volume, especially if you're deploying to production with these templates.

Background

Laravel comes with the default path of database/database.sqlite. This path is not ideal for Docker deployments, because the parent directory of this file contains other database files used by Laravel.

For Docker Swarm (what is used in production), we need to place the SQLite in a dedicated folder so we can mount a Docker Volume to ensure the data persists.

Laravel ENV Changes

To prepare the project, we automatically set the DB_DATABASE environment variable.

# Set absolute path to SQLite database from the container's perspective
DB_DATABASE=/var/www/html/.infrastructure/volume_data/sqlite/database.sqlite

NOTE: Notice how this is the ABSOLUTE path to the database file. The reason why we use /var/www/html is because that is the absolute path to the file in the eyes of the CONTAINER (not the host machine).

Development Setup For SQLite

Your project folder is mounted as /var/www/html inside the container. You simply need to ensure the .infrastructure/volume_data/sqlite/database.sqlite file exists in your project folder on your host. Move your existing database file to this location if you want to migrate your data.

Production Setup For SQLite

We automatically create a database_sqlite volume in production. This volume is mounted to /var/www/html/.infrastructure/volume_data/sqlite/ to the php service.

πŸš€ Running Laravel Specific Commands

In development, you may want to run artisan commands or composer commands. We can use spin run or spin exec to run these commands.

spin run php php artisan migrate

The above command will create a new container to run the php artisan migrate command. You can change run for exec if you'd like to run the command in an existing, running container.

spin run php composer install

The above command will create a new container to run the composer install command. This is helpful if you need to install new packages or update your composer.lock file.

If you need to attach your terminal to the container's shell, you can use spin exec:

spin exec -it php sh

This will attach your terminal to the php container's shell. If you're using an Alpine image, sh is the default shell. If you're using a Debian image, you can use bash instead of sh.

Feel free to run any commands you'd like with spin run or spin exec. The above examples should help give you patterns what you need to do.

πŸ‘¨β€πŸ”¬ Advanced configuration

If you'd like to further customize your experience, here are some helpful tips:

Trusted SSL certificates in development

We provide certificates by default. If you'd like to trust these certificates, you need to install the CA on your machine.

Download the CA Certificate:

You can create your own certificate trust if you'd like too. Just simply replace our certificates with your own.

Change the deployment image name

If you're using CI/CD (and NOT using spin deploy), you'll likely want to change the image name in the docker-compose.prod.yml file.

  php:
    image: ${SPIN_IMAGE_DOCKERFILE} # πŸ‘ˆ Change this if you're not using `spin deploy`

Set this value to the published image with your image repository.

Set the Traefik configuration MD5 hash

When running spin deploy, we automatically grab the MD5 hash value of the Traefik configuration and set it to SPIN_TRAEFIK_CONFIG_MD5_HASH. This efficiently ensures your Docker Swarm Configuration is always up to date.

Be sure to change this value or set the MD5 hash so you can continue to receive the benefits of getting the best deployment strategy when updating Docker Swarm configurations with Traefik.

configs:
  traefik:
    name: "traefik-${SPIN_TRAEFIK_CONFIG_MD5_HASH}.yml"
    file: ./.infrastructure/conf/traefik/prod/traefik.yml

Resources

  • Website overview of the product.
  • Docs for a deep-dive on how to use the product.
  • Discord for friendly support from the community and the team.
  • GitHub for source code, bug reports, and project management.
  • Get Professional Help - Get video + screen-sharing help directly from the core contributors.

Contributing

As an open-source project, we strive for transparency and collaboration in our development process. We greatly appreciate any contributions members of our community can provide. Whether you're fixing bugs, proposing features, improving documentation, or spreading awareness - your involvement strengthens the project. Please review our contribution guidelines and code of conduct to understand how we work together respectfully.

Need help getting started? Join our Discord community and we'll help you out!

Our Sponsors

All of our software is free an open to the world. None of this can be brought to you without the financial backing of our sponsors.

Sponsors

Individual Supporters

alexjustesenΒ Β GeekDougleΒ Β 

About Us

We're Dan and Jay - a two person team with a passion for open source products. We created Server Side Up to help share what we learn.

Dan Pastori
Jay Rogers


Find us at:

  • πŸ“– Blog - Get the latest guides and free courses on all things web/mobile development.
  • πŸ™‹ Community - Get friendly help from our community members.
  • πŸ€΅β€β™‚οΈ Get Professional Help - Get video + screen-sharing support from the core contributors.
  • πŸ’» GitHub - Check out our other open source projects.
  • πŸ“« Newsletter - Skip the algorithms and get quality content right to your inbox.
  • πŸ₯ Twitter - You can also follow Dan and Jay.
  • ❀️ Sponsor Us - Please consider sponsoring us so we can create more helpful resources.

Our products

If you appreciate this project, be sure to check out our other projects.

πŸ“š Books

πŸ› οΈ Software-as-a-Service

  • Bugflow: Get visual bug reports directly in GitHub, GitLab, and more.
  • SelfHost Pro: Connect Stripe or Lemonsqueezy to a private docker registry for self-hosted apps.

🌍 Open Source