One Framework a Day keeps the Boredom Away: Laravel

Welcome to this new edition of One Framework a Day keeps the Boredom Away. In this series I will show you how to deploy a particular framework on Clever Cloud every day until I want to go back to boredom. Today it's about Laravel.

In each post of this series we'll see how to deploy a particular framework on Clever Cloud. Today we are taking a look at Laravel.

If you want to tag along, make sure you have git, a Clever Cloud account and that you have installed our CLI Clever-Tools.

What is Laravel?

Laravel is a free, open-source PHP web framework, created by Taylor Otwell and intended for the development of web applications following the model–view–controller (MVC) architectural pattern.

To go a bit further the basics, I have deployed this URL shortener application called Polr. It's actualy written with Lumen, a Laravel micro-framework.

Setup

Here are the necessary steps to configure your Polr application:

  • Clone the backend: git clone https://github.com/cydrobolt/polr
  • Get in the project: cd polr
  • Create the PHP application: clever create --type php polr
  • Create the MySQL addon: clever addon create mysql-addon --plan dev polr-mysql
  • Link the database to the application: clever service link-addon polr-mysql
  • Add your domain: clever domain add mypolr.cleverapps.io
  • Copy the default configuration: cp .env.setup .env

Then you need to setup the default webroot. We don't support environment variable for this yet, so you will have to create a php.json file under a clevercloud directory:

mkdir clevercloud vim clevercloud/php.json

{
  "deploy": {
    "webroot": "/public"
  }
}

Now commit all your changes, run clever deploy than clever open. You will be taken straight to the setup wizard of Polr. Go through all the steps, yes even the database configuration, because the setup will write ot the DB at the end. It will also overwrite .env. Problem is we use immutable infrastructure so all the changes written on that file will be lost at reboot. And reboot can happen for many reasons. Best way to manage this is to use clever ssh to log on the machine and copy the content of the now changed .env file to your own version of the file.

All the fields in this file can be remove and replaced by environment variables. You can also use pre-existing variables. In my case I have configured the database part like this:

DB_HOST=$MYSQL_ADDON_HOST
DB_PORT=$MYSQL_ADDON_PORT
DB_DATABASE=$MYSQL_ADDON_DB
DB_USERNAME=$MYSQL_ADDON_USER
DB_PASSWORD=$MYSQL_ADDON_PASSWORD

Feel free to remove any fields you want to setup as an environment variable as they will be picked up automatically too.

The other option you have would have been to know exactly all the configuration variables needed, set them all, than ssh on the machine and use the artisan CLI to seed the database. Which is to me more cumbersome.

Whatever solution you choose, take a look at their installation guide. This will give you a good idea of all the things that are managed automatically by Clever Cloud 🙂

Blog

À lire également

Deploy Brinjel on Clever Cloud

Brinjel is an open-source field management software designed for market gardeners, helping them plan seasons, track harvests, and optimize agricultural production. Created by and for market gardeners, it emphasizes an intuitive interface and features tailored to real-world needs.
Company

Simplify the management of Clever Cloud services via Kubernetes with our new operator

For the past two years, we've been enabling our customers to combine the ease of deployment of Clever Cloud with an existing Kubernetes infrastructure through an operator.
Engineering

Keycloak as a Service: identity management without the complexity

Ensuring identification and access management (IAM) in an application is a challenge that is as strategic as it is complex. But beyond the initial configuration, it is the maintenance, updates and supervision of the solution that most mobilise your teams. What if you could concentrate on your applications... while a managed solution took care of the rest?
Company