> ## Documentation Index
> Fetch the complete documentation index at: https://documentation.bearsampp.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Create Local Virtual Hosts in Bearsampp

> Add Apache virtual hosts in Bearsampp to give each local project its own domain like myapp.local, with SSL generated automatically and Apache restarted for you.

Virtual hosts let you give each local project its own domain name instead of accessing everything under `http://localhost/`. With a virtual host, your project at `C:\projects\myapp\` becomes accessible at `http://myapp.local/`, making it easier to test realistic URLs and work with multiple projects simultaneously.

## How to add a virtual host

<Steps>
  <Step title="Right-click the Bearsampp tray icon">
    Find the Bearsampp icon in your Windows system tray and right-click it.
  </Step>

  <Step title="Open the Apache menu">
    Hover over **Apache** in the context menu.
  </Step>

  <Step title="Click Add a virtual host">
    Click **Add a virtual host**. A dialog opens with two fields.
  </Step>

  <Step title="Enter the server name">
    In the **Server name** field, type the local domain you want to use (e.g. `myapp.local`). The dialog pre-fills `test.local` as a placeholder.
  </Step>

  <Step title="Set the document root">
    Click **Browse** next to the **Document root** field and select the folder containing your project files. This is the folder Apache will serve when the domain is requested.
  </Step>

  <Step title="Click Save">
    Click **Save**. Bearsampp creates the virtual host configuration file and an SSL certificate, then restarts Apache automatically.
  </Step>
</Steps>

<Warning>
  The server name must be a valid domain name. Use a format like `myapp.local` — a bare name like `myapp` without a dot will be rejected. The `.local` suffix is a common convention for local development.
</Warning>

## What Bearsampp creates

When you save a virtual host, Bearsampp does two things:

1. **Creates a config file** at `bearsampp\vhosts\myapp.local.conf` containing the Apache `<VirtualHost>` block.
2. **Generates an SSL certificate** for the server name and stores it in `bearsampp\ssl\`.

Apache is then restarted to load the new configuration.

## Add the domain to your hosts file

After creating the virtual host, you must tell Windows to resolve the domain to your local machine. Without this step, your browser will try to look up the domain on the internet and fail.

You can do this with the HostsEditor tool included in Bearsampp, or by editing the hosts file manually.

### Using HostsEditor (recommended)

<Steps>
  <Step title="Open HostsEditor from the tray">
    Right-click the tray icon → **Tools** → **HostsEditor**.
  </Step>

  <Step title="Add an entry">
    Add a new entry mapping `127.0.0.1` to your virtual host domain (e.g. `myapp.local`) and save.
  </Step>
</Steps>

### Editing the hosts file manually

<Steps>
  <Step title="Open Notepad as Administrator">
    Press **Start**, search for **Notepad**, right-click it, and choose **Run as administrator**.
  </Step>

  <Step title="Open the hosts file">
    In Notepad, open the file at:

    ```
    C:\Windows\System32\drivers\etc\hosts
    ```
  </Step>

  <Step title="Add the entry">
    At the end of the file, add a new line in this format:

    ```
    127.0.0.1   myapp.local
    ```
  </Step>

  <Step title="Save the file">
    Save the file. No restart is required — the change takes effect immediately.
  </Step>
</Steps>

Once the hosts file is updated, open `http://myapp.local/` in your browser to access your project.

## Edit a virtual host

To change the configuration of an existing virtual host:

1. Right-click the tray icon → **Apache** → **Edit \[servername]**.
2. The config file opens in your configured text editor.
3. Make your changes, save the file, and restart Apache from the tray menu.

## Delete a virtual host

1. Right-click the tray icon → **Apache** → **Edit \[servername]**.
2. Click **Delete** in the dialog.
3. Confirm the deletion. Bearsampp removes the `.conf` file and restarts Apache.

<Note>
  Deleting a virtual host from the Bearsampp menu removes the config file at `bearsampp\vhosts\`, but does not delete the SSL certificate from `bearsampp\ssl\` or remove the entry from your hosts file. You can clean those up manually if needed.
</Note>
