Server Installation

Requirements

OS

All OSes (Linux, Windows and macOS) are supported.

Environment

info

We strongly suggest you use Yarn 1.x to run & build Casdoor frontend, using NPM might cause UI styling issues, see more details at: casdoor#294

Database

Casdoor uses XORM to talk to the database. Based on Xorm Drivers Support, The current supported databases are:

  • MySQL
  • MariaDB
  • PostgreSQL
  • SQL Server
  • Oracle
  • SQLite 3
  • TiDB

Download

The source code of Casdoor is hosted at GitHub: https://github.com/casdoor/casdoor . Both the Go backend code and React frontend code are inside the single repository.

NameDescriptionLanguageSource code
FrontendWeb frontend UI for CasdoorJavaScript + Reacthttps://github.com/casdoor/casdoor/tree/master/web
BackendRESTful API backend for CasdoorGolang + Beego + XORMhttps://github.com/casdoor/casdoor

Casdoor supports Go Modules. To download the code, you can just simply clone the code via git:

  1. cd path/to/folder
  2. git clone https://github.com/casdoor/casdoor

Configuration

Casdoor can be configured via a single file: conf/app.conf, the content of which by default is:

  1. appname = casdoor
  2. httpport = 8000
  3. runmode = dev
  4. SessionOn = true
  5. copyrequestbody = true
  6. driverName = mysql
  7. dataSourceName = root:123456@tcp(localhost:3306)/
  8. dbName = casdoor
  9. redisEndpoint =
  10. defaultStorageProvider =
  11. isCloudIntranet = false
  12. authState = "casdoor"
  13. httpProxy = "127.0.0.1:10808"
  14. verificationCodeTimeout = 10
  15. initScore = 2000
  16. logPostOnly = true
  17. origin = "https://door.casbin.com"
  • appname is the application name, which currently has no practical use
  • httpport is the port that your back-end application is listening on
  • runmode is dev or prod
  • SessionOn decides whether to enable session,used by default.
  • driverName, dataSourceName and dbName are introduced before, please see Config.
  • useProxy set the proxy port, because we have google-related services, which will be restricted by the network in some areas
  • verificationCodeTimeout set the expiration time of the verification code. After the expiration, the user needs to obtain it again

Despite all the configurable fields, as a beginner, you only need to modify two items: driverName and dataSourceName based on your database. This database will be used by Casdoor to store all data, including users, organizations, applications and so on.

  • Setup database (MySQL):

    Casdoor will store its users, nodes and topics information in a MySQL database named: casdoor, will create it if not existed. The DB connection string can be specified at: https://github.com/casdoor/casdoor/blob/master/conf/app.conf

    1. driverName = mysql
    2. dataSourceName = root:123456@tcp(localhost:3306)/
    3. dbName = casdoor
  • Setup database (Postgres):

    Since we must choose a database when opening Postgres with xorm, you should prepare a database manually before running Casdoor.

    Let’s assume that you have already prepared a database called casdoor, then you should specify app.conf like this:

    1. driverName = postgres
    2. dataSourceName = "user=postgres password=xxx sslmode=disable dbname="
    3. dbName = casdoor

    Please notice: You can add Postgres parameters in dataSourceName, but please make sure that dataSourceName ends with dbname=. Or database adapter may crash when you launch Casdoor.

  • Other database…

Run

There are currently two methods to start, you can choose one according to your own situation.

Development mode

Backend

Casdoor’s Go backend runs at port 8000 by default. You can start the Go backend with the following command:

  1. go run main.go

After the server is successfully running, we can start the frontend part.

Frontend

Casdoor’s frontend is a very classic Create-React-App (CRA) project. It runs at port 7001 by default. Use the following commands to run the frontend:

  1. cd web
  2. yarn install
  3. yarn start

Visit: http://localhost:7001 in your browser. Log into Casdoor dashboard with the default global admin account: built-in/admin

  1. admin
  2. 123

Production mode

Backend

Build Casdoor Go backend code into executable and start it.

For Linux:

  1. go build
  2. ./casdoor

For Windows:

  1. go build
  2. casdoor.exe

Frontend

Build Casdoor frontend code into static resources (.html, .js, .css files):

  1. cd web
  2. yarn install
  3. yarn build

Visit: http://localhost:8000 in your browser. Log into Casdoor dashboard with the default global admin account: built-in/admin

  1. admin
  2. 123
tip

To use another port, please edit conf/app.conf and modify httpport, then restart the Go backend.

casdoor port details

In dev environment, the frontend is run by yarn run in port 7001, so if you want to go to Casdoor login page, you need set Casdoor link as http://localhost:7001.

In prod environment, the frontend files is first built by yarn build and served in port 8000, so if you want to go to Casdoor login page, you need to set Casdoor link as http://SERVER\_IP:8000 (If you are using reverse proxy, you need to set the link as your domain).

Take our official forum Casnode as an example:

Casnode uses Casdoor to handle authentication.

When we are testing Casnode in dev environment, we set the serverUrl as http://localhost:7001, so when we test signin and signup functionality using Casdoor, it will go to localhost 7001 which is the Casdoor port.

And when we put Casnode to prod environment, we set the serverUrl as https://door.casbin.com, so users can signin or signup using Casdoor.

Casnode Example