{"id":13683528,"url":"https://github.com/h5bp/server-configs-apache","last_synced_at":"2025-05-11T03:48:36.403Z","repository":{"id":9724969,"uuid":"11682335","full_name":"h5bp/server-configs-apache","owner":"h5bp","description":"Apache HTTP server boilerplate configs","archived":false,"fork":false,"pushed_at":"2025-01-27T08:04:42.000Z","size":1206,"stargazers_count":3232,"open_issues_count":3,"forks_count":636,"subscribers_count":162,"default_branch":"main","last_synced_at":"2025-05-11T03:48:15.658Z","etag":null,"topics":["apache","best-practices","config","h5bp","htaccess","httpd","httpd-configuration","robust","standard"],"latest_commit_sha":null,"homepage":"","language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/h5bp.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":".github/CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE.txt","code_of_conduct":".github/CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":["LeoColomb"],"patreon":null,"open_collective":null,"ko_fi":null,"tidelift":null,"custom":null}},"created_at":"2013-07-26T09:23:30.000Z","updated_at":"2025-05-08T21:56:52.000Z","dependencies_parsed_at":"2024-12-31T00:02:38.782Z","dependency_job_id":"32fbdbe1-d955-426f-b3ee-adca5f5f42f4","html_url":"https://github.com/h5bp/server-configs-apache","commit_stats":{"total_commits":701,"total_committers":99,"mean_commits":7.08080808080808,"dds":0.7018544935805991,"last_synced_commit":"06825494d4a5fa9cd4330927512bd82f3658d6d6"},"previous_names":[],"tags_count":29,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/h5bp%2Fserver-configs-apache","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/h5bp%2Fserver-configs-apache/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/h5bp%2Fserver-configs-apache/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/h5bp%2Fserver-configs-apache/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/h5bp","download_url":"https://codeload.github.com/h5bp/server-configs-apache/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253514559,"owners_count":21920334,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["apache","best-practices","config","h5bp","htaccess","httpd","httpd-configuration","robust","standard"],"created_at":"2024-08-02T13:02:14.524Z","updated_at":"2025-05-11T03:48:36.351Z","avatar_url":"https://github.com/h5bp.png","language":"Shell","readme":"# [Apache Server Configs](https://github.com/h5bp/server-configs-apache)\n\n[![Server CI](https://github.com/h5bp/server-configs-apache/actions/workflows/server.yml/badge.svg)](https://github.com/h5bp/server-configs-apache/actions/workflows/server.yml)\n\n**Apache Server Configs** is a collection of configuration snippets that can help\nyour server improve the website's performance and security, while also\nensuring that resources are served with the correct content-type and are\naccessible, if needed, even cross-domain.\n\n\n## Getting Started\n\nThere are two options for getting the Apache server configs:\n\n* If you have access to the [main server configuration\n  file](https://httpd.apache.org/docs/current/configuring.html#main)\n  (usually called `httpd.conf`), you should configure Apache this way.\n  This is usually the recommended way, as using `.htaccess` files [slows\n  down](https://httpd.apache.org/docs/current/howto/htaccess.html#when)\n  Apache!\n* If you don't have access to it, which is quite common with hosting services,\n  checkout the [`.htaccess` guide](#htaccess-file).\n\nUsing the Apache server configs repo directly has a few required steps to be able to work.\n\nSee also the [Apache Getting Started](https://httpd.apache.org/docs/current/getting-started.html).\n\n### Check `httpd.conf` settings\n\nThe first thing to check is that the `httpd.conf` file contains appropriate values for\nyour specific install.\n\nMost specific variables are:\n\n* `ServerRoot`\n* `User`\n* `Group`\n* `ErrorLog`\n* `CustomLog`\n* `TypesConfig` (ensure that the path for the `mime.types` file is valid)\n\n### Apache test and restart\n\n* To verify Apache config\n\n  ```shell\n  apache2 -t\n  ```\n\n* To verify Apache config with a custom file\n\n  ```shell\n  apache2 -t -f httpd.conf\n  ```\n\n* To reload Apache and apply the new config\n\n  ```shell\n  apache2ctl reload\n  ```\n\n### Enable Apache httpd modules\n\nSome configurations won't have any effect if the\nappropriate modules aren't enabled. So, in order for everything\nto work as intended, you need to ensure you have the following\nApache modules enabled:\n\n* [`mod_autoindex.c` (autoindex_module)](https://httpd.apache.org/docs/current/mod/mod_autoindex.html)\n* [`mod_deflate.c` (deflate_module)](https://httpd.apache.org/docs/current/mod/mod_deflate.html)\n* [`mod_expires.c` (expires_module)](https://httpd.apache.org/docs/current/mod/mod_expires.html)\n* [`mod_filter.c` (filter_module)](https://httpd.apache.org/docs/current/mod/mod_filter.html)\n* [`mod_headers.c` (headers_module)](https://httpd.apache.org/docs/current/mod/mod_headers.html)\n* [`mod_include.c` (include_module)](https://httpd.apache.org/docs/current/mod/mod_include.html)\n* [`mod_mime.c` (mime_module)](https://httpd.apache.org/docs/current/mod/mod_mime.html)\n* [`mod_rewrite.c` (rewrite_module)](https://httpd.apache.org/docs/current/mod/mod_rewrite.html)\n* [`mod_setenvif.c` (setenvif_module)](https://httpd.apache.org/docs/current/mod/mod_setenvif.html)\n\nFor more detailed information on configuration files and how to\nuse them, please check the appropriate Apache documentation:\n\n* \u003chttps://httpd.apache.org/docs/current/configuring.html\u003e\n* \u003chttps://httpd.apache.org/docs/current/howto/htaccess.html\u003e\n\n#### Standalone\n\nThese instructions should work on any distribution where `apt-get` has been\nused to install Apache.\n\n1. Open up a terminal and type the following command. Enter your password when\n   prompted.\n\n    ```shell\n    sudo a2enmod setenvif headers deflate filter expires rewrite include\n    ```\n\n2. Restart apache by using the following command, so the new configuration takes\n   effect.\n\n    ```shell\n    sudo /etc/init.d/apache2 restart\n    ```\n\n#### With MAMP/WAMP/XAMPP\n\n* **MAMP PRO**. On the main screen, click the `Apache` tab and ensure that all\n   the required modules are 'checked', indicating they are enabled.\n\n* **WampServer**. If you have installed WampServer just click on the icon in the\n   task bar then \u003ckbd\u003eApache\u003c/kbd\u003e section then \u003ckbd\u003emodules\u003c/kbd\u003e section.\n   You will be presented with a list of modules. Simply click on a module name\n   to enable it. WampServer will automatically restart the Apache service after\n   you enable a module.\n\n* **Others**. Locate the `httpd.conf` file, which is typically found in:\n  * **MAMP**: `/Applications/MAMP/conf/apache/httpd.conf`\n  * **XAMPP**: `/Applications/XAMPP/etc/httpd.conf`\n  * **WAMP**: `C:\\apache\\conf\\httpd.conf`\n\n  Open the file in a text editor and uncomment all the required modules.\n  Once you have done so, reset MAMP/WAMP/XAMPP.\n\n### Basic structure\n\nThis repository has the following structure:\n\n```text\n./\n├── vhosts/\n│   ├── 000-default.conf\n│   └── templates/\n├── h5bp/\n│   ├── basic.conf\n│   └── .../\n└── httpd.conf\n```\n\n* **`vhosts/`**\n\n  This directory should contain all the server definitions.\n\n  Except if they are dot prefixed or non `.conf` extension, all files in this\n  folder **are** loaded automatically.\n\n  * **`templates` folder**\n\n    Files in this folder contain a `\u003cVirtualHost/\u003e` template for secure and non-secure hosts.\n    They are intended to be copied in the `vhosts` folder with all `example.com`\n    occurrences changed to the target host.\n\n* **`h5bp/`**\n\n  This directory contains config snippets (mixins) to be included as desired.\n\n  There are two types of config files provided, individual config snippets and\n  combined config files which provide convenient defaults.\n\n  * **`basic.conf`**\n\n    This file loads a small subset of the rules provided by this repository to add\n    expires headers, allow cross-domain fonts and protect system files from web\n    access.\n    The `basic.conf` file includes the rules which are recommended to always be\n    defined.\n\n* **`httpd.conf`**\n\n  The main Apache config file.\n\n\n## Usage\n\nThe [default location of the configuration files](https://httpd.apache.org/docs/current/getting-started.html#configuration) is `/usr/local/apache2/`, but these files may be located any of a variety of places, depending on how exactly you installed the server.  \nCommon locations for these files may be found [in the httpd wiki](http://wiki.apache.org/httpd/DistrosDefaultLayout).\n\n### As a reference\n\nTo use as reference requires no special installation steps, download/checkout the\nrepository to a convenient location and adapt your existing httpd configuration\nincorporating the desired functionality from this repository.\n\nDownload the [latest release archive](https://github.com/h5bp/server-configs-apache/releases/latest).\n\n### Directly\n\nTo use directly, add httpd config files from this repository.  \nFor example:\n\n```shell\napache2ctl stop\ngit clone https://github.com/h5bp/server-configs-apache.git /tmp/h5bp-apache\ncd /usr/local\ncp -r apache2 apache2-previous\ncp -r /tmp/h5bp-apache/* apache2\n# install-specific edits\napache2ctl start\n```\n\n### Manage sites\n\n```bash\ncd /usr/local/apache2/vhosts\n```\n\n* Creating a new site\n\n  ```bash\n  cp templates/example.com.conf .actual-hostname.conf\n  sed -i 's/example.com/actual-hostname/g' .actual-hostname.conf\n  ```\n\n* Enabling a site\n\n  ```bash\n  mv .actual-hostname.conf actual-hostname.conf\n  ```\n\n* Disabling a site\n\n  ```bash\n  mv actual-hostname.conf .actual-hostname.conf\n  ```\n\n```bash\napache2ctl reload\n```\n\n\n## `.htaccess` file\n\n### Usage\n\nJust copy the `.htaccess` file in the root of the website.\n\nGetting options:\n\n* Download the `h5bp.htaccess` on the [latest release](https://github.com/h5bp/server-configs-apache/releases/latest)\n  and rename the file to `.htaccess`\n* Install them via [npm](https://www.npmjs.com/): `npm install --save-dev apache-server-configs`\n  Inside the `dist/` folder, you'll find a ready-to-use `.htaccess` file.\n\n### Custom `.htaccess` builds\n\nSecurity, mime-type, and caching best practices evolve, and so should do your\n`.htaccess` file. In the past, with each new *Apache Server Configs* release\nit was quite tedious to find out which `.htaccess` trick was just new or only\nhad changes in certain nuances.\n\nThe [**build script**](#build-script-buildsh) with its re-usable and customizable\n[**build configuration**](#configuration-file-htaccessconf) lets you easily\nupdate your `.htaccess` file. Each new `.htaccess` build will contain the\nupdated *Apache Server Configs* source files, enabled or commented-out according\nto your settings in the `htaccess.conf` of your project root.\n\n#### Configuration file: `htaccess.conf`\n\nIt allows you to define which module to [enable](#enabling-modules) or\n[disable](#disabling-modules) for your project. Just copy the default\n[`htaccess.conf`](https://github.com/h5bp/server-configs-apache/blob/main/bin/htaccess.conf)\nfrom this repo into your project directory. Adjust to your needs, and/or\n[add custom code](#adding-custom-modules) snippets you need for your project.\nIts syntax is straight and pretty much self-explanatory:\n\n```apache\n# Example Module\n\ntitle   \"example module\"\nenable  \"src/example-module/images.conf\"\nenable  \"src/example-module/web_fonts.conf\"\ndisable \"src/example-module/not-needed.conf\"\nomit    \"src/example-module/not-needed-at-all.conf\"\n\n#... more modules ...\n```\n\n##### Disabling modules\n\nFor example, the *“Cross-origin web fonts”* snippet is always included in\nour pre-built `.htaccess` file and enabled. If your project does not deal\nwith web fonts, you can `disable` or `omit` this section:\n\nThis will comment out the section:\n\n```apache\ndisable  \"h5bp/cross-origin/web_fonts.conf\"\n```\n\n…and this will exclude the section, saving lines in output:\n\n```apache\nomit  \"h5bp/cross-origin/web_fonts.conf\"\n```\n\n##### Enabling modules\n\nFor example, the *“Forcing `https://`”* snippet is disabled by default,\nalthough being included in our pre-built `.htaccess`. To enable this\nsnippet, change the `disable` keyword to `enable`:\n\n```apache\nenable \"h5bp/rewrites/rewrite_http_to_https.conf\"\n```\n\n##### Controlling the size of the output .htaccess file\n\nThe default partials contain significant numbers of comment lines, which\ncontain valuable guidance about how and why to use the setting as well\nas web references. However, some may feel that the size of the resulting\n`.htaccess` file is too large.\n\nThe special keyword `no-partials-comments` can be used to prevent\ncomment lines from being copied out of the partials into `.htaccess`.\n\n\u003e [!Note]\n\u003e This keyword does not control comments created by the build\n\u003e script (such as `title` or `disabled` directives), only those that\n\u003e are in the source partials files.\n\n```apache\nno-partials-comments\n```\n\n##### Adding custom modules\n\nImagine you're passing all requests to non-existing files to your\nfavorite web framework. The according\n[_mod_dir_](https://httpd.apache.org/docs/trunk/mod/mod_dir.html#fallbackresource)\nsnippet would go like this:\n\n```apache\nFallbackResource index.php\n```\n\nStore this snippet in a file, e.g. `config/framework_rewrites.conf`, and add\na reference in your `htaccess.conf`:\n\n```apache\n# PROJECT MODULES\nenable \"config/framework_rewrites.conf\"\n```\n\n#### Build script: `build.sh`\n\nDive into your project root and call the build script from wherever you cloned\nthe repo. Here are three examples:\n\n1. Create a default `.htaccess`\n\nCreate a default `.htaccess` in the current work directory. An existing\n`htaccess.conf` in this directory will be used; if none is present, the\n[**default configuration**](https://github.com/h5bp/server-configs-apache/blob/main/bin/htaccess.conf)\nwill apply.\n\n\n```console\n$ path/to/server-configs-apache/bin/build.sh\n\n# Output looks like:\n[✔] Build .htaccess\n[✔] Moved in place: './.htaccess'\n```\n\n2. Custom output location\n\nJust add an output path and filename as a parameter. By the way, if there's an\nexisting `.htaccess` file, the build script will create a backup.\n\n```console\n$ path/to/server-configs-apache/bin/build.sh htdocs/.htaccess\n[✔] Build .htaccess\n[✔] Create backup: 'htdocs/.htaccess~'\n[✔] Moved in place: 'htdocs/.htaccess'\n```\n\n3. Custom `.htaccess` configuration\n\nWhy not maintain your personal `~/htaccess.conf`? This example creates a\n`.htaccess` in the current work directory, according to your favorite settings\nyou may have stored in your `$HOME` directory:\n\n```bash\npath/to/server-configs-apache/bin/build.sh ./.htaccess ~/htaccess.conf\n```\n\n\n## Support\n\n* Apache v**2.4.17**+\n\n\n## Contributing\n\nAnyone is welcome to [contribute](.github/CONTRIBUTING.md),\nhowever, if you decide to get involved, please take a moment to review\nthe [guidelines](.github/CONTRIBUTING.md):\n\n* [Bug reports](.github/CONTRIBUTING.md#bugs)\n* [Feature requests](.github/CONTRIBUTING.md#features)\n* [Pull requests](.github/CONTRIBUTING.md#pull-requests)\n\n\n## Acknowledgements\n\n[Apache Server Configs](https://github.com/h5bp/server-configs-apache/) is\nonly possible thanks to all the awesome\n[contributors](https://github.com/h5bp/server-configs-apache/graphs/contributors)!\n\n\n## License\n\nThe code is available under the [MIT license](LICENSE.txt).\n","funding_links":["https://github.com/sponsors/LeoColomb"],"categories":["Shell","Features","Credits"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fh5bp%2Fserver-configs-apache","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fh5bp%2Fserver-configs-apache","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fh5bp%2Fserver-configs-apache/lists"}