How to host Laravel on Square Cloud (Octane)
How to Host Laravel Applications on Square Cloud
Hosting Laravel on Square Cloud goes beyond simply uploading code. To ensure your application handles a high volume of requests with low latency, our environment offers native support for Swoole via Laravel Octane, transforming how PHP processes information.
1. The Swoole Advantage
Traditionally, PHP starts a new process for each request, creating memory and CPU overhead. By using Swoole in our environment, the application remains in memory (bootstrapped), ready to respond instantly.
This results in:
- Request responses in milliseconds.
- Lower resource consumption of your plan.
- Native capability to handle WebSockets and asynchronous tasks.
2. The Ideal Initialization Script
On Square Cloud, you can automate the entire preparation and initialization process of the application in a single command line. This ensures that with every restart or commit, your environment is perfectly synchronized.
Start Command Example:
php artisan optimize && php artisan migrate --force && php artisan octane:start --host=0.0.0.0 --port=80 --workers=4 --task-workers=8 --server=swooleWhat does this command do?
php artisan optimize: Clears and generates route and configuration caches.php artisan migrate --force: Runs your database migrations automatically.php artisan octane:start: Starts the high-performance server on port 80, utilizing 4 processing workers and 8 workers for heavy tasks.
Before uploading: run npm run build on your machine and ship the public/build folder in the ZIP (the PHP runtime does not install npm packages), and add Octane to the project with composer require laravel/octane. Square Cloud runs composer install on its own before each start, so send composer.json and composer.lock and leave it out of the command.
3. Performance Tips
- Task Workers: In the start command, the
--task-workers=8parameter allows you to send heavy tasks (like sending emails or processing images) to the background without blocking the main user response. - Symbolic Storage: Remember to run the
php artisan storage:linkcommand if you need to serve public files from thestoragefolder. You can add this to your start script. - Caching with Redis: Use a Redis instance on Square Cloud to manage Laravel sessions and cache for even more extreme performance.
Updated on: 10/04/2026
Thank you!
