Skip to content

Instantly share code, notes, and snippets.

@GAS85
Last active May 24, 2024 18:57
Show Gist options
  • Save GAS85/62b8e4851923e5ecec29cbc9b374ab18 to your computer and use it in GitHub Desktop.
Save GAS85/62b8e4851923e5ecec29cbc9b374ab18 to your computer and use it in GitHub Desktop.
Apache2 config for pihole with custom / non-admin link

Prerequisites

Install Pihole

Install pihole from the official repo as described here: https://github.com/pi-hole/pi-hole#one-step-automated-install, e.g. via

curl -sSL https://install.pi-hole.net | bash

During the installation please choose to install Web Interface, but to not install a Web Server.

Setup Apache2

Create Apache2 config for Pihole

Basically if you already have working apache2 config, just create file e.g. 004-pihole.conf in a /etc/apache2/sites-available/ with following content:

LAN Restriced

<IfModule alias_module>
    Alias /admin /var/www/html/admin
    <Directory "/var/www/html/admin">
        AllowOverride None
        Options None
        Order deny,allow
        Allow from 192.168.0.0/24 localhost 127.0.0.1
        #Allow from all
        Deny from all
    </Directory>
</IfModule>

In this case you can only access Pihole from the local network (192.168.0.0/24). If you would like to access from the internet also, please apply following config:

Internet access

<IfModule alias_module>
    Alias /admin /var/www/html/admin
    <Directory "/var/www/html/admin">
        AllowOverride None
        Options None
        Order deny,allow
        #Allow from 192.168.0.0/24 localhost 127.0.0.1
        Allow from all
        #Deny from all
    </Directory>
</IfModule>

Enable config

To enable Apache2 config for pihole please run:

a2ensite 004-pihole.conf

Then test our config and reload apache2 if succeed:

sudo apachectl configtest && sudo service apache2 reload

Finish

Now you can access your pihole via http(s)://YourIP_or_Domain/admin

Changing pihole URL path from /admin to /custom

If you would like to change you path from http(s)://YourIP_or_Domain/admin to e.g. http(s)://YourIP_or_Domain/custom, simply adjust Alias in 004-pihole.conf to expected path:

#Alias /admin /var/www/html/admin
Alias /custom /var/www/html/admin

And added simple rewrite rule (you have to enable apache mod_rewrite via sudo a2enmod rewrite) to your virtual host e.g. default-ssl.conf.

 #Pihole rewrite link from /admin to /pihole.
 RewriteEngine  on
 RewriteRule    "^/admin/(.*)"  "/custom/$2" [R]

Then test our config and reload apache2 if succeed:

sudo apachectl configtest && sudo service apache2 reload

Finish

Now you can access your pihole via http(s)://YourIP_or_Domain/custom

@dotSynergy
Copy link

just a heads up: if you are having trouble saving configuration (see this) just add apache's user to the pihole group.
in my case it was:
sudo usermod -a -G pihole www-data
hope this helped.

@Marcst76
Copy link

Thanks, one remark: "During the installation please choose to not install a Web Interface." That does not make sense because then there is no "/var/www/html/admin"-folder. The web interface needs to be installed. But the subsequent question "Do you wish to install the web server (lighttpd)" should be answered with "no".

@GAS85
Copy link
Author

GAS85 commented May 31, 2021

You right, now it is possible to choice between them. I did update to the docu.

@nehasjains
Copy link

Hello.

I install apache 2 and php for setting up a web server. The web server is working fine. Then I installed Pihole and install Web Interface, but opted not to install a Web Server. After the completion of the setup. I created a pihole.conf in /etc/apache2/sites-available/ folder and paste the text as below

Alias /admin /var/www/html/admin AllowOverride None Options None Order deny,allow Allow from 192.168.0.5/24 localhost 127.0.0.1 #Allow from all Deny from all

after saving the file ran commands

a2ensite pihole.conf
sudo apachectl configtest && sudo service apache2 reload

After this I am able to access the Pihole webadmin from http://192.168.1.5/admin.

The pihole is also working but dashboard is not showing any statics. I can go to query log page and see the pihole is blocking ads etc but why I am not able to see anything in the dashboard.

I have selected to show all information .

Please help.

Hoping for your help and reply

@GAS85
Copy link
Author

GAS85 commented Aug 9, 2021

Hey, @nehasjains
glad that totorial works for you, please check if you install php-sqlite3, e.g. by command apt install php-sqlite3. Ticket for reference: pi-hole/pi-hole#3356 (comment)

@nehasjains
Copy link

Hey, @nehasjains
glad that totorial works for you, please check if you install php-sqlite3, e.g. by command apt install php-sqlite3. Ticket for reference: pi-hole/pi-hole#3356 (comment)

thanks a lot, it worked.... I am really thankful to you for this straight forward tutorial.

How can I contact you for more help on Raspberry Pi ?

@GAS85
Copy link
Author

GAS85 commented Aug 10, 2021

Glad to help, but not sure if I can answer your questions quickly. I'm not the Raspberry expert, there is a big community around it. Also this tutorial was written for Ubuntu, but magic is that Linux is the same, you only have to adopt some points to Raspberry / ARM Processors. Feel free to use this Platform for questions.

@nehasjains
Copy link

Glad to help, but not sure if I can answer your questions quickly. I'm not the Raspberry expert, there is a big community around it. Also this tutorial was written for Ubuntu, but magic is that Linux is the same, you only have to adopt some points to Raspberry / ARM Processors. Feel free to use this Platform for questions.

Thanks.... I am really new to Linux, I must say just 15 days. Can you please guide me how can I control raspberry pi with google/alexa ?

Hoping for your kind guidance.

@GAS85
Copy link
Author

GAS85 commented Aug 11, 2021

Its depends from what you would like to achieve, do you need control Raspberry PI via Alexa, or you want that Raspberry connected to it bidirectional, or you would like to make Alexa from Raspberry?
Check this out:

Personally I use home assistant to control my heaters, lights and curtains updated with Shelly Relays and also controlled centrally.

You can also writ to my private chat here https://cloud.sitnikov.ga/index.php/call/2vnuims3, but I'm on vacation next weeks.

@Torstein-Eide
Copy link

Note that libapache2-mod-php is need, for php to work on apache2. pihole admin page uses php.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment