{"id":14424,"library":"apache-server-configs","title":"Apache Server Configs","description":"The `apache-server-configs` package provides a robust collection of boilerplate configuration snippets for the Apache HTTP server, currently at version 6.0.0. It aims to enhance web server performance, improve security postures, and ensure resources are served with correct content-types, including cross-domain access when necessary. The project maintains an active development cycle, with major version updates occurring roughly annually, addressing evolving web standards for security, caching, and performance. Minor releases typically introduce new MIME types, expand caching directives, and refine existing configurations. A key differentiator is its focus on modern best practices, including strong `Cache-Control` policies, comprehensive security headers like `Content-Security-Policy`, `Permissions-Policy`, and Cross-Origin policies, and optimized asset handling. It explicitly discourages the use of `.htaccess` files due to performance overhead, advocating for direct integration into `httpd.conf`.","status":"active","version":"6.0.0","language":"javascript","source_language":"en","source_url":"https://github.com/h5bp/server-configs-apache","tags":["javascript","apache","boilerplate","configs","configurations","h5bp","server","template"],"install":[{"cmd":"npm install apache-server-configs","lang":"bash","label":"npm"},{"cmd":"yarn add apache-server-configs","lang":"bash","label":"yarn"},{"cmd":"pnpm add apache-server-configs","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[],"quickstart":{"code":"import { promises as fs } from 'fs';\nimport { join } from 'path';\nimport { exec } from 'child_process';\n\nconst sourceDir = join(process.cwd(), 'node_modules', 'apache-server-configs', 'dist'); // Adjust if config files are not in 'dist'\nconst apacheConfDir = process.env.APACHE_CONF_DIR || '/etc/apache2/conf.d'; // Common Apache config directory\nconst httpdConfPath = process.env.HTTPD_CONF_PATH || '/etc/apache2/httpd.conf'; // Example main httpd.conf path\n\nasync function deployApacheConfigs() {\n  try {\n    console.log(`Copying Apache config files from ${sourceDir} to ${apacheConfDir}...`);\n    await fs.cp(sourceDir, apacheConfDir, { recursive: true, force: true });\n    console.log('Apache config files copied successfully.');\n\n    // Append an Include directive to httpd.conf if not already present\n    let httpdConfContent = await fs.readFile(httpdConfPath, 'utf8');\n    const includeDirective = `IncludeOptional ${apacheConfDir}/*.conf`;\n    if (!httpdConfContent.includes(includeDirective)) {\n      console.log(`Adding '${includeDirective}' to ${httpdConfPath}...`);\n      await fs.appendFile(httpdConfPath, `\\n# H5BP Apache Server Configs\\n${includeDirective}\\n`);\n    } else {\n      console.log(`'${includeDirective}' already present in ${httpdConfPath}.`);\n    }\n\n    // Enable required modules (assuming a Debian/Ubuntu-like system with a2enmod)\n    console.log('Enabling required Apache modules...');\n    const modules = ['setenvif', 'headers', 'deflate', 'filter', 'expires', 'rewrite', 'include', 'mime', 'autoindex'];\n    const a2enmodCommand = `sudo a2enmod ${modules.join(' ')}`;\n    console.log(`Executing: ${a2enmodCommand}`);\n    await new Promise((resolve, reject) => {\n      exec(a2enmodCommand, (error, stdout, stderr) => {\n        if (error) {\n          console.error(`Error enabling modules: ${stderr}`);\n          return reject(error);\n        }\n        console.log(`Modules enabled: ${stdout}`);\n        resolve();\n      });\n    });\n\n    // Test Apache configuration\n    console.log('Testing Apache configuration...');\n    await new Promise((resolve, reject) => {\n      exec('sudo apache2 -t', (error, stdout, stderr) => {\n        if (error) {\n          console.error(`Apache config test failed: ${stderr}`);\n          return reject(error);\n        }\n        console.log(`Apache config test successful: ${stdout}`);\n        resolve();\n      });\n    });\n\n    // Reload Apache to apply new config\n    console.log('Reloading Apache service...');\n    await new Promise((resolve, reject) => {\n      exec('sudo apache2ctl reload', (error, stdout, stderr) => {\n        if (error) {\n          console.error(`Apache reload failed: ${stderr}`);\n          return reject(error);\n        }\n        console.log(`Apache reloaded successfully: ${stdout}`);\n        resolve();\n      });\n    });\n\n    console.log('Apache server configs deployed and Apache reloaded successfully!');\n  } catch (error) {\n    console.error('Deployment failed:', error);\n    process.exit(1);\n  }\n}\n\ndeployApacheConfigs();","lang":"javascript","description":"This script demonstrates how to programmatically deploy and activate the Apache server configurations from `node_modules` into an Apache environment, including enabling necessary modules and verifying the setup via Node.js."},"warnings":[{"fix":"Ensure client-side browser support policies align with modern browser standards. For legacy IE support, manual re-introduction of these headers may be necessary.","message":"Internet Explorer (`X-UA-Compatible` and `X-XSS-Protection` headers) support was removed in v5.0.0, potentially affecting compatibility with older browsers.","severity":"breaking","affected_versions":">=5.0.0"},{"fix":"Review the package's `dist` directory and README for updated `.htaccess` file paths and adjust build scripts accordingly.","message":"File paths for the `.htaccess` build system were altered in v4.0.0, which can cause 'file not found' errors if existing build scripts are not updated.","severity":"breaking","affected_versions":">=4.0.0"},{"fix":"Where possible, migrate `.htaccess` directives directly into your main `httpd.conf` file or virtual host configurations, or use `Include` directives in `httpd.conf` to pull in configuration snippets.","message":"Using `.htaccess` files can introduce significant performance overhead as Apache must process them on every request; direct configuration in `httpd.conf` is strongly recommended.","severity":"gotcha","affected_versions":">=3.0.0"},{"fix":"Upgrade your Apache HTTP server to version 2.4 or higher to ensure full compatibility with the provided configurations.","message":"Apache httpd versions 2.3 and below are no longer supported since v3.0.0, which means configurations may fail to load or behave unexpectedly on older servers.","severity":"breaking","affected_versions":">=3.0.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Enable `mod_headers` using `sudo a2enmod headers` (Debian/Ubuntu) or by uncommenting `LoadModule headers_module modules/mod_headers.so` in `httpd.conf`, then restart Apache.","cause":"The `mod_headers` Apache module is not enabled, which is required for processing `Cache-Control` and other HTTP headers directives.","error":"Syntax error on line X of Y: Invalid command 'Cache-Control', perhaps misspelled or defined by a module not included in the server configuration"},{"fix":"Enable `mod_deflate` using `sudo a2enmod deflate` (Debian/Ubuntu) or by uncommenting `LoadModule deflate_module modules/mod_deflate.so` in `httpd.conf`, then restart Apache.","cause":"The `mod_deflate` Apache module is not enabled, preventing the server from applying compression filters.","error":"AH00526: Syntax error on line X of Y: Invalid command 'AddOutputFilterByType', perhaps misspelled or defined by a module not included in the server configuration"},{"fix":"Enable `mod_expires` using `sudo a2enmod expires` (Debian/Ubuntu) or by uncommenting `LoadModule expires_module modules/mod_expires.so` in `httpd.conf`, then restart Apache.","cause":"The `mod_expires` Apache module is not enabled, which is necessary for setting `Expires` headers and cache control.","error":"AH00526: Syntax error on line X of Y: Invalid command 'ExpiresActive', perhaps misspelled or defined by a module not included in the server configuration"},{"fix":"Enable `mod_rewrite` using `sudo a2enmod rewrite` (Debian/Ubuntu) or by uncommenting `LoadModule rewrite_module modules/mod_rewrite.so` in `httpd.conf`, then restart Apache.","cause":"The `mod_rewrite` Apache module is not enabled, which is critical for URL rewriting, redirects, and enforcing canonical URLs.","error":"AH00526: Syntax error on line X of Y: Invalid command 'RewriteEngine', perhaps misspelled or defined by a module not included in the server configuration"}],"ecosystem":"npm"}