A detailed Guide to self-host Twenty CRM on you local server

A detailed Guide to self-host Twenty CRM on you local server

Hello everyone! I'm back with a new blog, and I'm really excited to share something cool and amazing with you. As you already know about Twenty CRM, which I covered in my previous blog, if you haven't read it yet, please go and read that first. As I mentioned before, I really enjoy using Twenty these days. I've previously mentioned that we can self-host Twenty CRM on our local servers, so only we know about our data, keeping it safe from being exploited. Recently, you might have heard about the Internet Archive website being hacked. If that can happen, anything can happen, so why take the risk? Just self-host your own data and keep it safe. So, let's get started!

Here are some prerequisites for hosting Twenty on your local or cloud server.

  1. RAM: Ensure your environment has at least 2GB of RAM. Insufficient memory can cause processes to crash ( I’II recommend 4 GB of RAM)

  2. Docker & Docker Compose: Make sure both are installed and up-to-date.

What is Docker and why should I install it ?

So Docker is an open-source platform that automates the deployment, scaling, and management of applications using containers. A container is a lightweight, standalone, executable package that includes everything needed to run a piece of software, including the code, runtime, libraries, and system tools.

Docker enables developers to easily package applications and their dependencies into containers, which can then run consistently across different computing environments (development, testing, production, etc)

Advantages of Docker

  1. Isolation:

    • Docker containers are isolated from each other and the host system. This means you can run multiple applications with different dependencies on the same host without conflicts.
  2. Portability:

    • Docker containers can run on any machine that has Docker installed, making it easy to move applications between environments (e.g., from development to production).
  3. Scalability:

    • Docker makes it easy to scale applications up or down by creating or removing containers based on demand. This is especially useful for applications with variable workloads.
  4. Efficiency:

    • Containers are lightweight and share the host OS kernel, allowing them to start quickly and use fewer resources compared to traditional virtual machines.
  5. Version Control:

    • Docker images can be versioned, allowing you to track changes and roll back to previous versions if needed.

Simplified Deployment:

  • Docker streamlines the deployment process by packaging all dependencies in a single container. This eliminates the "it works on my machine" problem.

Step 1: Create a Directory & Set Up the Environment File

As I am using macOS for self hosting so following along would not be a problem of Linux user. so first you need to create a Directory name it whatever you want.

mkdir twenty

Now create a .env file in the working directory just copy the command and paste in the current directory

curl -o .env https://raw.githubusercontent.com/twentyhq/twenty/main/packages/twenty-docker/.env.example

Now your folder should look like this

As you can see above, this is the boilerplate of the .env file. Great, now let's move forward and Generate secret tokens. We need 4 tokens, so enter the command below 4 times in your terminal and copy all the outputs.

Run the following command four times to generate four unique random strings

openssl rand -base64 32

what does this command does?

The command openssl rand -base64 32 is used to generate a random string of 32 bytes, encoded in Base64.

Here’s what each part of the command does:

  • openssl: This is a command-line tool that provides various cryptographic functions, including generating random numbers, creating certificates, encrypting data, etc.

  • rand: This subcommand within openssl generates random data.

  • -base64: This option encodes the output in Base64, which is a way of representing binary data in an ASCII string format, making it easier to use in text files or environment variables.

  • 32: This specifies the length of the random data in bytes (32 bytes in this case). When encoded in Base64, the output string will be longer because Base64 encoding increases the size of the data by approximately 33%.

Great! Now paste the output of the command into your .env file. I can't share my output, so I hope you understand, and remember not to share yours either.

Set the Postgres Password

Update the POSTGRES_ADMIN_PASSWORD value in the .env file with a strong password.

POSTGRES_ADMIN_PASSWORD=my_strong_password

I'll use my own strong password for this, and you can use yours.

Step 2: Obtain the Docker Compose File

Now we will set up the Docker container. To do this, we need to download the docker-compose.yaml file for twenty. We can simply copy the command below, which downloads the file from the GitHub repository.

Note that you should be in the current working directory of twenty.

curl -O https://raw.githubusercontent.com/twentyhq/twenty/main/packages/twenty-docker/docker-compose.yml

Now that you have the Docker file in your folder, let's move on to the fun part. Start your Docker Desktop, and let's start the container.

Step 3: Launch the Application

You can just paste this command this will fire up the docker container from the docker-compose file.

If you want to start the containers in the background (detached mode), use the -d flag:

docker-compose up -d

else use

docker-compose up

You will see the following output on your terminal, which means the container is being created and we are good to go.

Step 4: Access the Application

Now, simply open your browser and go to localhost:3000. This is the port where your Twenty application is running, and you can log in and manage it as needed.

Below is the image as twenty running on localhost:3000 and I have created a workspace named hello and setup a data model of invoice

Configuration for extra needs

By default, Twenty runs on your local machine at port 3000. While this is perfect for development, production environments require external accessibility. The key to achieving this lies in properly configuring your SERVER_URL – a simple yet powerful setting that determines how users can access your Twenty instance.

The Three Components of SERVER_URL

Before diving into the configuration, let's break down what makes up your server URL:

  1. Protocol (http/https)

    • Choose http for basic setups without SSL

    • Opt for https when security is a priority (recommended for production)

  2. Domain or IP Address

  3. Port Number

    • Standard ports: 80 for HTTP, 443 for HTTPS

    • Custom ports when needed (e.g., 3000, 8080)

Configuration Scenarios

Direct Server Access

The simplest setup involves direct access to your Twenty instance. Add this to your .env file:

iniCopySERVER_URL=http://123.45.67.89:3000

This configuration works well for testing or internal networks, but remember that using plain HTTP isn't recommended for production environments.

Behind a Reverse Proxy

For production deployments, you'll likely use a reverse proxy like Nginx or Traefik. With SSL configured, your setup might look like:

iniCopySERVER_URL=https://twenty.yourcompany.com

This cleaner URL structure not only looks professional but also provides additional security through SSL encryption.

Security Considerations

  1. SSL Certificates

    • Always use HTTPS in production

    • Consider Let's Encrypt for free SSL certificates

    • Configure SSL termination at your reverse proxy

  2. Firewall Rules

    • Only expose necessary ports

    • Use UFW or similar tools to manage access

    • Consider implementing rate limiting

  3. Reverse Proxy Headers

    • Ensure proper header forwarding

    • Configure CORS if needed

    • Set up security headers

Making Changes Take Effect

After updating your configuration, remember to restart your Twenty instance:

bashCopydocker-compose down
docker-compose up -d

Best Practices and Common Pitfalls

  1. URL Consistency

    • Ensure your SERVER_URL matches exactly how users will access the application

    • Avoid mixing HTTP and HTTPS

    • Be consistent with www vs non-www URLs

  2. Performance Optimization

    • Consider using a CDN for static assets

    • Enable compression at the reverse proxy level

    • Monitor server resources and adjust accordingly

  3. Troubleshooting Tips

    • Check firewall rules if external access fails

    • Verify DNS settings if using a domain

    • Monitor logs for connection issues

Conclusion

Congratulations! You have successfully self-hosted Twenty on your local server or cloud. Now, you are fully in charge of your data. If you have any issues, feel free to comment below, visit Twenty’s GitHub repo, or check their troubleshooting guide. Thank you for reading this far. Please like and share the blog so others can learn about this amazing open-source app.

Did you find this article valuable?

Support K5LO7H's Blog by becoming a sponsor. Any amount is appreciated!