Skip to content

Commit 6862ac1

Browse files
committed
Restructure README and improve guides
Closes #218
1 parent 644805e commit 6862ac1

File tree

1 file changed

+133
-123
lines changed

1 file changed

+133
-123
lines changed

README.md

+133-123
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# [Apache Server Configs](https://github.com/h5bp/server-configs-apache/)
1+
# [Apache Server Configs](https://github.com/h5bp/server-configs-apache)
22

33
[![Test](https://github.com/h5bp/server-configs-apache/workflows/server/badge.svg)](https://github.com/h5bp/server-configs-apache/actions?query=workflow%3Aserver)
44

@@ -10,93 +10,49 @@ accessible, if needed, even cross-domain.
1010

1111
## Getting Started
1212

13-
There are a few options for getting the Apache server configs.
13+
There are a two options for getting the Apache server configs:
14+
* If you have access to the [main server configuration
15+
file](https://httpd.apache.org/docs/current/configuring.html#main)
16+
(usually called `httpd.conf`), you should configure Apache by this way.
17+
This is usually the recommended way, as using `.htaccess` files [slows
18+
down](https://httpd.apache.org/docs/current/howto/htaccess.html#when)
19+
Apache!
20+
* If you don't have access to it, which is quite common with hosting services,
21+
checkout the [`.htaccess` guide](#htaccess-file).
1422

15-
See also the [Apache Getting Started](https://httpd.apache.org/docs/current/getting-started.html).
16-
17-
### Using the httpd configuration
18-
19-
If you have access to the [main server configuration
20-
file](https://httpd.apache.org/docs/current/configuring.html#main)
21-
(usually called `httpd.conf`), you should configure Apache by this way.
22-
This is usually the recommended way, as using `.htaccess` files [slows
23-
down](https://httpd.apache.org/docs/current/howto/htaccess.html#when)
24-
Apache!
25-
26-
Getting options:
27-
* Download the [zip archive](https://github.com/h5bp/server-configs-apache/archive/3.2.1.zip)
28-
* Checkout directly:
29-
```shell
30-
apache2ctl stop
31-
cd /usr/local
32-
mv apache2 apache2-previous
33-
git clone https://github.com/h5bp/server-configs-apache.git apache2
34-
# install-specific edits
35-
apache2ctl start
36-
```
37-
38-
See [Apache httpd configuration usage guide](#Apache-httpd-configuration).
39-
40-
### Using the `.htaccess` file
41-
42-
If you don't have access, which is quite common with hosting services,
43-
just copy the `.htaccess` file in the root of the website.
44-
45-
Getting options:
46-
* Download the `h5bp.htaccess` on the [latest release](https://github.com/h5bp/server-configs-apache/releases/latest)
47-
* Install them via [npm](https://www.npmjs.com/): `npm install --save-dev apache-server-configs`
48-
Inside the `dist/` folder, you'll find a ready-to-use `.htaccess` file.
49-
50-
51-
## Usage
52-
53-
### Basic structure
54-
55-
This repository has the following structure:
56-
57-
```
58-
./
59-
├── vhosts/
60-
│ ├── 000-default.conf
61-
│ └── templates/
62-
├── h5bp/
63-
│ ├── basic.conf
64-
│ └── .../
65-
└── httpd.conf
66-
```
67-
68-
* **`vhosts/`**
69-
70-
This directory should contain all the server definitions.
71-
72-
Except if they are dot prefixed or non .conf extension, all files in this
73-
folder **are** loaded automatically.
23+
Using the Apache server configs repo directly has a few required steps to be able to work.
7424

75-
* **`templates` folder**
76-
77-
Files in this folder contain a `<VirtualHost/>` template for secure and non-secure hosts.
78-
They are intended to be copied in the `vhosts` folder with all `example.com`
79-
occurrences changed to the target host.
25+
See also the [Apache Getting Started](https://httpd.apache.org/docs/current/getting-started.html).
8026

81-
* **`h5bp/`**
27+
### Check `httpd.conf` settings
8228

83-
This directory contains config snippets (mixins) to be included as desired.
84-
85-
There are two types of config files provided, individual config snippets and
86-
combined config files which provide convenient defaults.
29+
The first thing to check is that the `httpd.conf` file contains appropriate values for
30+
your specific install.
8731

88-
* **`basic.conf`**
32+
Most specific variables are:
33+
* `ServerRoot`
34+
* `User`
35+
* `Group`
36+
* `ErrorLog`
37+
* `CustomLog`
38+
* `TypesConfig` (ensure that the path for the `mime.types` file is valid)
8939

90-
This file loads a small subset of the rules provided by this repository to add
91-
expires headers, allow cross domain fonts and protect system files from web
92-
access.
93-
The `basic.conf` file includes the rules which are recommended to always be
94-
defined.
40+
### Apache test and restart
9541

96-
* **`httpd.conf`**
42+
* To verify Apache config
43+
```shell
44+
$ apache2 -t
45+
```
9746

98-
The main Apache config file.
47+
* To verify Apache config with a custom file
48+
```shell
49+
$ apache2 -t -f httpd.conf
50+
```
9951

52+
* To reload Apache and apply new config
53+
```shell
54+
$ apache2ctl reload
55+
```
10056

10157
### Enable Apache httpd modules
10258

@@ -131,7 +87,7 @@ used to install Apache.
13187

13288
`sudo a2enmod setenvif headers deflate filter expires rewrite include`
13389

134-
2. Restart apache by using the following command, so the new configuration takes
90+
2. Restart apache by using the following command so the new configuration takes
13591
effect.
13692

13793
`sudo /etc/init.d/apache2 restart`
@@ -152,41 +108,83 @@ used to install Apache.
152108
* **XAMPP**: `/Applications/XAMPP/etc/httpd.conf`
153109
* **WAMP**: `C:\apache\conf\httpd.conf`
154110

155-
Open the file in a text editor and uncomment all the required modules.
111+
Open the file in a text editor and uncomment all of the required modules.
156112
Once you have done so, reset MAMP/WAMP/XAMPP.
157113

158-
### Apache httpd configuration
114+
### Basic structure
159115

160-
#### Check `httpd.conf` settings
116+
This repository has the following structure:
161117

162-
The first thing to check is that the `httpd.conf` file contains appropriate values for
163-
your specific install.
118+
```
119+
./
120+
├── vhosts/
121+
│ ├── 000-default.conf
122+
│ └── templates/
123+
├── h5bp/
124+
│ ├── basic.conf
125+
│ └── .../
126+
└── httpd.conf
127+
```
164128

165-
Most specific variables are:
166-
* `ServerRoot`
167-
* `User`
168-
* `Group`
169-
* `ErrorLog`
170-
* `CustomLog`
129+
* **`vhosts/`**
171130

172-
#### Apache test and restart
131+
This directory should contain all the server definitions.
173132

174-
* To verify Apache config
175-
```shell
176-
$ apache2 -t
177-
```
133+
Except if they are dot prefixed or non `.conf` extension, all files in this
134+
folder **are** loaded automatically.
178135

179-
* To verify Apache config with a custom file
180-
```shell
181-
$ apache2 -t -f httpd.conf
182-
```
136+
* **`templates` folder**
183137

184-
* To reload Apache and apply new config
185-
```shell
186-
$ apache2ctl reload
187-
```
138+
Files in this folder contain a `<VirtualHost/>` template for secure and non-secure hosts.
139+
They are intended to be copied in the `vhosts` folder with all `example.com`
140+
occurrences changed to the target host.
141+
142+
* **`h5bp/`**
143+
144+
This directory contains config snippets (mixins) to be included as desired.
145+
146+
There are two types of config files provided, individual config snippets and
147+
combined config files which provide convenient defaults.
148+
149+
* **`basic.conf`**
150+
151+
This file loads a small subset of the rules provided by this repository to add
152+
expires headers, allow cross domain fonts and protect system files from web
153+
access.
154+
The `basic.conf` file includes the rules which are recommended to always be
155+
defined.
156+
157+
* **`httpd.conf`**
158+
159+
The main Apache config file.
160+
161+
162+
## Usage
163+
164+
### As a reference
188165

189-
#### Manage sites
166+
To use as reference requires no special installation steps, download/checkout the
167+
repository to a convenient location and adapt your existing httpd configuration
168+
incorporating the desired functionality from this repository.
169+
170+
Download the [latest release archive](https://github.com/h5bp/server-configs-apache/releases/latest).
171+
172+
### Directly
173+
174+
To use directly, add httpd config files from this repository.
175+
For example:
176+
177+
```shell
178+
apache2ctl stop
179+
git clone https://github.com/h5bp/server-configs-apache.git /tmp/h5bp-apache
180+
cd /usr/local
181+
cp -r apache2 apache2-previous
182+
cp -r /tmp/h5bp-apache/* apache2
183+
# install-specific edits
184+
apache2ctl start
185+
```
186+
187+
### Manage sites
190188

191189
```bash
192190
$ cd /usr/local/apache2/vhosts
@@ -213,7 +211,19 @@ $ apache2ctl reload
213211
```
214212

215213

216-
## Custom `.htaccess` builds
214+
## `.htaccess` file
215+
216+
### Usage
217+
218+
Just copy the `.htaccess` file in the root of the website.
219+
220+
Getting options:
221+
* Download the `h5bp.htaccess` on the [latest release](https://github.com/h5bp/server-configs-apache/releases/latest)
222+
and rename the file to `.htaccess`
223+
* Install them via [npm](https://www.npmjs.com/): `npm install --save-dev apache-server-configs`
224+
Inside the `dist/` folder, you'll find a ready-to-use `.htaccess` file.
225+
226+
### Custom `.htaccess` builds
217227

218228
Security, mime-type, and caching best practices evolve, and so should do your
219229
`.htaccess` file. In the past, with each new *Apache Server Configs* release
@@ -224,13 +234,13 @@ The [**build script**](#build-script-buildsh) with its re-usable and customizabl
224234
[**build configuration**](#configuration-file-htaccessconf) lets you easily
225235
update your `.htaccess` file. Each new `.htaccess` build will contain the
226236
updated *Apache Server Configs* source files, enabled or commented-out according
227-
to your settings in the *htaccess.conf* of your project root.
237+
to your settings in the `htaccess.conf` of your project root.
228238

229-
### Configuration file: *htaccess.conf*
239+
#### Configuration file: `htaccess.conf`
230240

231241
Allows you to define which module to [enable](#enabling-modules) or
232242
[disable](#disabling-modules) for your project. Just copy the default
233-
[**htaccess.conf**](https://github.com/h5bp/server-configs-apache/blob/master/bin/htaccess.conf)
243+
[`htaccess.conf`](https://github.com/h5bp/server-configs-apache/blob/master/bin/htaccess.conf)
234244
from this repo into your project directory. Adjust to your needs, and/or
235245
[add custom code](#adding-custom-modules) snippets you need for your project.
236246
Its syntax is straight and pretty much self-explanatory:
@@ -247,11 +257,11 @@ omit "src/example-module/not-needed-at-all.conf"
247257
... more modules ...
248258
```
249259

250-
#### Disabling modules
260+
##### Disabling modules
251261

252262
For example, the *“Cross-origin web fonts”* snippet is always included in
253263
our pre-built `.htaccess` file and enabled. If your project does not deal
254-
with web fonts, you can **disable** or **omit** this section:
264+
with web fonts, you can `disable` or `omit` this section:
255265

256266
This will comment out the section:
257267

@@ -265,17 +275,17 @@ disable "h5bp/cross-origin/web_fonts.conf"
265275
omit "h5bp/cross-origin/web_fonts.conf"
266276
```
267277

268-
#### Enabling modules
278+
##### Enabling modules
269279

270280
For example, the *“Forcing https://”* snippet is disabled by default,
271281
although being included in our pre-built `.htaccess`. To enable this
272-
snippet, change the **disable** keyword to **enable:**
282+
snippet, change the `disable` keyword to `enable`:
273283

274284
```
275285
enable "h5bp/rewrites/rewrite_http_to_https.conf"
276286
```
277287

278-
#### Adding custom modules
288+
##### Adding custom modules
279289

280290
Imagine you're passing all requests to non-existing files to your
281291
favourite web framework. The according
@@ -286,21 +296,21 @@ snippet would go like this:
286296
FallbackResource index.php
287297
```
288298

289-
Store this snippet in a file, e.g. **config/framework_rewrites.conf,** and add
290-
a reference in your **htaccess.conf:**
299+
Store this snippet in a file, e.g. `config/framework_rewrites.conf`, and add
300+
a reference in your `htaccess.conf`:
291301

292302
```
293303
# PROJECT MODULES
294304
enable "config/framework_rewrites.conf"
295305
```
296306

297-
### Build script: *build.sh*
307+
#### Build script: `build.sh`
298308

299309
Dive into your project root and call the build script from wherever you cloned
300310
the repo. Here are three examples:
301311

302-
**1. Create a default .htaccess**
303-
in current work directory. An existing **htaccess.conf** in this directory will
312+
**1. Create a default `.htaccess`**
313+
in current work directory. An existing `htaccess.conf` in this directory will
304314
be used; if none is present, the
305315
[**default configuration**](https://github.com/h5bp/server-configs-apache/blob/master/bin/htaccess.conf)
306316
will apply.
@@ -316,7 +326,7 @@ $ path/to/server-configs-apache/bin/build.sh
316326

317327
**2. Custom output location**
318328
Just add output path and filename as parameter. By the way, if there's an
319-
existing *.htaccess* file, the build script will create a backup.
329+
existing `.htaccess` file, the build script will create a backup.
320330

321331
```bash
322332
$ path/to/server-configs-apache/bin/build.sh htdocs/.htaccess
@@ -325,9 +335,9 @@ $ path/to/server-configs-apache/bin/build.sh htdocs/.htaccess
325335
[✔] Moved in place: 'htdocs/.htaccess'
326336
```
327337

328-
**3. Custom .htaccess configuration**
329-
Why not maintain your personal **~/htaccess.conf?** This example creates a
330-
*.htaccess* in current work directory, according to your favourite settings
338+
**3. Custom `.htaccess` configuration**
339+
Why not maintain your personal `~/htaccess.conf`? This example creates a
340+
`.htaccess` in current work directory, according to your favourite settings
331341
you may have stored in your `$HOME` directory:
332342

333343
```bash

0 commit comments

Comments
 (0)