1Building CivetWeb 2========= 3 4This guide covers the build instructions for the stand-alone web server. 5See [Embedding.md](https://github.com/civetweb/civetweb/blob/master/docs/Embedding.md) for information on extending an existing C or C++ application. A brief overview of the source code files can be found in [Embedding.md](https://github.com/civetweb/civetweb/blob/master/docs/Embedding.md) as well. 6 7#### Where to get the source code? 8 9The latest development version can be found at 10https://github.com/civetweb/civetweb 11 12Tested and released versions can be found at 13https://github.com/civetweb/civetweb/releases 14 15 16Building for Windows 17--------- 18 19#### Using Visual Studio 20 21Open the *VS/civetweb.sln* in Visual Studio. 22To include SSL support, you may have to add an extra library for the cryptography support. You might wish to use yaSSL. However, it is GPL licensed or uses a commercial license. See [yaSSL.md](https://github.com/civetweb/civetweb/blob/master/docs/yaSSL.md) for more information. 23Alternatively, you might wish to use OpenSSL. See [OpenSSL.md](https://github.com/civetweb/civetweb/blob/master/docs/OpenSSL.md) for more information. 24 25#### Using MinGW-w64 or TDM-GCC 26In the start menu locate and run the "Run terminal" batch file. For TDM-GCC this is named "MinGW Command Prompt". 27Navigate to the civetweb sources directory and run: 28``` 29mingw32-make CC=gcc 30``` 31 32#### Using Qt Creator 33Open the Qt Designer project in the Qt folder 34 35#### Using CMake 36Except for the components in the `third_party` folder (e.g., Lua and Duktape), CivetWeb can also be built with CMake. 37CMake can be used for all supported operating systems. 38 39 40Building for Linux, BSD, and OSX 41--------- 42 43## Using Make 44 45``` 46make help 47``` 48Get a list of all supported make option 49 50``` 51make build 52make WITH_ALL=1 53``` 54Compile the code. 55Using the option "WITH_ALL=1" enables all optional features. 56 57``` 58make install 59``` 60Install on the system, Linux only. 61 62``` 63make lib WITH_IPV6=1 64make clean slib WITH_LUA=1 WITH_WEBSOCKET=1 65``` 66Build the static and shared libraries. 67The additional make options configure the library just as it would the application. 68 69The *slib* option should be done on a separate clean build as position 70independent code (PIC) is required for it. Trying to run it after 71building the static library or the server will result in a link error. 72 73``` 74make clean 75``` 76Clean up files generated during the build 77 78 79## Setting build options 80 81Make options can be set on the command line with the make command like so. 82``` 83make build WITH_LUA=1 84``` 85 86 87| Make Options | Description | 88| --------------------------- | ------------------------------------------------- | 89| `WITH_LUA=1` | build with Lua support | 90| `WITH_DUKTAPE=1` | build with server-side JavaScript support | 91| `WITH_IPV6=1` | with IPV6 support | 92| `WITH_WEBSOCKET=1` | build with web socket support | 93| `WITH_X_DOM_SOCKET=1` | build with unix domain socket support | 94| `WITH_SERVER_STATS=1` | build with support for server statistics | 95| `WITH_EXPERIMENTAL=1` | include experimental features (version depending) | 96| `WITH_ALL=1` | Include all of the above features | 97| `WITH_DEBUG=1` | build with GDB debug support | 98| `WITH_CPP=1` | build libraries with c++ classes | 99| `CONFIG_FILE=file` | use 'file' as the config file | 100| `CONFIG_FILE2=file` | use 'file' as the backup config file | 101| `HTMLDIR=/path` | place to install initial web pages | 102| `DOCUMENT_ROOT=/path` | default document root | 103| `PORTS=8080` | listening ports override when installing | 104| `SSL_LIB=libssl.so.0` | use versioned SSL library | 105| `CRYPTO_LIB=libcrypto.so.0` | system versioned CRYPTO library | 106| `PREFIX=/usr/local` | sets the install directory | 107| `COPT='-DNO_SSL'` | method to insert compile flags | 108 109Note that the WITH_* options used for *make* are not identical to the 110preprocessor defines in the source code - usually USE_* is used there. 111 112 113## Changing PREFIX 114 115To change the target destination pass the `PREFIX` option to the command `make install` (not `make build`). Example usage: 116 117``` 118$ make build 119$ make -n install PREFIX=/opt/civetweb 120``` 121Note: The `-n` corresponds to the `--dry-run` option (it does not make any changes): You can see where `make install` would install. Example output of the above command: 122 123``` 124$ make -n install PREFIX=/opt/civetweb 125install -d -m 755 "/opt/civetweb/share/doc/civetweb" 126install -m 644 resources/itworks.html /opt/civetweb/share/doc/civetweb/index.html 127install -m 644 resources/civetweb_64x64.png /opt/civetweb/share/doc/civetweb/ 128install -d -m 755 "/opt/civetweb/etc" 129install -m 644 resources/civetweb.conf "/opt/civetweb/etc/" 130sed -i 's#^document_root.*$#document_root /opt/civetweb/share/doc/civetweb#' "/opt/civetweb/etc/civetweb.conf" 131sed -i 's#^listening_ports.*$#listening_ports 8080#' "/opt/civetweb/etc/civetweb.conf" 132install -d -m 755 "/opt/civetweb/share/doc/civetweb" 133install -m 644 *.md "/opt/civetweb/share/doc/civetweb" 134install -d -m 755 "/opt/civetweb/bin" 135install -m 755 civetweb "/opt/civetweb/bin/" 136``` 137 138If the output looks good: Just remove the `-n` option to actually install the software on your system. 139 140 141## Setting compile flags 142 143Compile flags can be set using the *COPT* make option like so. 144``` 145make build COPT="-DNDEBUG -DNO_CGI" 146``` 147 148| Compile Flags | Description | 149| ---------------------------- | ------------------------------------------------------------------- | 150| `NDEBUG` | strip off all debug code | 151| `DEBUG` | build debug version (very noisy) | 152| | | 153| `NO_ATOMICS` | do not use atomic functions, use locks instead | 154| `NO_CACHING` | disable caching functionality | 155| `NO_CGI` | disable CGI support | 156| `NO_FILES` | do not serve files from a directory | 157| `NO_FILESYSTEMS` | completely disable filesystems usage (requires NO_FILES) | 158| `NO_NONCE_CHECK` | disable nonce check for HTTP digest authentication | 159| `NO_RESPONSE_BUFFERING` | send all mg_response_header_* immediately instead of buffering until the mg_response_header_send call | 160| `NO_SSL` | disable SSL functionality | 161| `NO_SSL_DL` | link against system libssl library | 162| `NO_THREAD_NAME` | do not set a name for pthread | 163| | | 164| `USE_ALPN` | enable Application-Level-Protocol-Negotiation, required for HTTP2 | 165| `USE_DUKTAPE` | enable server-side JavaScript (using Duktape library) | 166| `USE_HTTP2` | enable HTTP2 support (experimental, not reccomended for production) | 167| `USE_IPV6` | enable IPv6 support | 168| `USE_LUA` | enable Lua support | 169| `USE_SERVER_STATS` | enable server statistics support | 170| `USE_STACK_SIZE` | define stack size instead of using system default | 171| `USE_WEBSOCKET` | enable websocket support | 172| `USE_X_DOM_SOCKET` | enable unix domain socket support | 173| `USE_ZLIB` | enable on-the-fly compression of files (using zlib) | 174| | | 175| `MG_EXPERIMENTAL_INTERFACES` | include experimental interfaces | 176| `MG_LEGACY_INTERFACE` | include obsolete interfaces (candidates for deletion) | 177| | | 178| `SQLITE_DISABLE_LFS` | disables large files (Lua only) | 179| `SSL_ALREADY_INITIALIZED` | do not initialize libcrypto | 180| `OPENSSL_API_1_0` | Use OpenSSL V1.0.x interface | 181| `OPENSSL_API_1_1` | Use OpenSSL V1.1.x interface | 182| | | 183| `BUILD_DATE` | define as a string to be used as build id instead of __DATE__ | 184| | | 185 186 187Note: If `make` is used (with this [Makefile](https://github.com/civetweb/civetweb/blob/master/Makefile)), you should not pass the `USE_<feature>` flags using `COPT`, but use the `WITH_<feature>` syntax above, since additional features may also use additional source code files. 188 189 190## Cross Compiling 191 192Take total control with *CC*, *COPT* and *TARGET_OS* as make options. 193TARGET_OS is used to determine some compile details as will as code function. 194TARGET_OS values should be be one found in *resources/Makefile.in-os*. 195 196``` 197make CC=arm-none-linux-gnueabi-gcc COPT="-march=armv7-a -mfpu=vfp -mfloat-abi=softfp" TARGET_OS=FROG 198``` 199 200## Cocoa DMG Packaging (OSX Only) 201 202Use the alternate *Makefile.osx* to do the build. The entire build has 203to be done using *Makefile.osx* because additional compile and link options 204are required. This Makefile has all the same options as the other one plus 205one additional *package* rule. 206 207``` 208make -f Makefile.osx package 209``` 210 211Building with Buildroot 212--------- 213 214[Buildroot](http://buildroot.uclibc.org/) is a tool for creating cross compiled file systems. Including Civetweb in buildroot is fairly easy. There is even support for various build options. 215 2161. First, check if it already there. 217 - In buildroot, make menuconfig 218 - Package Selection for the target ---> 219 - Networking applications ---> 220 - civetweb 2212. If not there, just add it 222 - copy *Config.in* and *civetweb.mk* from Civetweb's *contrib/buildroot/* to Buildroot's *package/civetweb/* directory. 223 - In Buildroot's *package/Config.in, insert the following line in were you will know how to find it in the menu. 224 > ``` source "package/civetweb/Config.in" ``` 225 226 227Building on Android 228--------- 229 230This is a small guide to help you run civetweb on Android, originally 231tested on the HTC Wildfire. 232Note: You do not need root access to run civetweb on Android. 233 234- Download the source from the Downloads page. 235- Download the Android NDK from [http://developer.android.com/tools/sdk/ndk/index.html](http://developer.android.com/tools/sdk/ndk/index.html) 236- Run `/path-to-ndk/ndk-build -C /path-to-civetweb/resources` 237 That should generate civetweb/lib/armeabi/civetweb 238- Using the adb tool (you need to have Android SDK installed for that), 239 push the generated civetweb binary to `/data/local` folder on device. 240- From adb shell, navigate to `/data/local` and execute `./civetweb`. 241- To test if the server is running fine, visit your web-browser and 242 navigate to `http://127.0.0.1:8080` You should see the `Index of /` page. 243 244 245Notes: 246 247- `jni` stands for Java Native Interface. Read up on Android NDK if you want 248 to know how to interact with the native C functions of civetweb in Android 249 Java applications. 250 251 252 253