Install CppCMS on FreeBSD

CppCMS C++ web application server

Install, configure, and maintain the fast and high-performance CppCMS C++ web application server on FreeBSD. A step-by-step article shows how to install and configure CppCMS (application server) with Lighttpd (web server) to work together using the FastCGI protocol.

Topics covered:
  • 1.1Install CppCMS
    • 1.1.1Download CppCMS
    • 1.1.2CMake configuration
    • 1.1.3Build CppCMS
    • 1.1.4Install CppCMS
    • 1.1.5Locate CppCMS
  • 1.2CppCMS configuration
    • 1.2.1Application directory
    • 1.2.2Application configuration
  • 1.3Lighttpd configuration

Buy this service

The service includes a CMake build of the latest stable version of CppCMS from source code, installation, and setup of a CppCMS web application server on only one FreeBSD server. The customer must provide remote SSH access to the FreeBSD VPS or cloud server.

Product name:
Install CppCMS on FreeBSD
Product ID:
GWINC-SE-D3C9I7
Price*:
US $69.95 — Buy Now

*GST extra, please add 18% GST to the above price. GST is not applicable for orders outside India. International payments are accepted only through PayPal.

Affiliate links

Setting up a CppCMS C++ web application server requires a VPS with root access. For managed VPS hosting, try Cloudways managed VPS. Use our affiliate links to purchase a VPS or cloud server from third-party vendors. The affiliate commissions we earn facilitate free website access for everyone.

The affiliate links are listed in alphabetical order without any favor. Users are encouraged to refer to the Global Webdynamics LLP Terms of Service governing the Third-party vendors.

1.1Install CppCMS

To try out CppCMS, you may install CppCMS using the FreeBSD package manager. But, if the aim is to run the CppCMS C++ web application server on the production server, it is a best practice to build CppCMS from source code using custom build configuration options.

For installation with custom configurations, build the CppCMS C++ web application server from the source code. The article covers the CppCMS installation by using CMake build only.

1.1.1Download CppCMS

Create a build directory ( /gwinc/build/cppcms ) structure under the user's home directory ( /home/freebsd ). You may choose any build directory structure as per your naming convention.

Terminal ~ 1.1-1
$ mkdir -p /home/freebsd/gwinc/build/cppcms
$ cd /home/freebsd/gwinc/build/cppcms

Download the CppCMS source code from GitHub using the wget network downloader utility and extract the zip file using tar command.

Terminal ~ 1.1-2
$ wget https://github.com/artyom-beilis/cppcms/archive/refs/heads/1.2_updates.zip
$ tar -xzf 1.2_updates.zip

1.1.2CMake configuration

Make modifications to the CMake file as per requirements. Set or update CMake variables if required. Edit the CMake file ( CMakeLists.txt ) and set the compiler options to clang and clang++.

Terminal ~ 1.1-3
$ nano -w -c /home/freebsd/gwinc/build/cppcms/cppcms-1.2_updates/CMakeLists.txt
cmake_minimum_required(VERSION 2.6)
...
set(CMAKE_C_COMPILER "clang")
set(CMAKE_CXX_COMPILER "clang++")
...

Run CMake configuration with the custom build option ( -DDISABLE_ICONV=ON ) that will disable the usage of the iconv library and instead use the ICU Unicode library. For more build options, consult CppCMS documentation.

Terminal ~ 1.1-4
$ cd /home/freebsd/gwinc/build/cppcms/cppcms-1.2_updates
$ mkdir build
$ cd build
$ cmake -DDISABLE_ICONV=ON ..
-- The C compiler identification is Clang 14.0.5
-- The CXX compiler identification is Clang 14.0.5
...
-- Configuring done
-- Generating done
-- Build files have been written to: /home/freebsd/gwinc/build/cppcms/cppcms-1.2_updates/build

