Articles on: Websites & APIs

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:

npm run build && composer install --no-interaction --prefer-dist --optimize-autoloader && php artisan optimize && php artisan migrate --force && php artisan octane:start --host=0.0.0.0 --port=80 --workers=4 --task-workers=8 --server=swoole


What does this command do?

  1. npm run build: Compiles your frontend assets.
  2. composer install...: Installs PHP dependencies, optimizing the autoloader for production.
  3. php artisan optimize: Clears and generates route and configuration caches.
  4. php artisan migrate --force: Runs your database migrations automatically.
  5. php artisan octane:start: Starts the high-performance server on port 80, utilizing 4 processing workers and 8 workers for heavy tasks.



3. Performance Tips


  • Task Workers: In the start command, the --task-workers=8 parameter 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:link command if you need to serve public files from the storage folder. 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: 06/13/2026

Was this article helpful?

Share your feedback

Cancel

Thank you!