`_ file. We can do it
with ``sh -c "echo '127.0.0.1 qgis.demo' >> /etc/hosts"``.
Replace ``127.0.0.1`` with the IP of your server.
.. note::
Remember that both the :file:`myhost.conf` and :file:`/etc/hosts` files should
be configured for our setup to work.
You can also test the access to your QGIS Server from other clients on the
network (e.g. Windows or Macos machines) by going to their :file:`/etc/hosts`
file and point the ``myhost`` name to whatever IP the server machine has on the
network. You can be sure that that specific IP is not ``127.0.0.1`` as that's
the local IP, only accessible from the local machine. On ``*nix`` machines the
:file:`hosts` file is located in :file:`/etc`, while on Windows it's under
the :file:`C:\\Windows\\System32\\drivers\\etc` directory. Under Windows you
need to start your text editor with administrator privileges before opening
the hosts file.
We can test one of the installed qgis servers with a http request from command
line with ``curl http://qgis.demo/cgi-bin/qgis_mapserv.fcgi`` which
should output:
.. code-block:: xml
Service unknown or unsupported
.. note::
curl can be installed with ``apt install curl``.
Apache is now configured.
Also, from your web browser you can check the capabilities of the server:
http://qgis.demo/cgi-bin/qgis_mapserv.fcgi?SERVICE=WMS&VERSION=1.3.0&REQUEST=GetCapabilities
|moderate| |FA| Create another virtual host
-------------------------------------------------------------------------------
Let's create another Apache virtual host pointing to QGIS Server. You can
choose whatever name you like (``coco.bango``, ``super.duper.training``,
``example.com``, etc.) but for simplicity sake we're going to use ``myhost``.
* Let's set up the ``myhost`` name to point to the localhost IP by adding
``127.0.0.1 x`` to the :file:`/etc/hosts` with the following command:
``sh -c "echo '127.0.0.1 myhost' >> /etc/hosts"`` or by manually
editing the file with ``gedit /etc/hosts``.
* We can check that ``myhost`` points to the localhost by running in the terminal
the ``ping myhost`` command which should output:
.. code-block:: bash
qgis@qgis:~$ ping myhost
PING myhost (127.0.0.1) 56(84) bytes of data.
64 bytes from localhost (127.0.0.1): icmp_seq=1 ttl=64 time=0.024 ms
64 bytes from localhost (127.0.0.1): icmp_seq=2 ttl=64 time=0.029 ms
* Let's try if we can access QGIS Server from the ``myhost`` site by doing:
``curl http://myhost/cgi-bin/qgis_mapserv.fcgi`` or by accessing the url from
your Debian box browser. You will probably get:
.. code-block:: html
404 Not Found
Not Found
The requested URL /cgi-bin/qgis_mapserv.fcgi was not found on this server.
Apache/2.4.25 (Debian) Server at myhost Port 80
* Apache doesn't know that he's supposed to answer requests pointing to the server
named ``myhost``. In order to setup the virtual host the simplest way would
be to make a ``myhost.conf`` file in the :file:`/etc/apache2/sites-available`
directory that has the same content as :file:`qgis.demo.conf` except
for the ``ServerName`` line that should be ``ServerName myhost``. You could
also change where the logs go as otherwise the logs for the two virtual hosts
would be shared but this is optional.
* Let's now enable the virtual host with ``a2ensite myhost.conf``
and then reload the Apache service with ``service apache2 reload``.
* If you try again to access the http://myhost/cgi-bin/qgis_mapserv.fcgi url
you'll notice everything is working now!
|IC|
-------------------------------------------------------------------------------
You learned how to install different QGIS Server versions from packages,
how to configure Apache with QGIS Server, on Debian based Linux distros.
|WN|
-------------------------------------------------------------------------------
Now that you've installed QGIS Server and it's accesible through the HTTP
protocol, we need to learn how to access some of the services it can offer.
The topic of the next lesson is to learn how to access QGIS Server WMS services.
.. Substitutions definitions - AVOID EDITING PAST THIS LINE
This will be automatically updated by the find_set_subst.py script.
If you need to create a new substitution manually,
please add it also to the substitutions.txt file in the
source folder.
.. |FA| replace:: Follow Along:
.. |IC| replace:: In Conclusion
.. |LS| replace:: Lesson:
.. |WN| replace:: What's Next?
.. |moderate| image:: /static/global/moderate.png