To disable the building of the static library ( -DDISABLE_STATIC=ON ) and to use OpenSSL ( -DDISABLE_GCRYPT=ON ) instead of gcrypt, pass the following additional cmake build configuration flags.

Terminal ~ 1.1-5
...
$ cmake -DDISABLE_ICONV=ON -DDISABLE_STATIC=ON -DDISABLE_GCRYPT=ON ..
...

1.1.3Build CppCMS

Inside the CMake configured build directory ( /cppcms-1.2_updates/build ), run the gmake command to compile the source code as per the CMake generated Makefile.

Terminal ~ 1.1-6
$ cd /home/freebsd/gwinc/build/cppcms/cppcms-1.2_updates/build
$ gmake 
Scanning dependencies of target booster
[  1%] Building CXX object booster/CMakeFiles/booster.dir/lib/ptime/src/posix_time.cpp.o
[  1%] Building CXX object booster/CMakeFiles/booster.dir/lib/ptime/src/ctime.cpp.o
[  1%] Building CXX object booster/CMakeFiles/booster.dir/lib/regex/src/pcre_regex.cpp.o
...
Scanning dependencies of target test_aio_timer
[100%] Building CXX object booster/CMakeFiles/test_aio_timer.dir/lib/aio/test/test_timer.cpp.o
[100%] Linking CXX executable test_aio_timer
[100%] Built target test_aio_timer

1.1.4Install CppCMS

After a successful build, install the CppCMS header files, static and shared libraries, and binaries to standard system directories ( /include, /lib, and /bin ) by running the gmake install command with sudo privileges.

Terminal ~ 1.1-7
$ sudo gmake install
...
[ 13%] Built target booster
[ 27%] Built target cppcms
[ 28%] Built target loadable_storage
...
[100%] Built target test_aio_timer
Install the project...
-- Install configuration: "RelWithDebInfo"
-- Installing: /usr/local/lib/libcppcms.so.1.2.1
-- Installing: /usr/local/lib/libcppcms.so.1
-- Set runtime path of "/usr/local/lib/libcppcms.so.1.2.1" to ""
-- Installing: /usr/local/lib/libcppcms.so
...
-- Installing: /usr/local/lib/libbooster.so.0.2.0
-- Installing: /usr/local/lib/libbooster.so.0
-- Set runtime path of "/usr/local/lib/libbooster.so.0.2.0" to ""
-- Installing: /usr/local/lib/libbooster.so
-- Installing: /usr/local/include/booster/build_config.h
-- Installing: /usr/local/lib/libbooster.a
-- Up-to-date: /usr/local/include/booster/build_config.h

1.1.5Locate CppCMS

CppCMS header and library files are installed in the following system directories.

Terminal ~ 1.1-8
$ ls -l /usr/local/include/cppcms
total 968
-rw-r--r--  1 root  wheel  14245 Nov 10  2019 application.h
-rw-r--r--  1 root  wheel  13415 Nov 10  2019 applications_pool.h
...
-rw-r--r--  1 root  wheel   6792 Nov 10  2019 views_pool.h
-rw-r--r--  1 root  wheel  17033 Nov 10  2019 xss.h

$ ls -l /usr/local/lib/libcppcms*
-rw-r--r--  1 root  wheel  58532990 May 26 17:27 /usr/local/lib/libcppcms.a
lrwxr-xr-x  1 root  wheel        14 May 26 17:35 /usr/local/lib/libcppcms.so -> libcppcms.so.1
lrwxr-xr-x  1 root  wheel        18 May 26 17:35 /usr/local/lib/libcppcms.so.1 -> libcppcms.so.1.2.1
-rwxr-xr-x  1 root  wheel  23240264 May 26 17:22 /usr/local/lib/libcppcms.so.1.2.1

1.2CppCMS configuration

Create a web application root directory ( /usr/local/gwinc/web ) structure. Choose any root directory structure as per your naming convention.

Terminal ~ 1.2-1
$ sudo mkdir -p /usr/local/gwinc/web

