Skip to content

Instantly share code, notes, and snippets.

@dunderrrrrr
Last active February 21, 2020 13:36
Show Gist options
  • Save dunderrrrrr/3a33e6ae327d1e4f36606655c85dedf5 to your computer and use it in GitHub Desktop.
Save dunderrrrrr/3a33e6ae327d1e4f36606655c85dedf5 to your computer and use it in GitHub Desktop.
Pihole is an incredible easy to use and install AdBlocking Server with an easy to use web interface.

Pihole is an incredible easy to use and install AdBlocking Server with an easy to use web interface. PiHole works by replacing your current DNS server and uses multiple blocklists to block malicious DNS queries and AD Sites.

Begin setting your server on a static IP, guide here.

Install PiHole

$ git clone --depth 1 https://github.com/pi-hole/pi-hole.git Pi-hole
$ cd Pi-hole/automated\ install/
$ ./basic-install.sh

Follow on screen instructions.

Set password for webgui.

$ sudo pihole -a -p

Allow DNS in firewall.

sudo ufw allow http
sudo ufw allow https
sudo ufw allow 53

By default this installation comes with lighttpd, we will uninstall this and manage http and https requests with nginx instead.

$ sudo apt purge lighttpd
$ sudo apt autoremove
$ sudo apt install nginx

PiHole runs PHP, install this.

$ sudo apt-get install php-fpm
$ sudo nano /etc/php/7.2/fpm/php.ini

Set cgi.fix_pathinfo to 0.

cgi.fix_pathinfo=0
$ sudo systemctl restart php7.2-fpm

Set up domain and path to PiHole webgui files.

$ cp /etc/nginx/sites-available/default /etc/nginx/sites-available/yourdomain
$ nano /etc/nginx/sites-available/yourdomain
server {
    listen 80 default_server;
    listen [::]:80 default_server;

    root /var/www/html;
    index index.php index.html index.htm index.nginx-debian.html;

    server_name yourdomain.com;

    location / {
        try_files $uri $uri/ =404;
    }

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/run/php/php7.2-fpm.sock;
    }

    location ~ /\.ht {
        deny all;
    }
}

Activate site.

$ sudo ln -s /etc/nginx/sites-available/yourdomain /etc/nginx/sites-enabled
$ sudo systemctl reload nginx

You should now be all set. Point your router to use this server as DNS.

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