### Example Installation Output Source: https://civetweb.github.io/civetweb/Building.html This is an example output of the 'make -n install PREFIX=/opt/civetweb' command, showing the installation steps without actually performing them. ```bash install -d -m 755 "/opt/civetweb/share/doc/civetweb" install -m 644 resources/itworks.html /opt/civetweb/share/doc/civetweb/index.html install -m 644 resources/civetweb_64x64.png /opt/civetweb/share/doc/civetweb/ install -d -m 755 "/opt/civetweb/etc" install -m 644 resources/civetweb.conf "/opt/civetweb/etc/" sed -i 's#^document_root.*$#document_root /opt/civetweb/share/doc/civetweb#' "/opt/civetweb/etc/civetweb.conf" sed -i 's#^listening_ports.*$#listening_ports 8080#' "/opt/civetweb/etc/civetweb.conf" install -d -m 755 "/opt/civetweb/share/doc/civetweb" install -m 644 *.md "/opt/civetweb/share/doc/civetweb" install -d -m 755 "/opt/civetweb/bin" install -m 755 civetweb "/opt/civetweb/bin/" ``` -------------------------------- ### Start CivetWeb with Configuration File Source: https://civetweb.github.io/civetweb/UserManual.html Example of starting the CivetWeb server using a configuration file. The settings in 'CivetWeb.conf' are applied. ```bash $ cat CivetWeb.conf listening_ports 1234 document_root /var/www $ CivetWeb ``` -------------------------------- ### Start CivetWeb with Command Line Arguments Source: https://civetweb.github.io/civetweb/UserManual.html Example of starting the CivetWeb server using command-line arguments for listening ports and document root. ```bash $ CivetWeb -listening_ports 1234 -document_root /var/www ``` -------------------------------- ### Minimal CivetWeb Server Initialization and Handler Setup (C) Source: https://civetweb.github.io/civetweb/Embedding.html Demonstrates the essential steps to initialize CivetWeb, start the server, set a request handler for '/hello', and then stop the server. Ensure to call mg_init_library(0) before mg_start() and mg_exit_library() after mg_stop(). ```c { /* Server context handle */ struct mg_context *ctx; /* Initialize the library */ mg_init_library(0); /* Start the server */ ctx = mg_start(NULL, 0, NULL); /* Add some handler */ mg_set_request_handler(ctx, "/hello", handler, "Hello world"); ... Run the application ... /* Stop the server */ mg_stop(ctx); /* Un-initialize the library */ mg_exit_library(); } ``` -------------------------------- ### Install CivetWeb Source: https://civetweb.github.io/civetweb/Building.html Install CivetWeb on the system. This command is primarily for Linux. ```bash make install ``` -------------------------------- ### Install CivetWeb using vcpkg Source: https://civetweb.github.io/civetweb/Installing.html Use the vcpkg dependency manager to download and install CivetWeb. Ensure vcpkg is set up correctly before running these commands. ```bash git clone https://github.com/Microsoft/vcpkg.git cd vcpkg ./bootstrap-vcpkg.sh ./vcpkg integrate install ./vcpkg install civetweb ``` -------------------------------- ### Configure CivetWeb Standalone Server Source: https://civetweb.github.io/civetweb/UserManual.html Example of a CivetWeb configuration file. Lines starting with '#' and empty lines are ignored. Configuration options can be overridden by command-line arguments. ```config document_root c:\www listening_ports 80,443s ssl_certificate c:\CivetWeb\ssl_cert.pem ``` -------------------------------- ### Build and Install CivetWeb in Docker Source: https://civetweb.github.io/civetweb/Docker.html Compiles CivetWeb with all features enabled and installs it to the /app directory within the Docker build stage. ```Dockerfile RUN make build && \ make WITH_ALL=1 && \ make install PREFIX=/app ``` -------------------------------- ### Basic Lua Server Page Example Source: https://civetweb.github.io/civetweb/UserManual.html This example demonstrates how to use `mg.write()` to output dynamic content and access request information within a Lua Server Page. ```html
Today is: mg.write(os.date("%A")) ?>
URI is =mg.request_info.uri?>
``` -------------------------------- ### Dry Run Installation with Custom Prefix Source: https://civetweb.github.io/civetweb/Building.html Perform a dry run of the 'make install' command to see where CivetWeb would be installed with a custom PREFIX. The -n option prevents actual installation. ```bash make -n install PREFIX=/opt/civetweb ``` -------------------------------- ### List Make Options Source: https://civetweb.github.io/civetweb/Building.html Run this command to get a list of all supported make options for building CivetWeb on Linux, BSD, and OSX. ```bash make help ``` -------------------------------- ### Install Runtime Dependencies in Docker Image Stage Source: https://civetweb.github.io/civetweb/Docker.html Installs only the necessary runtime libraries for CivetWeb in the final Docker image stage. ```Dockerfile FROM alpine:3.18 RUN apk update && \ apk add --no-cache \ libstdc++ zlib ``` -------------------------------- ### Build CivetWeb on Linux Source: https://civetweb.github.io/civetweb/Installing.html Standard build process for CivetWeb on Linux systems. This involves downloading the source, compiling, and installing. ```bash make help make make install ``` -------------------------------- ### mg_start Source: https://civetweb.github.io/civetweb/api/mg_start.html Initializes the Civetweb web server. It's the primary function to call for server setup, accepting callbacks for event handling and options for configuration. Returns a context pointer on success or NULL on failure. ```APIDOC ## mg_start ### Description The function `mg_start()` is the only function needed to call to initialize the webserver. After the function returns and a pointer to a context structure is provided, it is guaranteed that the server has started and is listening on the designated ports. In case of failure a NULL pointer is returned. The behaviour of the web server is controlled by a list of callback functions and a list of options. The callback functions can do application specific processing of events which are encountered by the webserver. If a specific callback function is set to NULL, the webserver uses their default callback routine. The options list controls how the webserver should be started and contains settings for for example the ports to listen on, the maximum number of threads created to handle requests in parallel and if settings for SSL encryption. As a side effect on Unix systems, SIGCHLD and SIGPIPE signals will be ignored. If custom processing is needed for these signals, signal handlers must be setup after the call to `mg_start()` has completed. ### Parameters #### Function Parameters - **`callbacks`** (`const struct mg_callbacks *`) - A structure with optional callback functions to process requests from the web server. - **`user_data`** (`void *`) - A pointer to optional user data. - **`options`** (`char **`) - A list of options used to initialize the web server. The list consists of an NULL terminated list of option-value string pairs. #### Options - **`cgi_environment`** (string) - The option `cgi_environment` can contain extra variables to be passed to the CGI script in addition to the standard environment variables. The lust must be a comma separated list of name=value pairs like this: `VARIABLE1=VALUE1,VARIABLE2=VALUE2`. - **`cgi_interpreter`** (string) - The option `cgi_interpreter` can contain a path to an executable which will be used as a CGI interpreter for **all** CGI scripts regardless of the script file extension. If this option is not set (which is the default), CivetWeb looks at the first line of a CGI script to see if an interpreter is defined there. This first line is formatted as a shebang line as common in unix style shell scripts, but this will also work in Windows. For more information about the syntax, please see the Wikipedia page about the shebang line. - **`cgi_pattern`** (string) - Default: `**.cgi$|**.pl$|**.php$` - All files that match `cgi_pattern` are treated as CGI files. The default pattern allows CGI files to be anywhere. To restrict CGIs to a certain directory, use `/path/to/cgi-bin/**.cgi` as a pattern. Note that the full path of the local file is matched against the pattern, not the URI provided in the client request. - **`put_delete_auth_file`** (string) - The option `put_delete_auth_file` defines the password file to be used for PUT and DELETE requests. Without a password file it is not possible to put new files to the server, or to delete existing ones. This only applies to direct HTTP requests which use the PUT and DELETE methods without server side scripting. PUT and DELETE requests might still be handled by Lua scripts and CGI pages. ### Return Value - **`struct mg_context *`** - A pointer to a context structure when successful, or NULL in case of failure. ### See Also - `struct mg_callbacks;` - `mg_stop();` ``` -------------------------------- ### SSI Exec Directive Example Source: https://civetweb.github.io/civetweb/UserManual.html Shows how to use the ` ``` -------------------------------- ### init_context Source: https://civetweb.github.io/civetweb/api/mg_callbacks.html Callback function called after the CivetWeb server has been initialized and started, but before any requests are processed. ```APIDOC ## init_context ### Description This callback function is executed after the CivetWeb server has successfully started and completed its initialization. It is called before the server begins handling any incoming client requests, providing a window for the application to perform any necessary setup tasks. ``` -------------------------------- ### Set Docker Container Entrypoint Source: https://civetweb.github.io/civetweb/Docker.html Defines the command that will be executed when the container starts, launching the CivetWeb server with its configuration file. ```Dockerfile ENTRYPOINT [ "/app/bin/civetweb", "/app/etc/civetweb.conf" ] ``` -------------------------------- ### Install Build Dependencies in Dockerfile Source: https://civetweb.github.io/civetweb/Docker.html Installs build tools and libraries for CivetWeb compilation within the Docker build stage. ```Dockerfile FROM alpine:3.18 AS build RUN apk update && \ apk add --no-cache \ build-base zlib-dev ``` -------------------------------- ### SSL Cipher List Examples Source: https://civetweb.github.io/civetweb/UserManual.html Illustrates how to configure the `ssl_cipher_list` option to specify which SSL/TLS ciphers the server should offer to clients. Examples include enabling all ciphers or excluding specific types. ```plaintext ALL ``` ```plaintext ALL:!eNULL ``` ```plaintext AES128:!MD5 ``` -------------------------------- ### SSI Include Directive Examples Source: https://civetweb.github.io/civetweb/UserManual.html Demonstrates different ways to use the `