Configure Cherokee web server with MySQL database optimization and performance tuning

Intermediate 45 min May 01, 2026 68 views
Ubuntu 24.04 Debian 12 AlmaLinux 9 Rocky Linux 9

Set up Cherokee web server with optimized MySQL database connections, FastCGI configuration, and performance tuning for high-traffic web applications on Linux systems.

Prerequisites

  • Root or sudo access
  • Basic command line knowledge
  • Understanding of web server concepts

What this solves

Cherokee is a high-performance web server that excels at serving dynamic content with low resource usage. This tutorial shows you how to configure Cherokee with MySQL database optimization, FastCGI support, and advanced caching for production web applications. You'll set up secure database connections, tune MySQL performance parameters, and configure Cherokee's built-in caching system for maximum throughput.

Step-by-step installation

Update system packages

Start by updating your package manager to ensure you get the latest versions of Cherokee and MySQL.

sudo apt update && sudo apt upgrade -y
sudo dnf update -y

Install Cherokee web server

Install Cherokee along with its admin interface for easy configuration management.

sudo apt install -y cherokee cherokee-admin libcherokee-mod-libssl libcherokee-mod-streaming
sudo dnf install -y cherokee cherokee-admin cherokee-devel

Install MySQL server and development libraries

Install MySQL server along with development headers needed for Cherokee's MySQL integration.

sudo apt install -y mysql-server mysql-client libmysqlclient-dev php-mysql php-fpm
sudo dnf install -y mysql-server mysql-devel php php-mysqlnd php-fpm

Start and secure MySQL

Enable MySQL service and run the security script to set up initial authentication.

sudo systemctl enable --now mysql
sudo mysql_secure_installation

Follow the prompts to set a root password and remove test databases.

Create MySQL database and user

Create a dedicated database and user for your web application with optimized privileges.

sudo mysql -u root -p
CREATE DATABASE webapp_db CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER 'webapp_user'@'localhost' IDENTIFIED BY 'secure_password_here';
GRANT SELECT, INSERT, UPDATE, DELETE ON webapp_db.* TO 'webapp_user'@'localhost';
FLUSH PRIVILEGES;
EXIT;

Optimize MySQL configuration

Configure MySQL with performance optimizations for web applications and Cherokee integration.

[mysqld]

InnoDB Optimization

innodb_buffer_pool_size = 256M innodb_log_file_size = 64M innodb_flush_log_at_trx_commit = 2 innodb_flush_method = O_DIRECT

Query Cache (for read-heavy workloads)

query_cache_type = 1 query_cache_size = 64M query_cache_limit = 2M

Connection Optimization

max_connections = 200 max_connect_errors = 10000 connect_timeout = 10 wait_timeout = 600 interactive_timeout = 600

Thread Cache

thread_cache_size = 16 thread_stack = 256K

Table Cache

table_open_cache = 4000 table_definition_cache = 2000

Slow Query Log

slow_query_log = 1 slow_query_log_file = /var/log/mysql/slow.log long_query_time = 2

Binary Logging

log_bin = /var/log/mysql/mysql-bin.log binlog_expire_logs_seconds = 259200 max_binlog_size = 100M

Restart MySQL and verify optimization

Apply the configuration changes and verify MySQL is running with optimized settings.

sudo systemctl restart mysql
sudo systemctl status mysql
mysql -u root -p -e "SHOW VARIABLES LIKE 'innodb_buffer_pool_size';"

Configure PHP-FPM for Cherokee

Set up PHP-FPM with optimized settings for Cherokee web server integration.

[www]
user = www-data
group = www-data
listen = /run/php/php8.3-fpm.sock
listen.owner = www-data
listen.group = www-data
listen.mode = 0660

pm = dynamic
pm.max_children = 20
pm.start_servers = 4
pm.min_spare_servers = 2
pm.max_spare_servers = 6
pm.max_requests = 500

; Performance tuning
request_terminate_timeout = 60s
rlimit_files = 65536
rlimit_core = 0

; Security
security.limit_extensions = .php .php3 .php4 .php5 .php7 .php8

Optimize PHP configuration

Configure PHP with MySQL optimizations and performance settings for Cherokee.

; Memory and execution limits
memory_limit = 256M
max_execution_time = 60
max_input_time = 60
post_max_size = 32M
upload_max_filesize = 32M
max_file_uploads = 20

