Migrating Pi-Hole from lighttpd to apache

well its still a bit hell of work and requires many tests. i am looking forward to it.

I know there are people who have switched to Apache. You could try looking at the DietPi fork (not maintained by the Pi-hole team) as that uses Apache. It might help give you some clues.

We are working to develop Pi-hole so it can be used with your choice of Web server and/or resolver.

1 Like

Awesome! I hope you will add NGINX support too. Also I am looking for some info on how to host a website side-by-side with pi-hole. As far as I know it is not possible to host any site on localhost:80 when using pi-hole, or am I wrong? I guess it would be possible to user port 443 for other sites.

1 Like

You can use lighttpd on a different port and it will play nice.

Thanks, it works great! I wrote a little script to change the port:

#!/bin/bash

if (whiptail --title "Change Pi-hole port" --yesno "Do you want to change the port pi-hole uses?" 8 78) then
  PORT_PIHOLE="89"
  PORT_PIHOLE=$(whiptail --inputbox "Which port you do you want to use for Pi-hole?" 8 78 $PORT_PIHOLE --title "Pi-hole Port" 3>&1 1>&2 2>&3)
  sed -i "s/server.port                 = 80/server.port                 = $PORT_PIHOLE/" /etc/lighttpd/lighttpd.conf
  service lighttpd restart
fi

I just installed pihole on ubuntu server and because I already use Apache & PHP I uninstalled lighttpd.
I have several virtual sites on Apache so I added also pihole; all work without problems.

Here it is my config if anybody need to replicate for his use:
edit: /etc/apache2/sites-available/000-default.conf

#=== pihole WEBSITE ===

<VirtualHost *:80>
        ServerAdmin webmaster@localhost
        ServerName pihole
        ServerAlias pi.hole

        DocumentRoot /var/www/html/dns
        <Directory /var/www/html/dns/>
                Options FollowSymLinks MultiViews
                AllowOverride all
                Order deny,allow
                allow from all
        </Directory>

        ErrorLog ${APACHE_LOG_DIR}/pihole_error.log
        LogLevel warn
        CustomLog ${APACHE_LOG_DIR}/pihole_access.log combined
</VirtualHost>

#=== site1 WEBSITE ===

<VirtualHost *:80>
        ServerAdmin webmaster@localhost
        ServerName site1

        DocumentRoot /var/www/html/site1
        <Directory /var/www/html/site1/>
                Options FollowSymLinks MultiViews
                AllowOverride all
                Order deny,allow
                Deny from all
                allow from 127.0.0.1
                allow from 10.22.22.0/24
        </Directory>

        ErrorLog ${APACHE_LOG_DIR}/site1_error.log
        LogLevel warn
        CustomLog ${APACHE_LOG_DIR}/site1_access.log combined
</VirtualHost>

#==== site2 WEBSITE ====

<VirtualHost *:80>
        ServerAdmin webmaster@localhost
        ServerName webtv

        DocumentRoot /var/www/html/site2
        <Directory /var/www/html/site2/>
                Options FollowSymLinks MultiViews
                AllowOverride all
                Order deny,allow
                Deny from all
                allow from 10.22.22.0/24
                allow from 127.0.0.1
        </Directory>

        ErrorLog ${APACHE_LOG_DIR}/site2_error.log
        LogLevel warn
        CustomLog ${APACHE_LOG_DIR}/site2_access.log combined

</VirtualHost>

edit your server hosts file so you can access any website you need from server,
( if you host your custom files for blocking):

/etc/hosts

127.0.0.1       localhost
127.0.1.1       ubuntu1
127.0.1.2       pihole
127.0.1.3       site1
127.0.1.4       site2

10.22.22.16 site1
10.22.22.16 site2
10.22.22.16 pihole
10.22.22.16 ubuntu1

copy all web files for pihole ( move it from /var/www/html/ ) and also content from pihole in dns:
it will look like this:

/var/www/html/dns/admin/...
/var/www/html/dns/pihole/...
/var/www/html/dns/blockingpage.css
/var/www/html/dns/index.js
/var/www/html/dns/index.php
/var/www/html/site1/...
/var/www/html/site2/...

If I did not forgot something this is all you need to change to have pihole working in Apache, so now reload/restart apache.

1 Like

To add to @speedyq post, one also needs to install package 'libapache2-mod-php5' to get php to work with apache:
sudo apt-get libapache2-mod-php5

In Apache 2.4 and later, one should replace

Order deny,allow
allow from all

With

Require all granted

Otherwise an error will be thrown.

where can I change this script?

how to overwrite the file?

image

It will show this error
image

You need to launch the editor with sudo.

Something like sudo gedit or what ever your editor is. Looks like Leafpad possibly.

If this is something that needs to be fixed for your project, just change the lighttpd listening port. You will not see the blocking page and you will have to change the address for the admin page to that chosen port but it will still use the DNS blocking.

I dont know what is the command actually, is it true?

I cant edit 000-default.conf file

pi@raspberrypi:/etc/apache2/sites-available $ cd 000-default.conf
-bash: cd: 000-default.conf: Not a directory
pi@raspberrypi:/etc/apache2/sites-available $

This is way outside the Pi-hole support. You need to do some research into basic linux commands. cd means change directory, and you can't cd into a file.

2 Likes

Here is a nice cheat sheet for a bunch of distro's though they are not the basic Linux commands :wink:

https://www.linuxcounter.net/toolbox/

Some other options like Nginx which seems to perform better than lighthttpd on raw performance and Caddy with SSL out-of-the-box might worth a shot with pi-hole.

1 Like

Thanks for the guide. After pointing to the correct Pi-hole web folder, apache2 can serve the pi hole admin console now. However, on the console, the web api version is missing. Only showing dev().
When doing sudo pihole -up, it shows web admin component is missing.
Any idea how to get this fixed?
And I believe in the lighthttpd config there’s error page redirect setting for ad block page. How to migrate that setting to Apache? Thanks.

I'm not quite sure I understand the moving part. Those directories are indeed where the Pihole script installed PiHole. Well, almost:
[root@galactica html]# ll

total 12
drwxr-xr-x 7 root root 4096 May 23 23:04 admin
-rw-r--r-- 1 lighttpd lighttpd 13 May 11 13:19 custom_disable_timer
drwxr-xr-x 2 root root 4096 May 23 23:04 pihole

You reference the /var/www/html/dns (instead of pihole) as the Document Root in your configuration. Where are you moving these directories/files to, and do you need to modify the .conf file afterwards?

I tried following the steps, but I'm not able to get it working quite yet on Fedora 29.

For the record, my Apache installation seems a bit different. Instead of one master 000-default.conf file, there are individual files for each web server, so for example, 1001-xyz.conf, 1002-abc.conf, 1005-pihole.conf.

I'm running:

[root@galactica html]# httpd -v
Server version: Apache/2.4.34 (Fedora)
Server built: Jul 20 2018 10:44:54

[root@galactica html]# php --version
PHP 7.1.23 (cli) (built: Oct 9 2018 15:37:35) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2018 Zend Technologies

Hi spedyq,

thanks a lot! You saved my day! :slight_smile: it was enough to just remove lighttpd and start apache. Then you could still start pi-hole with (locally) http://127.0.0.1/admin (for pi-hole) or http://127.0.0.1/cacti (for Cacti Monitoring).

Thanks.

Hi mr_master,

Good you got it working.
Also what helped me is running pihole -d from command line.
It will show you where you have differences with the default (lighttpd) setup; nothing to be worried about!

1 Like

Hi msatter,

You are right, it was just an example for my case. http://pi.hole/admin would be the correct one. Therefore I wrote (locally) before.

Regards.