Install CppCMS on FreeBSD
CppCMS C++ web application server
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.
GWSE-D3C9I7*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. 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.
- Cloudways WordPress VPS hosting
- Linode VPS hosting $100 credit
- Tastytrade invest in US markets
- Vultr VPS hosting $100 credit
The affiliate links are listed in alphabetical order without any favor. Users are encouraged to refer to the Global Webdynamics Private Limited 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 (
      /gw/build/cppcms ) structure under the user's home directory (
      /home/freebsd ). You may choose any build directory structure as per your naming convention.
    
$ mkdir -p /home/freebsd/gw/build/cppcms
$ cd /home/freebsd/gw/build/cppcms
	  Download the CppCMS source code from GitHub using the
	  wget network downloader utility and extract the zip file using
	  tar command.
	
$ 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++.
    
$ nano -c /home/freebsd/gw/build/cppcms/cppcms-1.2_updates/CMakeLists.txt
cmake_minimum_required(VERSION 2.6)
...
set(CMAKE_C_COMPILER "clang")
set(CMAKE_CXX_COMPILER "clang++")
...
set(CMAKE_CXX_FLAGS "-std=c++14")
...
      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.
    
$ cd /home/freebsd/gw/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/gw/build/cppcms/cppcms-1.2_updates/build
      To disable the building of the static library (
      -DDISABLE_STATIC=ON ) and to use the OpenSSL (
      -DDISABLE_GCRYPT=ON ) instead of
      gcrypt, pass the following additional
      cmake build configuration flags.
    
...
$ 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.
    
$ cd /home/freebsd/gw/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.
    
$ 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.
$ 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/gw/web ) structure. Choose any root directory structure as per your naming convention.
  
$ sudo mkdir -p /usr/local/gw/web
# Set permissions
$ sudo chmod -R 755 /usr/local/gw
$ sudo chown -R freebsd:freebsd /usr/local/gw
1.2.1Application directory
      Create a CppCMS application directory (
      /usr/local/gw/web/example ) under the web application root directory (
      web ).
    
$ cd /usr/local/gw/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/gw/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/gw/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.
    
$ sudo nano -c /usr/local/gw/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/gw/web/example/web-config.json ), and the
    socket points to the CppCMS FastCGI application socket file descriptor.
  
$ sudo nano -c /usr/local/etc/lighttpd/vhosts.d/example.com.conf
$HTTP["host"] == "example.com"
{
  var.vhost_name = "example.com"
  server.name = vhost_name
  server.document-root = server_root + "/" + vhost_name + "/data"
  deflate.cache-dir = cache_root + "/" + vhost_name
  accesslog.filename = log_root + "/" + vhost_name + "/access.log"
  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/gw/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. 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.
- Cloudways WordPress VPS hosting
- Linode VPS hosting $100 credit
- Tastytrade invest in US markets
- Vultr VPS hosting $100 credit
The affiliate links are listed in alphabetical order without any favor. Users are encouraged to refer to the Global Webdynamics Private Limited Terms of Service governing the Third-party vendors.
