Skip to main content

Running laravel apps

Overview​

This guide explains how to run Laravel apps on Cloudron using the LAMP stack.

Install LAMP​

First, install the LAMP app on Cloudron.

Increase memory limit​

Increase the memory limit of the LAMP app to 1GB to ensure Composer runs reliably.

Create laravel project​

Open a Web Terminal and create a Laravel app using Composer:

  1. Switch to www-data user (the web server runs as this user).
  2. Change to the /app/data directory.
  3. Use Composer to create an empty Laravel project:
root@7c29d3b7-b93d-4c75-932e-c771a7383e39:/app/code# su - www-data
www-data@7c29d3b7-b93d-4c75-932e-c771a7383e39:~$ cd /app/data
www-data@7c29d3b7-b93d-4c75-932e-c771a7383e39:~$ composer create-project laravel/laravel my-project
Creating a "laravel/laravel" project at "./my-project"
Installing laravel/laravel (v8.5.18)
- Installing laravel/laravel (v8.5.18): Downloading (100%)
Created project in /app/data/my-project
> @php -r "file_exists('.env') || copy('.env.example', '.env');"
Loading composer repositories with package information
Warning from https://repo.packagist.org: You are using an outdated version of Composer. Composer 2 is now available and you should upgrade. See https://getcomposer.org/2
Updating dependencies (including require-dev)
Package operations: 104 installs, 0 updates, 0 removals
- Installing voku/portable-ascii (1.5.6): Downloading (100%)
- Installing symfony/polyfill-php80 (v1.22.1): Downloading (100%)
- Installing symfony/polyfill-mbstring (v1.22.1): Downloading (100%)
- Installing symfony/polyfill-ctype (v1.22.1): Downloading (100%)
- Installing phpoption/phpoption (1.7.5): Downloading (100%)
....
> @php artisan key:generate --ansi
Application key set successfully.

Configure Apache​

By default, Apache serves /app/data/public. Laravel's public directory is /app/data/my-project/public.

Configure Apache using the File Manager to edit /app/data/apache/app.conf. Restart the app after saving:

ServerName %{HTTP_HOST}

<VirtualHost *:80>
DocumentRoot /app/data/my-project/public

LogFormat "%{X-Forwarded-For}i %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" proxy
CustomLog "|/bin/cat" proxy
ErrorLog "|/bin/cat"

<Directory /app/data/my-project/public>
Options +FollowSymLinks
AllowOverride All
Require all granted
</Directory>

# Do not remove this include. It's required for your app to see the Real IP
Include "/app/code/apache/rpaf.conf"
# This line can be commented out, if you do no require PHPMyAdmin Access
Include "/app/code/apache/phpmyadmin.conf"

</VirtualHost>

After restarting, the default Laravel page appears:

Lamp Laravel

Configure queue worker​

Configure the Laravel Queue worker by adding the following line to /app/data/run.sh and restarting the app:

sudo -u www-data /usr/bin/php /app/data/my-project/artisan queue:work --queue=high,standard,low --sleep=3 --tries=3 &

Cron jobs​

Laravel uses a scheduler for scheduled tasks. Add the following job to the crontab as described in the cron documentation:

* * * * * cd /app/data/my-project/ && sudo -u www-data /usr/bin/php /app/data/my-project/artisan schedule:run