# Phase 2: Local macOS Apache Development

## Scope

This guide applies only to local macOS development using Apache `httpd`.

It does not apply to production. Production is served through Nginx, which does not read `.htaccess` files.

## Local hostname

Use:

```text
http://defapp.local/
```

Add this entry to `/etc/hosts`:

```text
127.0.0.1 defapp.local
```

## Local document root

Set the local document root to the parent applications directory:

```text
/Users/YOUR_USERNAME/websites/apps
```

The application then resolves at:

```text
http://defapp.local/defapp/
```

Alternatively, point the virtual host directly to DefApp:

```text
/Users/YOUR_USERNAME/websites/apps/defapp
```

The application then resolves at:

```text
http://defapp.local/
```

Choose one URL scheme and use it consistently.

## Recommended Apache virtual host

Save a local-only virtual-host file, for example:

```text
/etc/apache2/extra/httpd-defapp.conf
```

Example configuration when Apache points directly to the DefApp directory:

```apache
<VirtualHost *:80>
    ServerName defapp.local
    DocumentRoot "/Users/YOUR_USERNAME/websites/apps/defapp"

    <Directory "/Users/YOUR_USERNAME/websites/apps/defapp">
        Options -Indexes +FollowSymLinks
        AllowOverride None
        Require all granted
    </Directory>

    <Directory "/Users/YOUR_USERNAME/websites/apps/defapp/pages">
        Require all denied
    </Directory>

    <Directory "/Users/YOUR_USERNAME/websites/apps/defapp/old">
        Require all denied
    </Directory>

    <FilesMatch "\.(?:env|ini|log|sql|sqlite|bak|backup|dist)$">
        Require all denied
    </FilesMatch>

    ErrorLog "/private/var/log/apache2/defapp-error.log"
    CustomLog "/private/var/log/apache2/defapp-access.log" combined
</VirtualHost>
```

Replace `YOUR_USERNAME` with the local macOS account name.

## Why `AllowOverride None`

This configuration intentionally uses:

```apache
AllowOverride None
```

The local Apache virtual-host configuration owns access control. This avoids scattered `.htaccess` behavior and keeps local behavior explicit and reviewable.

Apache only processes `.htaccess` directives when the relevant directory allows overrides. `AllowOverride FileInfo` or `AllowOverride All` is required for `.htaccess` rewrite directives. [Apache documentation]

## Enable the virtual host

Ensure Apache includes the local file from `/etc/apache2/httpd.conf`:

```apache
Include /private/etc/apache2/extra/httpd-defapp.conf
```

Check configuration syntax:

```bash
sudo apachectl configtest
```

Expected result:

```text
Syntax OK
```

Restart Apache:

```bash
sudo apachectl restart
```

## Local validation

```bash
curl -i http://defapp.local/
curl -i http://defapp.local/css/app.css
curl -i http://defapp.local/pages/breadcrumbs.php
```

Expected results:

| Path | Expected result |
|---|---|
| `/` | HTTP 200 |
| `/css/app.css` | HTTP 200 and `Content-Type: text/css` |
| `/pages/breadcrumbs.php` | HTTP 403 or HTTP 404 |

## If `.htaccess` testing is needed

Use it only for Apache compatibility testing. Create a local-only file that is not committed to the production deployment:

```text
.htaccess.local
```

Example:

```apache
Options -Indexes
```

To test actual `.htaccess` processing, local Apache must permit it:

```apache
<Directory "/Users/YOUR_USERNAME/websites/apps/defapp">
    AllowOverride Options FileInfo
</Directory>
```

Do not use this as the normal configuration. Prefer virtual-host configuration with `AllowOverride None`# Phase 2: Local macOS Apache Development

## Scope

This guide applies only to local macOS development using Apache `httpd`.

It does not apply to production. Production is served through Nginx, which does not read `.htaccess` files.

## Local hostname

Use:

```text
http://defapp.local/
```

Add this entry to `/etc/hosts`:

```text
127.0.0.1 defapp.local
```

## Local document root

Set the local document root to the parent applications directory:

```text
/Users/YOUR_USERNAME/websites/apps
```

The application then resolves at:

```text
http://defapp.local/defapp/
```

Alternatively, point the virtual host directly to DefApp:

```text
/Users/YOUR_USERNAME/websites/apps/defapp
```

The application then resolves at:

```text
http://defapp.local/
```

Choose one URL scheme and use it consistently.

## Recommended Apache virtual host

Save a local-only virtual-host file, for example:

```text
/etc/apache2/extra/httpd-defapp.conf
```

Example configuration when Apache points directly to the DefApp directory:

```apache
<VirtualHost *:80>
    ServerName defapp.local
    DocumentRoot "/Users/YOUR_USERNAME/websites/apps/defapp"

    <Directory "/Users/YOUR_USERNAME/websites/apps/defapp">
        Options -Indexes +FollowSymLinks
        AllowOverride None
        Require all granted
    </Directory>

    <Directory "/Users/YOUR_USERNAME/websites/apps/defapp/pages">
        Require all denied
    </Directory>

    <Directory "/Users/YOUR_USERNAME/websites/apps/defapp/old">
        Require all denied
    </Directory>

    <FilesMatch "\.(?:env|ini|log|sql|sqlite|bak|backup|dist)$">
        Require all denied
    </FilesMatch>

    ErrorLog "/private/var/log/apache2/defapp-error.log"
    CustomLog "/private/var/log/apache2/defapp-access.log" combined
</VirtualHost>
```

Replace `YOUR_USERNAME` with the local macOS account name.

## Why `AllowOverride None`

This configuration intentionally uses:

```apache
AllowOverride None
```

The local Apache virtual-host configuration owns access control. This avoids scattered `.htaccess` behavior and keeps local behavior explicit and reviewable.

Apache only processes `.htaccess` directives when the relevant directory allows overrides. `AllowOverride FileInfo` or `AllowOverride All` is required for `.htaccess` rewrite directives. [Apache documentation]

## Enable the virtual host

Ensure Apache includes the local file from `/etc/apache2/httpd.conf`:

```apache
Include /private/etc/apache2/extra/httpd-defapp.conf
```

Check configuration syntax:

```bash
sudo apachectl configtest
```

Expected result:

```text
Syntax OK
```

Restart Apache:

```bash
sudo apachectl restart
```

## Local validation

```bash
curl -i http://defapp.local/
curl -i http://defapp.local/css/app.css
curl -i http://defapp.local/pages/breadcrumbs.php
```

Expected results:

| Path | Expected result |
|---|---|
| `/` | HTTP 200 |
| `/css/app.css` | HTTP 200 and `Content-Type: text/css` |
| `/pages/breadcrumbs.php` | HTTP 403 or HTTP 404 |

## If `.htaccess` testing is needed

Use it only for Apache compatibility testing. Create a local-only file that is not committed to the production deployment:

```text
.htaccess.local
```

Example:

```apache
Options -Indexes
```

To test actual `.htaccess` processing, local Apache must permit it:

```apache
<Directory "/Users/YOUR_USERNAME/websites/apps/defapp">
    AllowOverride Options FileInfo
</Directory>
```

Do not use this as the normal configuration. Prefer virtual-host configuration with `AllowOverride None`.

