DEV Community

Cover image for Deploy a Laravel Application with Continuous Deployment on Koyeb
Edouard Bonlieu for Koyeb

Posted on • Originally published at koyeb.com

Deploy a Laravel Application with Continuous Deployment on Koyeb

Introduction

Laravel is a popular, simple and flexible PHP application framework that is ideal for modern, full-stack web apps.

Laravel provides a great developer experience with its many built-in features like dependency injections, an expressive database abstraction layer, queues and scheduled jobs, unit and integration testing, and more.

In this guide, we create a basic Laravel application, push it to a GitHub repository, and deploy it on the Koyeb Serverless Platform using git-driven deployment which allows you to push your code without having to take care of the build, deployment, and run process. Koyeb handles all this for you.

By deploying your Laravel application on Koyeb, you benefit from the platform's built-in autoscaling, autohealing, TLS encryption, global load balancing across our edge network, service discovery, and more.

If you want to learn how to Dockerize and Deploy a Laravel Application to Production, make sure to check out the linked guide.

Requirements

To follow and complete this guide successfully, you need:

Steps

To deploy a Laravel web application on the Koyeb serverless platform, you need to follow these three steps:

  1. Create a new Laravel application
  2. Push the Laravel application to a GitHub repository
  3. Deploy the Laravel application on Koyeb

Create a new Laravel application

To get started, we will create a new Laravel project using Composer, a PHP package manager. In your terminal, run the following command:

composer create-project --prefer-dist laravel/laravel laravel-on-koyeb
Enter fullscreen mode Exit fullscreen mode

This command will create a new Laravel application in the laravel-on-koyeb directory and install all the dependencies required by the app to run properly.

You can launch the application in development mode by running the following command in your terminal from the laravel-on-koyeb directory:

php artisan serve
Enter fullscreen mode Exit fullscreen mode

Open a browser window and navigate to the http://localhost:8000 URL. You land on the Laravel welcome page.

Generate a key for Laravel's encryption services

Generate an APP_KEY to properly secure user sessions and other encrypted data by running:

php artisan key:generate --show
Enter fullscreen mode Exit fullscreen mode

Save this value in a safe place. We will pass it to Koyeb as an ENV_VAR when we deploy the Laravel app on the platform later.

Add a Procfile

A Procfile tells Koyeb how to run your application. Create a Profile in your application's root directory by executing:

echo "web: vendor/bin/heroku-php-apache2 public/" > Procfile
Enter fullscreen mode Exit fullscreen mode

Push the Laravel application to a GitHub Repository

Now that we have created our Laravel application, we will create a git directory to store it. Return to your laravel-on-koyeb directory and initialize a new git directory for your Laravel project:

git init
Enter fullscreen mode Exit fullscreen mode

Add a .gitignore file

To keep only the necessary files in the repository, add this .gitignore file to exclude all unnecessary Laravel files.

curl https://raw.githubusercontent.com/github/gitignore/master/Laravel.gitignore > .gitignore
Enter fullscreen mode Exit fullscreen mode

Execute the following command to add and commit the changes made in your files to your repository:

git add .
git commit -m "Laravel app initial commit"
Enter fullscreen mode Exit fullscreen mode

Then add these changes to your remote GitHub repository for this app.

git remote add origin git@github.com:YOUR_GITHUB_USERNAME/laravel-on-koyeb.git
Enter fullscreen mode Exit fullscreen mode

Rename the repository default branch to main executing:

git branch -M main
Enter fullscreen mode Exit fullscreen mode

Next, push your changes to the GitHub repository by running:

git push -u origin main
Enter fullscreen mode Exit fullscreen mode

You are now ready to deploy your application on Koyeb.

Deploy the Laravel application on Koyeb

Go to the Koyeb Control Panel and click the Create App button.

  1. On the App Creation form, select GitHub as your deployment method.
  2. Under Repository, select your laravel-on-koyeb repository and specify the Branch. For this demo, put main.
  3. Thanks to your Procfile, there is no need to specify a Run command. Since this is a basic app, you can use the default settings for container size, regions, horizontal scaling, and port.
  4. Add an environment variable Secret with the key as APP_KEY and the value as the value you generated in the step above.
  5. Finally, give your App a name, i.e laravel-on-koyeb, and click Create App.

You land on the deployment page of your service where you can follow the progress of your Laravel application's deployment. Koyeb is building and deploying your application. Once the build and deployment are completed, you can access your application by clicking the App URL ending with koyeb.app in the Koyeb control panel.

If you want to learn about how Koyeb automatically builds your Laravel applications from git, make sure to read our how we build from git documentation.

Your Laravel application is now running on Koyeb and benefits from native autoscaling, automatic HTTPS (SSL), auto-healing, and global load-balancing across our edge network.

Conclusion

In this guide, you learned how to deploy a Laravel application on Koyeb and benefit from its built-in continuous deployment pipeline. Each change you push to your repository will automatically trigger a new build and deployment on the Koyeb Serverless Platform.

Your changes then go live as soon as the deployment passes all necessary health checks. In case of a failure during one of your deployments, we ensure to keep the latest working deployment active so your application is always up and running.

If you have any questions or suggestions to improve this guide, feel free to reach out to us on Slack.

Top comments (0)