# Creating a new virtual host

Creating a separate virtual host (vhost), with its own clone of the `elentra-1x-me` repository, and its own database, can be very useful because it allows you to keep the same version (e.g. `release/1.26`), without needing to switch between versions when you need to work on a different Elentra version.

By setting up additional vhosts, you can have local Elentra instances for multiple versions of Elentra, for example your institution's branded edition and the consortium version, or previously-supported releases.

{% hint style="info" %}
For the purposes of this example, we will suppose that you are creating a new vhost called `uni-elentra.localhost`, i.e. which you would access using <http://uni-elentra.localhost/>.
{% endhint %}

### **Steps**

1. Change to the `elentra-developer` directory:

   ```bash
   cd ~/Documents/elentra-developer
   ```
2. Create a new Apache configuration file for the new vhost:

   ```bash
   cp resources/vhosts/elentra-1x-me.localhost.conf resources/vhosts/uni-elentra.localhost.conf
   ```
3. Modify the new `resources/vhosts/uni-elentra.localhost.conf` file to use a different source code path and hostname, for example the following:

   ```
   # Disable so that CSS/JS will refresh properly.
   EnableSendfile On

   <VirtualHost *:80>
       ServerName uni-elentra.localhost                          # <- CHANGE

       # Required because of /etc/httpd/conf.d/php.conf hardcoded defaults
       <IfModule mod_php7.c>
           php_value session.save_handler redis
           php_value session.save_path "tcp://redis:6379?auth=password"
       </IfModule>

       DocumentRoot /var/www/vhosts/uni-elentra-1x-me/www-root   # <- CHANGE
       <Directory "/var/www/vhosts/uni-elentra-1x-me/www-root">  # <- CHANGE
           Options FollowSymLinks
           Require all granted
           AllowOverride all
       </Directory>

       <FilesMatch \.(php|phar)$>
           SetHandler "proxy:unix:/var/run/php-fpm/www.sock|fcgi://localhost"
       </FilesMatch>

       ProxyPass "/app/" "ws://localhost:${WEBSOCKET_PORT}/app/"
       ProxyPassReverse "/app/" "ws://localhost:${WEBSOCKET_PORT}/app/"
       ProxyPass "/apps/" "http://localhost:${WEBSOCKET_PORT}/apps/"
       ProxyPassReverse "/apps/" "http://localhost:${WEBSOCKET_PORT}/apps/"
   </VirtualHost>
   ```

   * If your new instance will run a version of Elentra ME that uses an older version of PHP (e.g. 7.4), then you may want to hard code the the version of the PHP in the sock file used. This way, you won't have to manually switch PHP versions when developing on multiple versions at the same time:

     ```
         <FilesMatch \.(php|phar)$>
             SetHandler "proxy:unix:/var/opt/php/7.4/run/php-fpm/www.sock|fcgi://localhost"
         </FilesMatch>
     ```
   * For the new changes to take effect, restart the docker container:

     ```
     ./developer down
     ./developer up
     ```
4. Add an entry to the `/etc/hosts` file for the new vhost:

   ```
   127.0.0.1	uni-elentra.localhost
   ```
5. Clone the `elentra-1x-me` and `elentra-1x-api` repositories from your remote, for example:

   ```bash
   cd ~/Sites
   git clone git@gitlab.com:MyUni/elentra-1x-me.git uni-elentra-1x-me
   git clone git@gitlab.com:MyUni/elentra-1x-api.git uni-elentra-1x-api
   ```
6. Set up the composer dependencies as per the [Getting Started](/technical/developers/getting-started.md) section.

   ```
   ./developer shell
   cd /var/www/vhosts/uni-elentra-1x-me
   composer install
   npm install
   npm run build
   ```
7. Create an empty database (or optionally import/scrub from staging)

   ```sql
   CREATE DATABASE uni_elentra_auth;
   CREATE DATABASE uni_elentra_me;
   CREATE DATABASE uni_elentra_me_clerkship;
   CREATE DATABASE uni_elentra_cbe;

   GRANT ALL PRIVILEGES ON uni_elentra_auth.* TO elentra;
   GRANT ALL PRIVILEGES ON uni_elentra_me.* TO elentra;
   GRANT ALL PRIVILEGES ON uni_elentra_me_clerkship.* TO elentra;
   GRANT ALL PRIVILEGES ON uni_elentra_cbe.* TO elentra;
   ```
8. Run the setup script by visiting <http://uni-elentra.localhost/>.
   * Update the hostname to be `http://uni-elentra.localhost` instead of the default.
   * Update the database to be `uni_elentra_me`, `uni_elentra_auth`, etc. instead of the defaults.
9. Run the database migrations in the `elentra-1x-me` directory:

   ```
   php elentra migrate --up
   ```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.elentra.org/technical/developers/troubleshooting/creating-a-new-virtual-host.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
