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

Clever Cloud and OCamlPro join forces to help migrate COBOL mainframe infrastructures to Cloud and Open Source

Clever Cloud and OCamlPro have teamed up to present SuperBOL to help companies migrate from the mainframe.
Company

Clever Cloud joins the Eclipse Foundation: a commitment to the future of European open source

Clever Cloud, a French provider of Platform as a Service (PaaS) hosting and deployment solutions, is proud to become a contributing member of the Eclipse Foundation, a leading not-for-profit organisation in the field of open source.
Press

Up to €100,000 in funding to adopt Hyper Open X technologies

The Hyper Open X consortium, made up of sixteen major French cloud players, has launched anambitious call for projects designed to accelerate the adoption of open source technologies for cloud and edge computing.
Company