Deploy a Laravel Application with Continuous Deployment on Koyeb
5 minIntroduction
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:
- A Koyeb account to deploy and run the Laravel web application
- The Koyeb CLI installed to interact with Koyeb from the command line
- A GitHub account
- PHP and Composer installed on your machine
Steps
To deploy a Laravel web application on the Koyeb serverless platform, you need to follow these three steps:
- Create a new Laravel application
- Push the Laravel application to a GitHub repository
- 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:
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:
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:
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:
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:
Add a .gitignore file
To keep only the necessary files in the repository, add this .gitignore file to exclude all unnecessary Laravel files.
Execute the following command to add and commit the changes made in your files to your repository:
Then add these changes to your remote GitHub repository for this app.
Rename the repository default branch to main executing:
Next, push your changes to the GitHub repository by running:
You are now ready to deploy your application on Koyeb.
Deploy the Laravel application on Koyeb
Go to the Koyeb control panel. On the Overview tab, click the Create Web Service button to begin:
- Choose GitHub as the deployment method.
- Select your
laravel-on-koyeb
repository from the list. - In the Environment variables section, click the Add variable button to add an
APP_KEY
variable set to the value you generated in the step above. - Choose a name for your App and Service, for example
laravel-on-koyeb
, and click Deploy.
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.
Want more PHP resources? Check out our PHP documentation and one-click PHP app to learn how to deploy a PHP application on Koyeb.
If you would like to read more Koyeb tutorials, check out out our tutorials collection. Have an idea for a tutorial you'd like us to cover? Let us know by joining the conversation over on the Koyeb community platform!