Migrating Pi-Hole from lighttpd to apache

Is this possible? I could have SWORN I saw it done here on the forums, but now that I search it, I cannot find it at all.

I've googled it, but only found:

which mentions to downgrade PH. But I rather not do that.

My end goal is to also turn my RaspPi into a webserver, but I am mainly familiar with Apache and even Nginx. Also, some services I am wanting to reverse proxy into, I have instructions for Apache, but nothing for lighttpd. So the smallest change (I think) is to move PH from lighttpd to apache, rather than move all the services to lighttpd, etc.

Hi,
I am running the apache webserver instead of lighttpd on the pi3 with xbian installed. So yes it is possible to migrate using another webserver.
I did not encounter problems with the functionality of the pi-hole gui.

Only downside is, that if you upgrade pi-hole using the update script, it will automatically install lighttpd.
So after upgrading I run:
sudo apt-get remove lighttpd
to uninstall lighttpd.

Hi,
Is it possible to post your steps into setting the admin dashboard on Apache?

It has been a long time ago since I installed Apache, but the thing is that I already installed it on the Pi before installing pi-hole. I remember that installing Apache was just a standard default install.

  • sudo apt-get install apache2
    I also installed php5 (but only needed if you use php in webpages)
  • sudo apt-get install php5
    Apache uses /var/www/html as default location for your webpages.
    Since pi-hole gets installed in the same directory (in sub-directory pihole), there is nothing extra to be done to use the apache server except from starting it: sudo service apache2 starrt

In the webbrowser I request webpage:
'http://xbian/admin/index.php
or you can use the pi ip-address instead of 'xbian' in the URL.

1 Like

would be a nice feature for the install script where you could select lighttpd or apache i am not sure if thats possible since there is a lighttpd.conf for the pi-hole /etc/lighttpd/lighttpd.conf. but i am sure it has been already discussed just have to look around the internet.

3 Likes

what is the vhost setup though? iirc (haven't looked at it recently), but it had a setup for the admin, and then another for handling of the DNS queries.

We actually had a pull request a whole back to address this, which ice asked the developer to take another look at to update it. Never say never

1 Like

have you been looking for this?

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 $