Installing Drupal with DDEV in Ubuntu

While I was planning to update my front-end skills I was contacted to review my experience using Drupal. The truth is that I did a template a long time ago and I needed to refresh how it works. This blog post is the result, I hope it helps!

Drupal

  1. Guide to install Drupal locally – Dev environment https://www.drupal.org/docs/official_docs/en/_local_development_guide.html Requires: Docker / DDEV – an open source tool for launching local web development environments in minutes. It supports PHP, Node.js, and Python (experimental). https://ddev.readthedocs.io/en/latest/
  2. Other: Linux development environments https://www.drupal.org/docs/develop/local-server-setup/linux-development-environments Note: They suggest using docker instead.
  3. Options https://www.drupal.org/docs/develop/local-server-setup/docker-development-environments/docker-solutions-overview

DDEV doc Install https://ddev.com/get-started/

Requires

  • Docker Community Edition.
  • DDEV install.

You can follow these instructions: https://ddev.readthedocs.io/en/latest/

On my local computer, I had docker podman already installed, so I skipped the docker installation to install DDEV directly. Install this script

https://raw.githubusercontent.com/drud/ddev/master/scripts/install_ddev.sh

Using the command

curl -L https://raw.githubusercontent.com/drud/ddev/master/scripts/install_ddev.sh | bash

Result

[XXX]$ curl -L https://raw.githubusercontent.com/drud/ddev/master/scripts/install_ddev.sh | bash
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  7223  100  7223    0     0  33679      0 --:--:-- --:--:-- --:--:-- 33752
ddev_linux-amd64.v1.21.6.tar.gz: OK
Download verified. Ready to place ddev and mkcert in your /usr/local/bin.
Running "sudo mv  -f ddev mkcert macos_ddev_nfs_setup.sh /usr/local/bin/" Please enter your password if prompted.
Running mkcert -install, which may request your sudo password.'.
The local CA is already installed in the system trust store! đź‘Ť
The local CA is now installed in the Firefox and/or Chrome/Chromium trust store (requires browser restart)! 🦊

ddev is now installed. Run "ddev" and "ddev --version" to verify your installation and see usage.

Config local environment

# Replace my-site-name!
export SITE_NAME=my-site-name
mkdir $SITE_NAME
cd $SITE_NAME
ddev config --docroot web --project-name $SITE_NAME --project-type drupal10 --create-docroot

Note: I chose tico-libros as my site.

This failed, probably because I was using Podman. Message:

[XXX@XXX-Alienware-17-R4 tico-libros]$ ddev config --docroot web --project-name $SITE_NAME --project-type drupal10 --create-docroot
FATA[0000] Unable to get docker context: unable to run 'docker context inspect' - please make sure docker client is in path and up-to-date: exit status 125

I removed podman

apt remove podman

I installed docker following these instructions: https://docs.docker.com/engine/install/ubuntu/

Then try to run the DDEV install and config process again.

Install, got this message:

[XXX@XXX-Alienware-17-R4 Downloads]$ curl -L https://raw.githubusercontent.com/drud/ddev/master/scripts/install_ddev.sh | bash
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  7223  100  7223    0     0  14100      0 --:--:-- --:--:-- --:--:-- 14107
ddev_linux-amd64.v1.21.6.tar.gz: OK
Download verified. Ready to place ddev and mkcert in your /usr/local/bin.
Running "sudo mv  -f ddev mkcert macos_ddev_nfs_setup.sh /usr/local/bin/" Please enter your password if prompted.
[sudo] password for XXX: 
Running mkcert -install, which may request your sudo password.'.
The local CA is already installed in the system trust store! đź‘Ť
The local CA is already installed in the Firefox and/or Chrome/Chromium trust store! đź‘Ť

ddev is now installed. Run "ddev" and "ddev --version" to verify your installation and see usage.

Conffig, again, I’m calling my testing side “tico-libros”

export SITE_NAME=**tico-libros**
mkdir $SITE_NAME
cd $SITE_NAME
ddev config --docroot web --project-name $SITE_NAME --project-type drupal10 --create-docroot

Got this message

[XXX@XXX-Alienware-17-R4 tico-libros]$ ddev config --docroot web --project-name $SITE_NAME --project-type drupal10 --create-docroot
Could not connect to a docker provider. Please start or install a docker provider.
For install help go to: <https://ddev.readthedocs.io/en/latest/users/install/>

Try docker start didn’t work, This requires some options and a container.

Check this one instead https://ddev.readthedocs.io/en/latest/users/install/ddev-installation/ to install DDEV according to current documentation. Same result.

It requires an image, so I used this command to check the existing images on my computer

docker ps -a

I guess I should pull the Ubuntu image, and then run it?

docker pull ubuntu

Result

[XXX@XXX-Alienware-17-R4 tico-libros]$ sudo docker pull ubuntu
Using default tag: latest
latest: Pulling from library/ubuntu
dbf6a9befcde: Pull complete 
Digest: sha256:dfd64a3b4296d8c9b62aa3309984f8620b98d87e47492599ee20739e8eb54fbf
Status: Downloaded newer image for ubuntu:latest
docker.io/library/ubuntu:latest

Now let’s try to run Ubuntu

