2. Set up your project locally¶
In this section we will build the new project you’ve created in the local development environment; that is, we will set it up on your own computer.
Obtain the project’s slug (its unique ID) from the Dashboard:
Alternatively you can use the
divio command to list your cloud project, which will show their slugs:
divio project list
Build the project locally¶
divio project setup command (for example if your project slug is
divio project setup tutorial-project
The Divio CLI will execute a number of steps - this may take a few minutes, depending on how much needs to be downloaded and processed. The Divio CLI tool will build your project locally (see The deployment process for a more detailed description of what’s happening here). Note that depending on the project, you won’t necessarily see all the intermediate steps here:
Creating workspace cloning project repository [...] downloading remote docker images [...] building local docker images [...] creating new database container [...] syncing and migrating database [...] Your workspace is setup and ready to start.
As well as cloning the repository and attempting to build the project, the
setup command will add a
directory containing some Divio-related configuration that connects it to the Control Panel.
cd into the newly-created project directory, where you will find your project code.
Run the set-up script¶
This step is required as part of the beta implementation of the PHP/Laravel project type, and will be refined in later releases.
You’ll find a script in
divio/setup.php that helps set up the project for local development purposes, and performs
database migrations. Run it with:
docker-compose run web php /app/divio/setup.php
This takes a few minutes. Once complete, you can run your project.
Start the local project¶
Start the project by running
docker-compose up in the terminal:
➜ docker-compose up tutorial-project_database_default_1 is up-to-date Starting tutorial-project_web_1 ... done Attaching to tutorial-project_database_default_1, tutorial-project_web_1 database_default_1 | 2020-07-14 16:38:39+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 5.6.49-1debian9 started. [...] database_default_1 | 2020-07-14 16:44:42 1 [Note] Event Scheduler: Loaded 0 events database_default_1 | 2020-07-14 16:44:42 1 [Note] mysqld: ready for connections. database_default_1 | Version: '5.6.49' socket: '/var/run/mysqld/mysqld.sock' port: 3306 MySQL Community Server (GPL) web_1 | Laravel development server started: http://0.0.0.0:80
Open the project in your web browser by visiting http://127.0.0.1:8000.
(You may notice above that Laravel claims to be running on port 80, not port 8000. It is - but that’s only inside the
docker-compose.yml configuration file is responsible for this port-mapping.)
CONTROL-C will stop the project.
So far, we have used the
docker commands. It’s good to have a basic familiarity
with them and what they do. As you proceed through this tutorial, you may encounter the occasional issue. These
commands will help you when this happens.
divio command is used mainly to manage your local project’s resources and to interact with our Control Panel.
You have already used
divio project setup and
divio project list; you can also use it to do things like push
and pull database and media content. Try:
divio project dashboard
See the Divio CLI reference for more.
docker command is mostly used to manage Docker processes, images and containers (rather than applications as a
whole) and Docker itself. You will rarely need to use it, but it can be useful when you need to understand what Docker
is doing on your machine, or for certain operations.
For example, if you have your project running locally (with
docker-compose up) open a new terminal window to run:
This will show you the Docker processes that are running - you will see something like this (note that the details will differ depending on what you actually have running):
➜ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAME d6007edbaf32 tutorialproject_web "/tini -g -- pytho..." 17 minutes ago Up 8 seconds 0.0.0.0:8000->80/tcp tutorialproject_web_ 27ff3e661027 postgres:9.6 "docker-entrypoint..." 17 minutes ago Up 8 seconds 5432/tcp tutorialproject_db_
In this example, the first container is an instance of the image that you built (when deployed, a similar container will be running in a cloud environment). The second shown here is a Postgres database, running in its own Docker container.
You have already used
docker ps. Try:
docker-compose command is used mainly to control and interact with your local project. You will mostly use it
to start the local project and open a shell in the local web container. You have already used
Just for example, try:
docker-compose run web composer install
This will run the
composer install inside the container (in fact this is one of the commands in the
script you ran earlier).
You have now set up a project in the local environment, and launched it. The next step is to do some further development work in the project, test it, and deploy it to the cloud.