fcgi
fcgi
fcgi is a FastCGI implementation for the Crystal language. It allows you to run Crystal web applications behind a FastCGI-compatible web server (like Apache with mod_fcgid or Nginx with ngx_http_fastcgi_module).
Installation
Add this to your application's shard.yml:
dependencies:
fcgi:
github: blazerw/fcgi
version: ~> 0.2.0
Usage
require "fcgi"
Basically, you create an app using your favorite Crystal framework (Kemal, Lucky, etc.). Figure out what's needed to boot your app and framework, then use Fcgi::Request and Fcgi::Response to bridge the FastCGI protocol with your application's HTTP::Server::Context.
See the examples directory for details on how to integrate with Kemal and Lucky.
Deployment (e.g., DreamHost)
These examples have been tested on Dreamhost using the following configuration:
Domain to host: mysubdomain.mydomain.com
Do you want the www in your URL?: Remove WWW
Run this domain under the user: username
Web Directory: /home/username/mysubdomain.mydomain.com
PHP Mode: PHP 8.x FastCGI # Yes, PHP Mode enables FastCGI.
Automatically upgrade PHP: true
HTTPS: true
Extra Web Security?: false
Passenger: false
Enable CloudFlare on this domain?: false
Google Apps: false
Add a .htaccess file to your web directory:
<IfModule mod_fastcgi.c>
AddHandler fastcgi-script .fcgi
</IfModule>
<IfModule mod_fcgid.c>
AddHandler fcgid-script .fcgi
</IfModule>
Options +FollowSymLinks +ExecCGI
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ dispatch.fcgi/$1 [QSA,L]
ErrorDocument 500 "500 Main: FCGI application failed to start properly!"
ErrorDocument 501 "501 Main: FCGI application failed to start properly!"
ErrorDocument 502 "502 Main: FCGI application failed to start properly!"
ErrorDocument 503 "503 Main: FCGI application failed to start properly!"
You must change dispatch.fcgi to the name of your compiled Crystal web application (or create a symbolic link).
Examples
Development
The library has been modernized for Crystal 1.19.1 and includes:
- Improved header parsing and type safety.
- Integration with
Logfor internal logging. - Comprehensive spec suite in
spec/.
Contributing
- Fork it ( https://github.com/blazerw/fcgi/fork )
- Create your feature branch (
git checkout -b my-new-feature) - Commit your changes (
git commit -am 'Add some feature') - Push to the branch (
git push origin my-new-feature) - Create a new Pull Request
Contributors
- Randy Wilson - creator, maintainer
fcgi
- 1
- 0
- 0
- 0
- 0
- 7 days ago
- April 4, 2018
MIT License
Sat, 25 Apr 2026 01:50:19 GMT