How to host a Ruby on Rails application (Puma)
How to Host Ruby on Rails Applications on Square Cloud
Ruby on Rails is a powerful and highly structured full-stack framework. To deploy it into production on Square Cloud with maximum efficiency, the secret lies in separating the asset compilation stage from the web server execution.
1. Compilation and Build Preparation
Before running your application in production, Rails needs to consolidate its dependencies and compile all frontend files (CSS, JavaScript, images, and fonts). This process optimizes loading times and ensures the server does not need to process raw files on the fly.
You don't need to install the gems locally for the deploy: Square Cloud runs bundle install every time the application starts. To skip development and test gems, set BUNDLE_WITHOUT=development:test in the Environment Variables.
You can precompile the assets locally, or let the start command do it (see below):
RAILS_ENV=production bundle exec rails assets:precompileThe precompile command will generate minified files with unique hashes inside public/assets, ready to be served at high speeds.
2. Production Execution Command
With the build prepared and assets compiled, your initialization command on Square Cloud should focus exclusively on bringing up the production HTTP server (Puma) pointing to the mandatory port.
Create a squarecloud.app file (configuration file) with RUNTIME=ruby; without it the upload fails with MISSING_MAIN/INVALID_MAIN:
RUNTIME=ruby
MEMORY=1024
VERSION=recommended
DISPLAY_NAME=My Rails App
SUBDOMAIN=my-rails-app
START=rm -f tmp/pids/server.pid && bundle exec rails assets:precompile && bundle exec rails db:prepare && bundle exec rails server
You can also use bundle exec puma -C config/puma.rb -p 80 as the server command.
3. Preparing the Deployment Package (.zip)
To upload your application, create a .zip file containing the clean structure of your project.
- What to INCLUDE: The
app/,bin/,config/,db/,lib/, andpublic/folders, along with theGemfile,Gemfile.lock,Rakefile,config.ruandsquarecloud.appfiles. Leaveconfig/master.keyout of the .zip. - What to EXCLUDE:
.bundle/(Local configurations)log/andtmp/(Local log and cache files that will be recreated on the server)node_modules/(If you use Node tools for assets, the build has already generated the final output in the public folder)
4. Performance Tips and Troubleshooting
- Terminal Logs: Make sure to add the environment variable
RAILS_LOG_TO_STDOUT=truein the Square Cloud panel so you can monitor access and errors in real time via the dashboard. - Asset Error (404): If your app starts but the layout looks broken (missing CSS), ensure that the
RAILS_SERVE_STATIC_FILES=truevariable is configured in your panel, allowing Puma to serve thepublicfolder directly if you are not using a CDN. - Production Mode: Set
RAILS_MASTER_KEY(the content ofconfig/master.key) andBUNDLE_WITHOUT=development:testin the application's Environment Variables; without the master key, Rails won't start. The runtime already setsRACK_ENV=production, so Rails runs in production.
Updated on: 10/04/2026
Thank you!
