1

Sorry in case this is a noob question but I am new. I was wondering how I can install and use those three and in future maybe even more programs, while all pointing to the same IP. I managed to change ports for apache so i can access both Pi-Hole and the website, but failed to get Nextcloud running, since every request gets forwarded to the Pi-Hole's front page. Any idea what I'm doing wrong?

1
  • Pi-Hole is an DNS sinkhole it is normal , that mean all DNS requests go to Pi-Hole. If you can contact your HTTP apache server, then it's probably one problem side Nexcloud . have you try to configure nexcloud from here ? For installation go to : http://localhost, if you cannot access to this url try: http://127.0.0.1 for bypass DNS request and Pi-Hole
    – Ephemeral
    Commented Dec 12, 2019 at 19:18

2 Answers 2

3

You can do it using tools like docker and docker-compose. Each container has different port. Your will be mapping ports of containers to your host to avoid problems. I am assuming you are using raspberry pi os.

Summary:

  • Install docker
  • Install docker-compose
  • Clone repository
  • Create a file called docker-compose.yml
  • Insert content on that file
  • Run docker-compose
  • Access to apache, nextcloud and pihole

Docker and docker-compose

for docker install:

$ curl -fsSL https://get.docker.com | sh

Add your user to the Docker group (Optional, to avoid using sudo):

$ sudo usermod -aG docker ${USER}

If you ran the previous command, remember to log out and back in for this to take effect!

Test docker:

$ docker version

Now install docker-compose:

$ sudo apt-get install libffi-dev libssl-dev
$ sudo apt install python3-dev
$ sudo apt-get install -y python3 python3-pip
$ sudo pip3 install docker-compose

Already you have the necessary for running the containers.

The next steps, clone a project repository to create by docker-compose the containers:

git clone https://github.com/SensorsIot/IOTstack.git IOTstack
cd IOTstack

Create a file docker-compose.yml:

$ touch docker-compose.yml

and paste the content:

version: '3.6'
services:
  nextcloud:
    volumes:
    - ./volumes/nextcloud/html:/var/www/html

    image: nextcloud
    container_name: nextcloud
    ports:
    - "9321:80"
    restart: unless-stopped
    depends_on:
    - nextcloud_db
    links:
    - nextcloud_db
    networks:
    - iotstack_nw
    - nextcloud_internal
    environment:
    - MYSQL_HOST=nextcloud_db
    - MYSQL_PASSWORD=mySQL_password
    - MYSQL_DATABASE=nextcloud
    - MYSQL_USER=nextcloud

  nextcloud_db:
    environment:
    - MYSQL_ROOT_PASSWORD=root_password
    - MYSQL_PASSWORD=mySQL_password
    - MYSQL_DATABASE=nextcloud
    - MYSQL_USER=nextcloud

    image: linuxserver/mariadb
    container_name: nextcloud_db
    volumes:
    - ./volumes/nextcloud/db:/config
    restart: unless-stopped
    networks:
    - nextcloud_internal

  mariadb:
    environment:
    - MYSQL_ROOT_PASSWORD=root_password
    - MYSQL_PASSWORD=mySQL_password
    - MYSQL_DATABASE=nextcloud
    - MYSQL_USER=nextcloud
    image: linuxserver/mariadb
    container_name: mariadb
    volumes:
    - ./volumes/mariadb/config:/config
    ports:
    - "3306:3306"
    restart: unless-stopped
    networks:
    - iotstack_nw
  portainer-ce:
    container_name: portainer-ce
    image: portainer/portainer-ce
    restart: unless-stopped
    ports:
    - "8000:8000"
    - "9000:9000"
    volumes:
    - /var/run/docker.sock:/var/run/docker.sock
    - ./volumes/portainer-ce/data:/data
  pihole:
    container_name: pihole
    image: pihole/pihole:latest
    restart: unless-stopped
    ports:
    - "5053:53/udp"
    - "5053:53/tcp"
    - "9322:80"
    - "8443:443"
    environment:
    - TZ:America/Chicago
    volumes:
    - ./etc-pihole/:/etc/pihole/
    - ./etc-dnsmasq.d/:/etc/dnsmasq.d/
    dns:
    - 127.0.0.1
    - 1.1.1.1
  apacheserver:
    container_name: apache
    image: httpd:2.4
    restart: unless-stopped
    ports:
    - "9320:80"
    - "9443:443"
    volumes:
    - ./volumes/apache/:/usr/local/apache2/htdocs