; MySQL/MySQLi optimization
mysql.connect_timeout = 10
mysql.default_socket = /var/run/mysqld/mysqld.sock
mysqli.default_socket = /var/run/mysqld/mysqld.sock

; PDO MySQL optimization
pdo_mysql.default_socket = /var/run/mysqld/mysqld.sock
pdo_mysql.cache_size = 2000

; OPcache configuration
opcache.enable = 1
opcache.memory_consumption = 128
opcache.max_accelerated_files = 4000
opcache.validate_timestamps = 1
opcache.revalidate_freq = 60

; Session optimization
session.save_handler = files
session.gc_maxlifetime = 1440
session.gc_probability = 1
session.gc_divisor = 100

Start PHP-FPM service

Enable and start PHP-FPM to handle dynamic content processing for Cherokee.

sudo systemctl enable --now php8.3-fpm
sudo systemctl status php8.3-fpm

Start Cherokee admin interface

Launch Cherokee's web-based admin interface for easy configuration management.

sudo cherokee-admin -b
sudo systemctl enable cherokee

The admin interface will be available at http://your-server-ip:9090. Note the one-time password displayed in the terminal.

Configure Cherokee FastCGI for PHP

Set up FastCGI to connect Cherokee with PHP-FPM for dynamic content processing.

In the Cherokee admin interface:

  • Go to vServersdefaultBehavior
  • Click Rule ManagementAdd new rule
  • Select Extensions and enter: php
  • Set Handler to FastCGI
  • Configure the FastCGI source:
Information Source: Local Interpreter
Host: localhost
Socket: /run/php/php8.3-fpm.sock
Spawn Server: No

Configure Cherokee caching

Enable Cherokee's built-in caching system for improved performance with database-driven content.

In the Cherokee admin interface:

  • Go to vServersdefaultBehavior
  • Add a new rule for Directory: /
  • Set Handler to Static Content
  • Enable Only allow GET and HEAD methods
  • Configure caching in the Expiration tab:
Mode: Specify max-age
Time: 1h
No cache: Uncheck
Public: Check

Configure Cherokee compression

Enable GZIP compression to reduce bandwidth usage and improve load times.

In the Cherokee admin interface:

  • Go to vServersdefaultEncoding
  • Check Allow x-gzip and Allow gzip
  • Set compression level to 6 (balanced speed/ratio)
  • Add MIME types:
text/plain
text/html
text/css
text/javascript
application/javascript
application/json
application/xml
text/xml

Create MySQL connection pool configuration

Configure connection pooling to optimize database performance under load.

host};dbname={$this->database};charset=utf8mb4";
            $options = [
                PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
                PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
                PDO::ATTR_PERSISTENT => true,
                PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8mb4",
                PDO::ATTR_TIMEOUT => 10,
            ];
            
            $this->connection = new PDO($dsn, $this->username, $this->password, $options);
        } catch (PDOException $e) {
            error_log("Database connection failed: " . $e->getMessage());
            throw $e;
        }
    }
    
    public static function getInstance() {
        if (self::$instance === null) {
            self::$instance = new self();
        }
        return self::$instance;
    }
    
    public function getConnection() {
        return $this->connection;
    }
}
?>

Set proper file permissions

Configure secure file permissions for Cherokee and web application files.

Never use chmod 777. It gives every user on the system full access to your files. Instead, fix ownership with chown and use minimal permissions.
sudo chown -R www-data:www-data /var/www/html
sudo find /var/www/html -type d -exec chmod 755 {} \;
sudo find /var/www/html -type f -exec chmod 644 {} \;
sudo chmod 640 /var/www/html/config/database.php

Apply Cherokee configuration

Save and apply all configuration changes in the Cherokee admin interface.

In the Cherokee admin interface, click Save to apply all changes, then restart Cherokee:

sudo systemctl restart cherokee
sudo systemctl status cherokee

Verify your setup

Test that Cherokee is properly connected to MySQL and serving dynamic content.

sudo systemctl status cherokee
sudo systemctl status mysql
sudo systemctl status php8.3-fpm
curl -I http://localhost/
mysql -u webapp_user -p -e "SELECT 1 as test;"

Create a test PHP file to verify database connectivity:

