Laravel on Section
Learn how to run a default Laravel app at the edge for low latency and high availability. You can use our repo as a template, or perform the steps yourself using the Kubernetes dashboard or kubectl commands.
Option 1 - Copy Our GitHub Repo
- Make a new repo from our template: in your browser visit https://github.com/section/laravel-template and select
Use this template(don't clone, don't fork, but use the template). Choose yourself as an owner, give it a name of your choice, and make it be Public (not Private).
- In your new GitHub repo, under Settings > Secrets > Actions, use
New repository secretto add these two:
- Make a simple change to the HTML text in
resources/views/welcome.blade.phpand watch your changes go live.
Every time you push to the repo your project will be built and deployed to Section automatically using GitHub Actions.
Option 2 - Step by Step
Following are step-by-step instructions to deploy a default Laravel app to the edge on Section. We'll Dockerize it, push it to GitHub Packages, and deploy it on Section.
Create the Laravel App
Create a Laravel app via the Composer
composer create-project laravel/laravel laravel
After the Laravel app has been created, test it locally using the Laravel's Artisan CLI
php artisan serve
Access it by running
curl http://localhost:8000 in your terminal or by visiting
http://localhost:8000 in your browser. You should get the default Laravel welcome page.
Let's build the container image that we'll deploy to Section. First, make a
Dockerfile in your directory with the following content.
COPY . .
RUN composer install
CMD php artisan serve --host=0.0.0.0
.dockerignore file from the
cp .gitignore .dockerignore
Build and tag the Docker image.
docker build . -t ghcr.io/YOUR_GITHUB_USERNAME/laravel:main
Push it to GitHub Packages. This makes it available to Section.
docker push ghcr.io/YOUR_GITHUB_USERNAME/laravel:main
Be sure to make it public. To see your packages and make this change, visit
Next, create a Section deployment for the Laravel app with a
laravel-deployment.yaml file, substituting
YOUR_GITHUB_USERNAME and the environment variables accordingly. This will direct Section to distribute the container you've pushed to GitHub Packages.
- name: laravel
- containerPort: 80
- name: APP_NAME
- name: APP_ENV
- name: APP_KEY
- name: APP_DEBUG
- name: APP_URL
- name: LOG_CHANNEL
- name: LOG_DEPRECATIONS_CHANNEL
- name: LOG_LEVEL
- name: BROADCAST_DRIVER
- name: CACHE_DRIVER
- name: FILESYSTEM_DISK
- name: QUEUE_CONNECTION
- name: SESSION_DRIVER
- name: SESSION_LIFETIME
- name: MAIL_MAILER
- name: MAIL_HOST
- name: MAIL_PORT
- name: MAIL_USERNAME
- name: MAIL_PASSWORD
- name: MAIL_ENCRYPTION
- name: MAIL_FROM_ADDRESS
- name: MAIL_FROM_NAME
For a production Laravel app, use Kubernetes Secrets as the values for private environment variables.
Expose it on the internet, mapping the container's port
- name: 80-8080
See the pods running on Section's network with either the Kubernetes dashboard or
kubectl get pods -o wide. The
-o wide switch shows where your app is running according to the default AEE location optimization strategy. Your app will be optimally deployed according to traffic. In lieu of significant traffic, your deployment will be made to default locations.
See What You've Built
See the Laravel app you've built by visiting the
YOUR.DOMAIN.COM according to your DNS and HTTPS configuration.