Debian install PHP and Caddy for Pi-hole

Server environment
1. Debian10 Buster sid

Updated Oct 25, 2019

Install PHP 7.4 PPA

sudo apt -y install lsb-release apt-transport-https ca-certificates 
sudo wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg
echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" | sudo tee /etc/apt/sources.list.d/php.list

Install PHP7.4

// apt install 
apt-get -y install curl php7.4-cli php7.4-fpm php7.4-mysql php7.4-curl php7.4-gd php7.4-intl php-pear php7.4-pspell php7.4-sqlite3 php7.4-tidy php7.4-xmlrpc php7.4-xsl php7.4-mbstring php-gettext

Install Caddy

curl https://getcaddy.com | bash -s personal
// Caddy binary file will store at
/usr/local/bin/caddy

// Change permission
sudo chown root:root /usr/local/bin/caddy 
// permissions 
sudo chmod 755 /usr/local/bin/caddy

Config a site with PHP

// Edit Caddy file
nano /etc/caddy/CaddyFile

https://xx.com:81 {
    root /var/www/html/admin
    log /var/log/caddy/pihole.review.log 
    errors /var/log/caddy/errors.log
    #basicauth / admin password
    tls /etc/letsencrypt/live/xx.com/fullchain.pem /etc/letsencrypt/live/xx.com/privkey.pem
    gzip
	
    fastcgi / /var/run/php/php7.0-fpm.sock php {
        ext .php
        split .php
        index index.php
    }
    rewrite {
		to {path} {path}/ /index.php?page={uri_escaped}
    }
}

Photo by Kobu Agency on Unsplash

References

  1. https://dengxiaolong.com/caddy/zh/example.cmsmadesimple.html
  2. https://computingforgeeks.com/how-to-install-php-7-3-on-debian-9-debian-8/