getConnection();
    $stmt = $db->query('SELECT VERSION() as mysql_version, NOW() as current_time');
    $result = $stmt->fetch();
    
    echo "

Cherokee + MySQL Test

"; echo "

MySQL Version: " . $result['mysql_version'] . "

"; echo "

Current Time: " . $result['current_time'] . "

"; echo "

Connection: SUCCESS

"; } catch (Exception $e) { echo "

Connection failed: " . $e->getMessage() . "

"; } ?>

Access http://your-server-ip/test_db.php to verify the connection works.

Performance monitoring and tuning

Enable Cherokee performance logging

Configure detailed logging to monitor Cherokee performance and identify bottlenecks.

In the Cherokee admin interface:

  • Go to vServersdefaultLogging
  • Enable Access Log
  • Set format to Combined Log Format
  • Add custom log for timing:
%h %l %u %t "%r" %>s %b "%{Referer}i" "%{User-agent}i" %D

Monitor MySQL performance

Set up monitoring for MySQL query performance and connection usage.

mysql -u root -p -e "SHOW GLOBAL STATUS LIKE 'Connections';"
mysql -u root -p -e "SHOW GLOBAL STATUS LIKE 'Threads_connected';"
mysql -u root -p -e "SHOW GLOBAL STATUS LIKE 'Slow_queries';"
mysql -u root -p -e "SHOW PROCESSLIST;"

Create performance monitoring script

Set up automated monitoring for Cherokee and MySQL performance metrics.

#!/bin/bash

Cherokee + MySQL Performance Monitor

LOGFILE="/var/log/cherokee_mysql_performance.log" DATE=$(date '+%Y-%m-%d %H:%M:%S') echo "[$DATE] Performance Check" >> $LOGFILE

Cherokee process info

CHEROKEE_PROCS=$(ps aux | grep cherokee | grep -v grep | wc -l) echo "Cherokee processes: $CHEROKEE_PROCS" >> $LOGFILE

MySQL connections

MYSQL_CONNECTIONS=$(mysql -u root -p"$MYSQL_ROOT_PASSWORD" -e "SHOW GLOBAL STATUS LIKE 'Threads_connected';" -s -N | awk '{print $2}') echo "MySQL connections: $MYSQL_CONNECTIONS" >> $LOGFILE

PHP-FPM processes

PHP_FPM_PROCS=$(ps aux | grep php-fpm | grep -v grep | wc -l) echo "PHP-FPM processes: $PHP_FPM_PROCS" >> $LOGFILE

Load average

LOAD_AVG=$(uptime | awk -F'load average:' '{print $2}') echo "Load average: $LOAD_AVG" >> $LOGFILE echo "---" >> $LOGFILE
sudo chmod +x /usr/local/bin/monitor_cherokee_mysql.sh
sudo crontab -e

Add this line to run monitoring every 5 minutes:

/5    * /usr/local/bin/monitor_cherokee_mysql.sh

For comprehensive monitoring of Cherokee and MySQL performance, consider integrating with Prometheus and Grafana dashboards for real-time metrics visualization.

Common issues

SymptomCauseFix
PHP files download instead of executingFastCGI not configured properlyCheck FastCGI socket path in Cherokee admin, verify PHP-FPM is running
Database connection timeoutsMySQL max_connections too lowIncrease max_connections in MySQL config, restart MySQL
Cherokee won't start after config changesSyntax error in configurationCheck sudo journalctl -u cherokee for error details
High memory usagePHP-FPM pool size too highReduce pm.max_children in PHP-FPM pool config
Slow database queriesMissing indexes or poor queriesEnable slow query log, analyze with EXPLAIN statements
Permission denied errorsIncorrect file ownershipsudo chown -R www-data:www-data /var/www/html
FastCGI socket connection failedPHP-FPM not listening on socketVerify socket path in both Cherokee and PHP-FPM configs match

Next steps

Running this in production?

Want this handled for you? Setting this up once is straightforward. Keeping it patched, monitored, backed up and tuned across environments is the harder part. See how we run infrastructure like this for European SaaS and e-commerce teams.

Automated install script

Run this to automate the entire setup

Need help?

Don't want to manage this yourself?

We handle managed cloud infrastructure for businesses that depend on uptime. From initial setup to ongoing operations.