How to install Pi-hole with Apache on CentOS 7
Installing Pi-hole on a CentOS 7 server (instead of a dedicated machine like a Raspberry Pi) is an option that the fine gentlemen who developed it gave us. Since I already had a server ready with Apache, I took that route.
I have a small Optiplex 3040 that I use as my home server (you can read more about what I use here) and decided that I’ve had enough with ads showing up on my devices. On my desktop and laptop I use uBlock Origin but my other devices don’t have that luck. Enter Pi-hole!
It’s actually quite easy to install it using Apache (the default setup is even easier, and well documented). It goes like this:
- Setup your server with a static IP. That is out of the scope of this post but you can find out instructions for CentOS 7 here.
- Run the install script as root:
- If you got the chills from the previous command, I understand perfectly. You shouldn’t run scripts directly from the internet. Check the script before you do it. You can find it here.
- The relevant question of the script is if you want to install the lighttpd web server. You should answer *no* at this step.
- Now that the setup is over, proceed to install Apache and some necessary software for Pi-hole:
yum install httpd php php-pdo.
- Edit the file /etc/sudoers.d/pihole and replace lighttpd with apache.
- Set SELinux to permissive (unfortunately it seems that Pi-hole doesn’t work too well with it). You shouldn’t do this if you don’t trust the security of your server or your network. Edit the file /etc/sysconfig/selinux and replace enforcing with permissive.
- That should do it! Reboot your server just to ensure everything is fine and go to http://YOUR_STATIC_IP/admin to check your new Pi-hole installation.
There are a few more things you can do, like setting up a Name-based Virtual Host:
- Create a new configuration file on /etc/httpd/conf.d/router.home.example.com.conf
Insert the following example (adapt it to your use):
<VirtualHost *:80> ServerName router.home.example.com DocumentRoot /var/www/html/admin </VirtualHost>
Restart the Apache daemon:
systemctl restart httpd
You should now be able to access your Pi-hole dashboard using the name router.home.example.com. This assumes you have your own DNS Server at home. I’ll make a post about setting up one, but for now, you can look here for instructions.