devilbox/docs/getting-started/create-your-first-project.rst

329 lines
11 KiB
ReStructuredText
Raw Normal View History

2018-03-10 21:29:15 +00:00
*************************
Create your first project
*************************
2018-03-11 13:57:10 +00:00
.. note::
This section not only applies for one project, it applied for as many projects as you need.
**There is no limit in the number of projects.**
.. _prerequisites:
Prerequisites
=============
.. important::
The prerequisites section only provides you some theoretical, but useful insights about how
it all works together. You should at least read it once to be able to debug any problems you
might encounter.
If you have read it already, jump directly to :ref:`project_creation_workflow`
Data directory
--------------
By default all your projects must be created in the ``./data/www/`` directory which is inside in
your Devilbox git directory. This can be changed as well, but is outside the scope of this
*getting started tutorial*.
You can verifiy that the path is actually ``./data/www/`` by checking your ``.env`` file:
.. code-block:: bash
host> grep HTTPD_DATADIR .env
HOST_PATH_HTTPD_DATADIR=./data/www
2018-03-15 08:09:42 +00:00
Project directory
-----------------
The project directory is a directory directly within the data directory.
**This represents one project.**
By creating this directory, the web server will create a new virtual host for you. This
happens fully automated and there is nothing else required to do except just to create a directory.
The name of this directory will also be used to build up the final project url together with the
domain suffix: ``http://<project directory>.<domain suffix>``
Create as many project directories as you require.
2018-03-11 13:57:10 +00:00
Docroot directory
-----------------
The docroot directory is a directory within each project directory from which the webserver will serve the files.
By default this directory must be named ``htdocs``. This can be changed as well, but is outside
the scope of this *getting started tutorial*.
You can verifiy that the docroot directory is actually ``htdocs`` by checking your ``.env`` file:
.. code-block:: bash
host> grep DOCROOT_DIR .env
HTTPD_DOCROOT_DIR=htdocs
2018-03-15 08:09:42 +00:00
2018-03-11 13:57:10 +00:00
Domain suffix
-------------
The default domain suffix (``TLD_SUFFIX`` variable in ``.env`` file) is ``loc``. That means that
all your projects will be available under the following address: ``http://<project-directory>.loc``.
This can be changed as well, but is outside the scope of this *getting started tutorial*.
You can verifiy that the suffix is actually ``loc`` by checking your ``.env`` file:
.. code-block:: bash
host> grep ^TLD_SUFFIX .env
TLD_SUFFIX=loc
2018-03-15 08:09:42 +00:00
Making sense of it
------------------
2018-03-11 13:57:10 +00:00
2018-03-15 08:09:42 +00:00
Ok, let's sum it up and make sense of the previously provided information. To better illustrate
the behaviour we are going to use ``project-1`` as our project directory name.
2018-03-11 13:57:10 +00:00
2018-03-15 08:09:42 +00:00
+---------------+---------------------------------+-------------------------------------------------------------+
| Item | Example | Description |
+===============+=================================+=============================================================+
| data dir | ``./data/www`` | Where all of your projects reside. |
+---------------+---------------------------------+-------------------------------------------------------------+
| project dir | ``./data/www/project-1`` | A single project. It's name will be used to create the url. |
+---------------+---------------------------------+-------------------------------------------------------------+
| docroot dir | ``./data/www/project-1/htdocs`` | Where the webserver looks for files within your project. |
+---------------+---------------------------------+-------------------------------------------------------------+
| domain suffix | ``loc`` | Suffix to build up your project url. |
+---------------+---------------------------------+-------------------------------------------------------------+
| project url | ``http://project-1.loc`` | Final resulting project url. |
+---------------+---------------------------------+-------------------------------------------------------------+
2018-03-11 13:57:10 +00:00
2018-03-15 08:09:42 +00:00
**data dir**
2018-03-11 13:57:10 +00:00
2018-03-15 08:09:42 +00:00
This directory is mounted into the ``httpd`` and ``php`` container, so that both know where all projects can be found. This is also the place where you create ``project directories`` for each of your projects.
2018-03-11 13:57:10 +00:00
2018-03-15 08:09:42 +00:00
**project dir**
2018-03-11 13:57:10 +00:00
2018-03-15 08:09:42 +00:00
Is your project and used to generate the virtual host together with the domain suffix.
2018-03-11 13:57:10 +00:00
2018-03-15 08:09:42 +00:00
**docroot dir**
2018-03-11 13:57:10 +00:00
2018-03-15 08:09:42 +00:00
A directory inside your ``project dir`` from where the webserver will actually serve your files.
2018-03-11 13:57:10 +00:00
2018-03-15 08:09:42 +00:00
**domain suffix**
2018-03-11 13:57:10 +00:00
2018-03-15 08:09:42 +00:00
Used as part of the project url.
.. note::
The projcet directory will be discussed in more detail in :ref:`project_creation_workflow` below.
2018-03-11 13:57:10 +00:00
.. _project_creation_workflow:
Project creation workflow
=========================
Step 1: visit Intranet vhost page
---------------------------------
Before starting, have a look at the vhost page at http://localhost/vhosts.php
It should look like the screenshot below and will actually already provide the information needed to create a new project.
.. image:: /_static/img/devilbox-vhosts-empty.png
Step 2: create a project directory
----------------------------------
In your Devilbox git directory, navigate to ``./data/www`` and create a new directory.
.. note::
Choose the directory name wisely, as it will be part of the domain for that project.
For this example we will use ``project-1`` as our project name.
.. code-block:: bash
# navigate to your Devilbox git directory
host> cd path/to devilbox
# navigate to the data directory
host> cd data/www
# create a new project directory named: project-1
host> mkdir project-1
Vist the vhost page again and see what has changed: http://localhost/vhosts.php
.. image:: /_static/img/devilbox-vhosts-directory.png
**So what has happened?**
By having created a project directory, the web server container has created a new virtual host. However it has noticed, that the actual document root directory does not yet exist and therefore it cannot serve any files yet.
Step 3: create a docroot directory
----------------------------------
.. note::
As desribed in :ref:`prerequisites` the docroot directory name must be ``htdocs`` for now.
Navigate to your newly created project directory and create a directory named `htdocs` inside it.
.. code-block:: bash
# navigate to your Devilbox git directory
host> cd path/to devilbox
# navigate to your above created project directory
host> cd data/www/project-1
# create the docroot directory
host> mkdir htdocs
Vist the vhost page again and see what has changed: http://localhost/vhosts.php
.. image:: /_static/img/devilbox-vhosts-dns.png
**So what has happened?**
By having created the docroot directory, the web server is now able to serve your files. However it has noticed, that you have no way yet, to actually visit your project url, as no DNS record for it exists yet.
The intranet already gives you the exact string that you can simply copy into your ``/etc/hosts`` file on your host operating system to solve this issue.
.. important::
This will only work on **native Docker** for Linux or MacOS. Read up on the next section to also find out how to do that on **Docker Toolbox** and Windows.
Step 4: create a DNS entry
--------------------------
.. note::
This step can also be automated via the bundled DNS server to automatically provide catch-all
DNS entries to your host computer, but is outside the scope of this
*getting started tutorial*.
Add DNS for Linux and MacOS (native Docker)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
On Linux and MacOS (when using the native Docker), this step is fairly simple. The intranet provides
you the exact string you need to paste into your ``/etc/hosts`` file on your host operating system.
.. code-block:: bash
# Open your /etc/hosts file with sudo or root privileges
# and add the following DNS entry
host> sudo vi /etc/hosts
127.0.0.1 project-1.loc
Add DNS for Windows (native Docker)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
On Windows (when using the native Docker), you can also copy paste the command provided by the intranet,
however the destination file is different. You have to add this string into: ``C:\Windows\System32\drivers\etc``.
Open ``C:\Windows\System32\drivers\etc`` with admistrative privileges and add the following entry
.. code-block:: bash
127.0.0.1 project-1.loc
Add DNS for Docker Toolbox
^^^^^^^^^^^^^^^^^^^^^^^^^^
When using ``Docker Toolbox`` the Devilbox runs inside a virtual machine and therefore the Webserver port (``80``)
is not exposed to your host operating system. So your DNS record must point to the virtual machine instead of your
host system.
1. Find out the IP address the virtual machine is running on
2. Add a DNS entry to your host operating system for this IP address.
For the sake of this example, let's assume the virtual machine is running on ``192.16.0.1``, then the DNS record you will
have to add instead on your host operating system is:
**Docker Toolbox on MacOS**
.. code-block:: bash
host> sudo vi /etc/hosts
192.16.0.1 project-1.loc
**Docker Toolbox on Windows**
Open ``C:\Windows\System32\drivers\etc`` with admistrative privileges and add the following entry
.. code-block:: bash
192.16.0.1 project-1.loc
Back to intranet
^^^^^^^^^^^^^^^^
Vist the vhost page again and see what has changed: http://localhost/vhosts.php
.. image:: /_static/img/devilbox-vhosts-finished.png
**So what has happened?**
By having created the DNS record, the Devilbox intranet is aware that everything is setup now and
gives you a link to your new project.
2018-03-11 16:51:22 +00:00
Step 5: Visit your project
2018-03-11 13:57:10 +00:00
--------------------------
On the intranet, click on your project link. This will open your project in a new Browser tab or
visit http://project-1.loc
.. image:: /_static/img/devilbox-project-no-files.png
**So what has happened?**
Everything is setup now, however the webserver is trying to find a ``index.php`` file in your document root which does not yet exist.
So all is left for you to do is to add your HTML or PHP files.
2018-03-11 16:51:22 +00:00
Step 6: Create a hello world
2018-03-11 13:57:10 +00:00
----------------------------
Navigate to your docroot directory within your project and create a ``index.php`` file with some output.
.. code-block:: bash
# navigate to your Devilbox git directory
host> cd path/to devilbox
# navigate to your projects docroot directory
host> cd data/www/project-1/htdocs
# Create a hello world index.php file
host> echo "<?php echo 'hello world';" > index.php
Alternatively create an ``index.php`` file in ``data/www/project-1/htdocs`` with the following contents:
.. code-block:: php
<?php echo 'hello world';
Vist your project url again and see what has changed: http://project-1.loc
.. image:: /_static/img/devilbox-project-hello-world.png
Checklist
=========
1. :ref:`prerequisites` are read and understood
2018-03-11 16:51:22 +00:00
2. Project directory is created
3. Docroot directory is created
2018-03-11 13:57:10 +00:00
4. DNS entry is added to the host operating system
5. PHP files are added to your docroot directory