sudo docker run ubuntu:latest

Okay! seems to be there, now I need to know how to use it to config DDEV

Terminal showing the docker containers I had created so far

DDEV doc indicates that we need to include our user in the docker group, also that we shouldn’t use sudo to run docker or DDEV (Except for the hostname command in DDEV)

sudo usermod -aG docker $USER

Re-star user group setup

newgrp docker

Check if everything works without sudo

docker run hello-world

Automatically start docker on startup

sudo systemctl enable docker.service
sudo systemctl enable containerd.service

To disable that

sudo systemctl disable docker.service
sudo systemctl disable containerd.service

We can have some issues with disk space and dockers logs, so we need to setup logging

https://docs.docker.com/config/containers/logging/json-file/

How to sample

docker run \\
      --log-driver json-file --log-opt max-size=10m \\
      alpine echo hello world

Finally, this worked ddev config so I gave Drupal’s instructions a try again.

ddev config --docroot web --project-name $SITE_NAME --project-type drupal10 --create-docroot

And it worked

Creating a new ddev project config in the current directory (/repos/tico-libros/tico-libros) 
Once completed, your configuration will be written to /repos/tico-libros/tico-libros/.ddev/config.yaml
 
Created docroot at /repos/tico-libros/tico-libros/web 
You have specified a project type of drupal10 but no project of that type is found in /repos/tico-libros/tico-libros/web 
stable: Pulling from library/busybox
2123501b93d4: Pull complete 
Digest: sha256:05a79c7279f71f86a2a0d05eb72fcb56ea36139150f0a75cd87e80a4272e4e39
Status: Downloaded newer image for busybox:stable
docker.io/library/busybox:stable
No settings.php file exists, creating one 
Configuration complete. You may now run 'ddev start'.

Then ddev start / Output

Network ddev_default created 
It looks like you have a new ddev release.
May we send anonymous ddev usage statistics and errors?
To know what we will see please take a look at
<https://ddev.readthedocs.io/en/stable/users/details/opting-in>
Permission to beam up? [Y/n] (yes):

I choose N

Then, it started downloading everything… but got into a new issue

Failed to start tico-libros: Unable to listen on required ports, port 80 is already in use,
Troubleshooting suggestions at <https://ddev.readthedocs.io/en/stable/users/basics/troubleshooting/#unable-listen>

We need to stop any docker containers running right now and restart

ddev poweroff && docker rm -f $(docker ps -aq)

Got this

Container ddev-tico-libros-dba  Removed 
Container ddev-tico-libros-db  Removed 
Container ddev-tico-libros-web  Removed 
Network ddev-tico-libros_default  Removed 
Project tico-libros has been stopped. 
The ddev-ssh-agent container has been removed. When you start it again you will have to use 'ddev auth ssh' to provide key authentication again. 
bc75ac3b7642
bd85331eddad
05da50347b22

I also try to check if it was a port conflict (due to the error message) using this information: https://ddev.readthedocs.io/en/stable/users/usage/troubleshooting/#web-server-ports-already-occupied

sudo gedit .ddev/config.yaml
.ddev yaml config file

Adjusting port 80 to 8080, and 43 to 8443

After stopping docker it required to authenticate again by running ddev auth ssh

Result

Network ddev_default created 
Container ddev-ssh-agent  Started 
ssh-agent container is running: If you want to add authentication to the ssh-agent container, run 'ddev auth ssh' to enable your keys. 
Enter passphrase for bitbucket: 
Identity added: bitbucket (xxx@gmail.com)
Identity added: github (xxx@gmail.com)

Then ddev start

[XXX@XXX-Alienware-17-R4 tico-libros]$ ddev start
Starting tico-libros... 
Network ddev-tico-libros_default  Created 
Container ddev-tico-libros-dba  Started 
Container ddev-tico-libros-web  Started 
Container ddev-tico-libros-db  Started 
Container ddev-router  Started

Got “403 Forbidden”, quick research shows that it could be that the ROOT is not mounted or the project is mounted but there is no index.php or index.html in the docroot (or it is misconfigured).

Browser with a 403 forbidden nginx error message

According to the documentation is an expected behavior when is empty https://ddev.readthedocs.io/en/latest/users/usage/faq/#performance-troubleshooting

Tip! Want to check the ddev root folder? ddev ssh you sort of “connect” to that server file system, you can logout with exit

Location: https://tico-libros.ddev.site:8443/

After adding a index.html or index.php to the /web folder it worked.

Drupal installation

To execute the command, we should always use composer.

ddev composer create "drupal/recommended-project"

Done!

Drupal installation User Interface

Install dush

ddev composer require drush/drush

Use dush to install Drupal, adjust the password

ddev drush site:install --account-name=admin --account-pass=my-password

Note: During the installation, you will find warnings letting you know that the tables are going to be removed, and so on. This shouldn’t be a concern if you are creating a Drupal site for the first time.

The install.php page letting me know that drupal is already installed.

Launch the new Drupal and login

ddev launch
Welcome page, this is the Drupal site already installed and active.

Want to check the URL of your site?

ddev describe

Output

Clearly, this installation requires hardening.

Themes

https://www.drupal.org/project/project_theme

Links