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
- Open Control Panel › Websites › Apps and click the Laravel tile (under Developer).
- Choose the Domain
example.com. Leave Folder empty: Laravel always goes in the website's main folder. - 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
- Open Software › Git. Under New repository, enter the Clone from address, a Name such as
site, and in Deploy to the folderexample.com. Click Create. - On the repository's page, click Deploy now and confirm. The files are copied (without
.git) intoweb/example.com. - Open Domains › Domains, click Manage on
example.com, change the Website folder toexample.com/publicand click Save. Onlypublic/is now served.
2. Install the packages
- Open Software › Composer.
- Set Folder with composer.json to
web/example.comand click Save folder if you changed it. - Choose composer install, leave --no-dev ticked and click Run composer install.
3. Set up the database and .env
For your own project (1b):
-
Open Databases › MySQL databases. Under Quick create, type
appand click Create. Copy the name, user and password from the message. -
In Files › File Manager, make a file
.envinweb/example.comfrom the contents of.env.example, and fill inDB_HOST=localhost,DB_DATABASE,DB_USERNAMEandDB_PASSWORD. SetAPP_ENV=production,APP_DEBUG=falseandAPP_URL. -
If the server has the web terminal, open Software › Terminal and run, in the project folder:
bashphp artisan key:generate php artisan migrate --force php artisan config:cache
4. Run the scheduler
-
Open Software › Cron jobs.
-
Under Add a cron job, choose Custom… and enter
* * * * *, or choose Every 5 minutes if your tasks don't need to run every minute. -
Enter the Command:
textcd /home/sarahbakes/web/example.com && php artisan schedule:run >/dev/null 2>&1 -
Click Add.
Tip: run
php -vin the terminal to see which PHP version thephpcommand 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)
- Open Databases › Redis cache, choose the Memory size and click Turn on Redis.
- Copy the Socket path from Connect another app.
- In
.env, setREDIS_CLIENT=phpredis,REDIS_SCHEME=unixandREDIS_PATH=<socket>, thenCACHE_STORE=redis,SESSION_DRIVER=redisorQUEUE_CONNECTION=redisas 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
.envout of the repository, so your live settings are never replaced.