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.
To follow and complete this guide successfully, you need:
To deploy a Laravel web application on the Koyeb serverless platform, you need to follow these three steps:
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
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
php artisan serve
Open a browser window and navigate to the
http://localhost:8000 URL. You land on the Laravel welcome page.
Generate an APP_KEY to properly secure user sessions and other encrypted data by running:
php artisan key:generate --show
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.
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
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:
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
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"
Then add these changes to your remote GitHub repository for this app.
git remote add origin firstname.lastname@example.org:YOUR_GITHUB_USERNAME/laravel-on-koyeb.git
Rename the repository default branch to main executing:
git branch -M main
Next, push your changes to the GitHub repository by running:
git push -u origin main
You are now ready to deploy your application on Koyeb.
Go to the Koyeb Control Panel and click the Create App button.
GitHubas your deployment method.
laravel-on-koyebrepository and specify the Branch. For this demo, put
APP_KEYand the value as the value you generated in the step above.
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.
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 would like to read more Koyeb tutorials, checkout 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!
Koyeb is a developer-friendly serverless platform to deploy any apps globally.Start for free
Deploy 2 services for free and enjoy our predictable pricing as you grow
Get up and running in 5 minutes