HF PanelDocsv1.0.0

Run a Laravel app

Create a new Laravel project or deploy your own from Git, serve its public folder, connect the database, and add the scheduler, queues and Redis.

This tutorial runs a Laravel app on example.com: either a brand-new project from the App installer, or your own code from a Git repository. You then set up the database, the scheduler and Redis.

You need: a hosting account with example.com added, its website folder empty (apart from the placeholder page), and a PHP version Laravel supports for that website under Software › PHP settings.

1a. Start a new project

  1. Open Control Panel › Websites › Apps and click the Laravel tile (under Developer).
  2. Choose the Domain example.com. Leave Folder empty: Laravel always goes in the website's main folder.
  3. Click Install Laravel.

A new project is created with Composer, a database is made for it and its details are already in the project's .env file. The public/ folder becomes the website's root, so the rest of the project is never served. Go to step 3.

1b. Or deploy your own project from Git

  1. Open Software › Git. Under New repository, enter the Clone from address, a Name such as site, and in Deploy to the folder example.com. Click Create.
  2. On the repository's page, click Deploy now and confirm. The files are copied (without .git) into web/example.com.
  3. Open Domains › Domains, click Manage on example.com, change the Website folder to example.com/public and click Save. Only public/ is now served.

2. Install the packages

  1. Open Software › Composer.
  2. Set Folder with composer.json to web/example.com and click Save folder if you changed it.
  3. Choose composer install, leave --no-dev ticked and click Run composer install.

3. Set up the database and .env

For your own project (1b):

  1. Open Databases › MySQL databases. Under Quick create, type app and click Create. Copy the name, user and password from the message.

  2. In Files › File Manager, make a file .env in web/example.com from the contents of .env.example, and fill in DB_HOST=localhost, DB_DATABASE, DB_USERNAME and DB_PASSWORD. Set APP_ENV=production, APP_DEBUG=false and APP_URL.

  3. If the server has the web terminal, open Software › Terminal and run, in the project folder:

    bash
    php artisan key:generate
    php artisan migrate --force
    php artisan config:cache
    

4. Run the scheduler

  1. Open Software › Cron jobs.

  2. Under Add a cron job, choose Custom… and enter * * * * *, or choose Every 5 minutes if your tasks don't need to run every minute.

  3. Enter the Command:

    text
    cd /home/sarahbakes/web/example.com && php artisan schedule:run >/dev/null 2>&1
    
  4. Click Add.

Tip: run php -v in the terminal to see which PHP version the php command runs. If it isn't the version your website uses, ask your hosting provider for the path of the right one.

5. Use Redis for cache, sessions and queues (optional)

  1. Open Databases › Redis cache, choose the Memory size and click Turn on Redis.
  2. Copy the Socket path from Connect another app.
  3. In .env, set REDIS_CLIENT=phpredis, REDIS_SCHEME=unix and REDIS_PATH=<socket>, then CACHE_STORE=redis, SESSION_DRIVER=redis or QUEUE_CONNECTION=redis as you need.

Run queued jobs with a cron job such as php artisan queue:work --stop-when-empty every minute.

Note: if your hosting provider uses the Strict setting for PHP functions, process control functions are switched off, which some queue workers need. Ask them if workers fail.

6. Get SSL and test

Check Domains › SSL/TLS for a certificate, then open https://example.com. Errors go to storage/logs in the project and to Websites › Logs.

7. Ship updates

For 1b: on Software › Git, click Pull updates, then Deploy now. Run composer install again when composer.lock changed, and php artisan migrate --force in the terminal when there are new migrations.

Important: deploying overwrites files with the same name. Keep .env out of the repository, so your live settings are never replaced.