Swiftpack.co - Package - PerfectlySoft/PerfectTemplateFCGI

PerfectTemplateFCGI 简体中文

Get Involed with Perfect!

Star Perfect On Github Stack Overflow Follow Perfect on Twitter Join the Perfect Slack

Swift 3.0 Platforms OS X | Linux License Apache PerfectlySoft Twitter Slack Status

Perfect Empty Starter FastCGI Project

This repository holds a blank Perfect project which can be cloned to serve as a starter for new work. It builds with Swift Package Manager and produces a FastCGI based server executable.


We are transitioning to using JIRA for all bugs and support related issues, therefore the GitHub issues has been disabled.

If you find a mistake, bug, or any other helpful suggestion you'd like to make on the docs please head over to http://jira.perfect.org:8080/servicedesk/customer/portal/1 and raise it.

A comprehensive list of open issues can be found at http://jira.perfect.org:8080/projects/ISS/issues


The master branch of this project currently compiles with DEVELOPMENT-SNAPSHOT-2016-06-20-a released June 20th, 2016 using Swift Package Manager.

Ensure that you have installed the few dependencies which Perfect requires for your platform:


This server can run with any FastCGI enabled webserver over either UNIX socket files or TCP.

Apache 24

To run with Apache 2.4, build and install the mod_perfect FastCGI module:



Instructions for running with NGINX:


Building & Running

The following will clone and build an empty starter project and launch the server.

git clone https://github.com/PerfectlySoft/PerfectTemplateFCGI.git
cd PerfectTemplateFCGI
swift build

You should see the following output:

Starting FastCGI server on named pipe /Library/WebServer/VirtualHosts/perfect.fastcgi.sock

This means the server is running and waiting for connections.

Starter Content

The template file contains a very simple "hello, world!" example. Note that you must install mod_perfect or otherwise configure your web server for FastCGI and change the namedPipe path such that it points one level above your server's document root.

import PerfectFastCGI
import PerfectHTTP

var routes = Routes()
routes.add(method: .get, uri: "/**") {
    req, resp in
    resp.appendBody(string: "<html><title>Hello, world!</title><body>Hello, world!</body></html>")

let server = FastCGIServer()

do {
    // Launch the FastCGI server
    // The path to the sock file must point to a directory one level up from the site's document root.
    // The file must be called "perfect.fastcgi.sock"
    // For example, the following path would suffice for a server whose document root is:
    // /Library/WebServer/VirtualHosts/wwwroot/
    try server.start(namedPipe: "/Library/WebServer/VirtualHosts/perfect.fastcgi.sock")
} catch {
    print("Error thrown: \(error)")

Further Information

For more information on the Perfect project, please visit perfect.org.


Stars: 3
Help us keep the lights on