How to Deploy a Rails Project to China?
Tags: ruby, rails, framework, china
Published: 2021-03-01 20:13:34

---
canonical_url: https://www.21cloudbox.com/solutions/how-to-deploy-ruby-rails-in-produciton-server.html
---
# What is Rails?
Rails is a web framework developed based on the Ruby language. It is well-received by [startups around the world](https://stackshare.io/rails).  With its perfect functions and ease of use it is a favorite of full stack engineers.

21YunBox provides a very simple Rails project deployment method like Heroku or Netlfiy. You can deploy with 21YunBox by using the **Ruby** runtime environment.

# How to deploy Rails Project to Server
1. Register to become a [21YunBox member](https://www.21yunbox.com/u/signup/)
2. Create a [PostgreSQL database](https://launch-in-china.21yunbox.com/solutions/how-to-create-a-postgresql-database.html)
2. In Gitee Fork [Rails 6 start template](https://gitee.com/eryiyunbox-examples/rails6-starter)
3. Create a **Cloud Service** on 21YunBox, and allow 21YunBox to access your code base
4. Create with the following configuration

**Environment**
```bash
Ruby
```

**Build command**

Create an `eryi_build.sh` file in the root directory of rails with the following content,
Then during the build process, execute:
```bash
./eryi_build.sh
```

```bash
# eryi_build.sh command executed
bundle install
bundle exec rake assets:precompile
bundle exec rake assets:clean
bundle exec rake db:migrate
```

**Start command**:
```bash
bundle exec puma -C config/puma.rb
```

Click **Advanced Configuration** to configure environment variables:

| KEY                          | VALUE                                                |
| :---------------------------:| :---------------------------------------------------:|
| **RAILS_ENV**                | `production`                                         |
| **PORT**                     | `10000`, 21YunBox default reads port 10000           |
| **DATABASE_URL**             | In **Cloud Database**, click **Database URL** to get |
| **RAILS_SERVE_STATIC_FILES** | `true`                                               |
| **RAILS_MASTER_KEY**         | Generated by `bin/rails credentials:edit`            |

In seconds, your rails service can be accessed at `app_id.21yunbox.com`.

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/oz6t9bmn6erag7mhevfv.png) *Screenshot of successful deployment of Rails startup template*

# Why Choose 21YunBox?

> 21YunBox is a Cloud Service platform based out of Beijing. Our services enable your team to be more effective in leveraging the growing opportunity within China by hosting your sites at blazing speeds with an operational and maintenance free, and low code solution.
>
> 21YunBox provides an easy and budget friendly, end-to-end web platform deployment service for all applications from small teams to large enterprises.
We also offer [full support in obtaining your ICP license]({% post_url 2021-02-12-how-to-get-an-icp %}){:target="_blank"} allowing you to legally host online content inside of Mainland China.


To learn about the differences between 21YunBox and these foreign (outside of China) cloud service platforms, please refer to:

* [21YunBox vs Heroku](https://launch-in-china.21yunbox.com/solutions/how-to-speed-up-heroku-in-china.html)
* [21YunBox vs Netlify](https://launch-in-china.21yunbox.com/blog/solutions/alternatives-to-netlify-in-china.html)
* [21YunBox vs Vercel](https://launch-in-china.21yunbox.com/solutions/how-to-speed-up-vercel-in-china.html)
* [21YunBox vs Gatsby Cloud](https://launch-in-china.21yunbox.com/solutions/how-to-speed-up-gatsby-cloud-in-china.html)
* [21YunBox vs Github Pages](https://launch-in-china.21yunbox.com/solutions/how-to-speed-up-github-pages-in-china.html)
* [21YunBox vs Surge.sh](https://launch-in-china.21yunbox.com/solutions/how-to-speed-up-surgesh-in-china.html)
* [Compare in terms of function and price: 21YunBox vs Heroku, Netlify, Vercel](https://www.21yunbox.com/compare-others/)


<br>
*This article's content originated [here](https://launch-in-china.21yunbox.com/solutions/how-to-deploy-ruby-rails-in-produciton-server.html)*

*For additional detail and future modifications, refer the original post.*