Installing Pi-hole on Existing Apache Server

I'm adding this here in case anyone else needs it. But mostly so I can "Google" it the next time I install Pi-hole on Apache.

Installing Pi-hole on an existing and working Apache web server on Raspberry Pi. This assumes you have set up your own static IP and whatnot.

  1. Run the Pi-hole install. When you get to "Do you wish to install the web server" select "Off".
  2. Finish the Pi-hole installation process. Do not panic.
  3. Run "sudo usermod -a -G pihole www-data"
  4. Install "sudo apt install php-sqlite3"
  5. At a minimum, restart Apache "sudo service apache2 restart" or reboot the Pi.
  6. Enjoy.
5 Likes

Thank you, this was helpful! Just wanted to add two things in case it helps someone else.

  • If you have Apache but not PHP yet, run sudo apt install php libapache2-mod-php.
  • On a fresh install of Pi-hole v5.3.1 the group membership was already setup (edit: but that's probably because I installed lighttpd).
2 Likes

I am working from a NextCloud install first then installing PiHole afterwards. I had trouble allowing the correct access via different port than 80. I chose 81.

  1. Added it to new pihole.conf in the /etc/apache2/sites-available

sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/pihole.conf

sudo nano /etc/apache2/sites-available/pihole.conf
added or edited the following lines:
<VirtualHost *:81>
DocumentRoot /var/www/html/admin/
<Directory /var/www/html/admin/>

  1. Added a new Listen port in the port.conf

sudo nano /var/apache2/ports.conf
add line:
Listen 81

  1. Whitelisted the directories for pihole specifically in the apache2.conf

sudo nano /var/apache2/ports.conf
add lines at the appropriate spot:
<Directory /var/www/html/pihole/>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted

	<Directory /var/www/html/admin/>
        Options Indexes FollowSymLinks
        AllowOverride None
	    Require all granted
	</Directory>
  1. Finally update the Apache2 config files & restart service

sudo a2ensite pihole
sudo systemctl reload apache2

β€”

Not sure if that was all overkill or I opened it up too much but that I how I got it working on my R-Pi 4.
Documenting it to help out anyone else who was a NOOB like me…

1 Like

I have managed to get the dashboard working by installing the following packages with apache+php8.0

php8.0-sqlite3
php8.0-fpm

You will also need to do
a2enconf php8.0-fpm

1 Like

This last bit did the trick for me. Thank you.

I am running bullseye on a Raspberry Pi 3.

In case someone else needs to know this: since pihole v6, they have moved from using lighttpd to host the web interface to using pihole-FTL itself to host & run it. Hence, it's not possible anymore to host the interface on apache nor lighttpd, because it's not compatible in any way (the web interface files are .lp files instead of .php nowadays).

If you are running any web server on the same installation as pihole, I recommend moving the pihole web interface files from /var/www/html/admin to a different location and then configuring the new file location either with pihole-FTL --config or editing /etc/pihole/pihole.toml. On top of that, you need to edit the same config to change pihole webserver ports to something else than 80/443, as they will conflict with the existing webserver. If I knew these, I'd have saved hours of debugging :sweat_smile:

2 Likes

Good catch! Future travelers, please read this entire thread before you do anything rash!