# Set permissions
$ sudo chmod -R 755 /usr/local/gwinc
$ sudo chown -R freebsd:freebsd /usr/local/gwinc

1.2.1Application directory

Create a CppCMS application directory ( /usr/local/gwinc/web/example ) under the web application root directory ( web ).

Terminal ~ 1.2-2
$ cd /usr/local/gwinc/web
$ mkdir example

Build a CppCMS C++ console application named example using any C++ IDE and LLVM Clang C++ compiler. Copy the resultant executable file ( example ) to the application directory ( /usr/local/gwinc/web/example ).

To learn how to create a CppCMS web application, refer to the chapter CppCMS C++ web application.

1.2.2Application configuration

Create a CppCMS application JSON configuration file ( web-config.json ) under the web application directory ( /usr/local/gwinc/web/example ). Add fastcgi as the value for api property under service object. This will enable a FastCGI connection between the Lighttpd web server and the CppCMS application server.

Terminal ~ 1.2-3
$ sudo nano -w -c /usr/local/gwinc/web/example/web-config.json
{
    "service":
    {
        "api": "fastcgi",
        "socket": "stdin"
    },
    "localization":
    {
        "locales": ["en_US.UTF-8"],
        "disable_charset_in_content_type": false
    }
}

1.3Lighttpd configuration

Open example.com.conf virtual host configuration file and add a catch-all URL rewrite rule ( "^/(.*)" ) to url.rewrite-once section at the end after all the static URL rewrite rules. When all the static URL rules don't match, the URL is updated to match the CppCMS web application path ( "/example/$1" ).

Add the CppCMS FastCGI server configurations. The bin-path points to the CppCMS application configuration file ( /usr/local/gwinc/web/example/web-config.json ), and the socket points to the CppCMS FastCGI application socket file descriptor.

Terminal ~ 1.3-1
$ sudo nano -w -c /usr/local/etc/lighttpd/vhosts.d/example.com.conf
# VIRTUAL HOST (example.com)

$HTTP["host"] == "example.com" {

  var.vhost_name = "example.com"
  server.name = vhost_name

  server.document-root = server_root + "/" + vhost_name + "/data"
  accesslog.filename = log_root + "/" + vhost_name + "/access.log"
  deflate.cache-dir = cache_root + "/" + vhost_name

  static-file.exclude-extensions += (".h", ".c", ".hpp", ".cpp")

  setenv.add-response-header += (
	"Access-Control-Allow-Origin" => "*",
	"Access-Control-Allow-Methods" => "GET, POST"
  )

  url.rewrite-once = (
    "^/(.+)(\-[0-9]+)(\.)(css|js)$" => "/$4/$1$3$4",
    "^/(.+)(\.)(woff|woff2)$" => "/font/$1$2$3",
    "^/(.+)(\.)(xml|txt)$" => "/$3/$1$2$3",
    "^/(.+)(\.)(ico|jpg|png|gif|svg)$" => "/img/$1$2$3",
    "^/(.*)" => "/example/$1"
  )

  # FastCGI
  var.example_app_dir = "/usr/local/gwinc/web/example"

  $HTTP["url"] =~ "^/example" {
    fastcgi.server = ("/example" => ("example-app" => (
      "bin-path" => example_app_dir + "/example -c " + example_app_dir + "/web-config.json",
      "socket" => socket_root + "/example-fcgi-socket",
      "max-procs" => 1,
      "check-local" => "disable"
    )))
  }
}

Affiliate links

Setting up a CppCMS C++ web application server requires a VPS with root access. For managed VPS hosting, try Cloudways managed VPS. Use our affiliate links to purchase a VPS or cloud server from third-party vendors. The affiliate commissions we earn facilitate free website access for everyone.

The affiliate links are listed in alphabetical order without any favor. Users are encouraged to refer to the Global Webdynamics LLP Terms of Service governing the Third-party vendors.