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

SuperBOL: The COBOL revolution in the Cloud

COBOL, a programming language that is over 60 years old, continues to power a large proportion of the IT systems of the world's major companies, particularly in the financial and insurance sectors.
Features

Clever Cloud welcomes the first startups to the UP Programme

Clever Cloud is proud to announce the arrival of the first five startups selected to join its UP Programme, an initiative dedicated to supporting young technology companies in their growth phase.
Company

A minor update resulted in a cascade of errors: how it went wrong, what we’ve learnt

On Friday, August 2nd, 2024 Clever Cloud’s platform became very unstable, leading to downtime of varying duration and scope, for customers using services on the EU-FR-1 (PAR) region, and remote zones depending on the EU-FR-1 control plane (OVHcloud, Scaleway, and Oracle). Privates and on-premise zones weren’t impacted.
Company Engineering