networks:
  iotstack_nw: # Exposed by your host.
    # external: true
    name: IOTstack_Net
    driver: bridge
    ipam:
      driver: default
      config:
      - subnet: 10.77.60.0/24
        # - gateway: 10.77.60.1

  iotstack_nw_internal: # For interservice communication. No access to outside
    name: IOTstack_Net_Internal
    driver: bridge
    internal: true
    ipam:
      driver: default
      config:
      - subnet: 10.77.76.0/24
        # - gateway: 10.77.76.1 
  nextcloud_internal: # Network for NextCloud service
    name: IOTstack_NextCloud
    driver: bridge
    internal: true

  # default:
  #   external: true
  #   name: iotstack_nw

  # hosts_nw:
  #   driver: hosts

Now start docker-compose:

$ docker-compose -f docker-compose.yml up -d

You will have an output like this

Creating network "IOTstack_NextCloud" with driver "bridge"
Creating network "IOTstack_Net" with driver "bridge"
Creating network "iotstack_default" with the default driver
Creating pihole       ... done
Creating nextcloud_db ... done
Creating portainer-ce ... done
Creating mariadb      ... done
Creating apache       ... done
Creating nextcloud    ... done

If you want to see the containers running, only run:

$ docker ps

You will see a similar output like this

CONTAINER ID   IMAGE                    COMMAND                  CREATED          STATUS                             PORTS                                                                                             NAMES
xxxxxxxxxxxx   nextcloud                "/entrypoint.sh apac…"   12 seconds ago   Up 8 seconds                       0.0.0.0:9321->80/tcp                                                                              nextcloud
yyyyyyyyyyyy   linuxserver/mariadb      "/init"                  16 seconds ago   Up 11 seconds                      0.0.0.0:3306->3306/tcp                                                                            mariadb
wwwwwwwwwwww   httpd:2.4                "httpd-foreground"       16 seconds ago   Up 11 seconds                      0.0.0.0:9320->80/tcp, 0.0.0.0:9443->443/tcp                                                       apache
vvvvvvvvvvvv   portainer/portainer-ce   "/portainer"             16 seconds ago   Up 11 seconds                      0.0.0.0:8000->8000/tcp, 0.0.0.0:9000->9000/tcp                                                    portainer-ce
nnnnnnnnnnnn   pihole/pihole:latest     "/s6-init"               16 seconds ago   Up 11 seconds (health: starting)   67/udp, 0.0.0.0:5053->53/tcp, 0.0.0.0:5053->53/udp, 0.0.0.0:9322->80/tcp, 0.0.0.0:8443->443/tcp   pihole
ffffffffffff   linuxserver/mariadb      "/init"                  16 seconds ago   Up 12 seconds      

At this point you can access to the different services on your browser:

portainer: to see containers. Need to create admin credentials to finish configuration.
http://localhost:9000 

apache. Need to create an index.html on ./volumes/apache/
http://localhost:9320 

nextcloud. Need to create admin credentials to finish configuration.
http://localhost:9321 

pihole. You can find password typing $ docker logs pihole  or access to container through  $ docker exec -ti apache bash    and inside the container run $ sudo pihole -a -p   to create a new password

http://localhost:9322/admin/ 

If containers are created but you want to eliminate them, only run

$ docker-compose down

Important! I only tested the docker-compose file with nextcloud, portainer and mariadb on my raspberry pi 4 2gb. Apache and pihole was added and tested on desktop pc.

The apps versions running on my rpi are:

  • Nextcloud 20.0.6
  • 10.1.47-MariaDB-0ubuntu0.18.04.1
  • Portainer 2.1.1

Raspberry pi:

  • Linux raspberrypi 5.10.11-v7l+ #1399 SMP Thu Jan 28 12:09:48 GMT 2021 armv7l GNU/Linux

Of course you can change values of docker-compose.yml file according to your requirements.

you can find more information on :

1
  • touch docker-compose.yml I think you meant "nano" or "vi" from context. Nicely done and I've copied the compose file for future reference. Thanks.
    – Ron K.
    Commented Feb 25, 2021 at 1:30
2

I had problems too with NextCloud and Pi-Hole. With NextCloud working, pi-Hole didn't work after installation (in any case the webserver didn't work).

After a complete installation of Pi-Hole (with lighttpd the webserver), I had to change pi-hole's port from 80 to 8080

What didn't work for me:

  • Add the port server configuration in a new file /etc/lighttpd/external.conf
  • Delete external.conf and change port configuration in /etc/lighttpd/lighttpd.conf

What worked:

  • Change port configuration in /etc/lighttpd/lightppd.conf
  • sudo touch /etc/lighttpd/external.conf to create an empty external.conf file

I can now access the server with http://192.168.68.108:8080/admin/or http://pi.hole:8080/admin/ or http://myPiName:8080/admin/

I didn't see any problem between the two functions of my Pi since.

1
  • The problem with this is that the PiHole directs ad lookups to port 80, and expects a blank image or empty page to be served rather than the traffic hitting whatever else you have running on 80.
    – JPhi1618
    Commented Sep 7, 2020 at 4:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.