How To Install Caddy on AlmaLinux 9

Everything Linux, A.I, IT News, DataOps, Open Source and more delivered right to you.
Subscribe
"The best Linux newsletter on the web"

In this article, we will show you how to install Caddy on your AlmaLinux Systems.

Caddy is a powerful, enterprise-ready, open source web server with automatic HTTPS written in Go. It is an ultimate server. It simplifies your infrastructure. Also, it takes care of TLS certificate renewals, OCSP stapling, static file serving, reverse proxying, Kubernetes ingress, and more.

Its modular architecture means you can do more with a single, static binary that compiles for any platform.

Caddy runs great in containers because it has no dependencies—not even libc. Run Caddy practically anywhere.

Install Caddy on AlmaLinux:

Follow the steps below to get started with Caddy:

  • Update your AlmaLinux system packages with running the below command:
sudo dnf clean all && sudo dnf update
sudo dnf groupinstall "Development Tools"
sudo dnf install epel-release -y
  • Caddy package is available on AlmaLinux base repository. So You can install it directly via installing required packages first with the below commands:
sudo dnf install 'dnf-command(copr)'
sudo dnf copr enable @caddy/caddy
  • Then install it as follows:
sudo dnf install caddy
  • Start and enable the Caddy service as follows
sudo systemctl start caddy
sudo systemctl enable caddy
  • Check the status of Caddy Service as shown below
sudo systemctl status caddy 
  • Check the caddy version by running the following command
caddy -v
  • Add the HTTP and HTTPS ports to the firewall as follows
sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https
sudo systemctl reload firewalld

Access Caddy web server

  • Access Caddy web server by opening your favorite browser and access the Caddy using the URL below:

http://localhost

Enable PHP on Caddy Web Server

  • Install PHP, PHP-FPM and other required packages to your server by running the below command:
sudo dnf install php-fpm php-gd php-cli -y
  • Create a directory and give the appropriate permissions to it :
mkdir -p /var/www/example.com
chown caddy:caddy /var/www/example.com
chown caddy:caddy /var/log/caddy
  • Edit the Caddy configuration file:
sudo vim /etc/caddy/Caddyfile

Then add the following:

80 {
        root * /var/www/example.com
	php_fastcgi unix//run/php-fpm/www.sock
        file_server
        encode gzip

        log {
             	output file /var/log/caddy/example.access.log
        }

	@static {
                file
                path *.ico *.css *.js *.gif *.jpg *.jpeg *.png *.svg *.woff *.pdf *.webp
        }
	header @static Cache-Control max-age=5184000

}
  • After that, edit the PHP-FPM file as follow:
sudo vim /etc/php-fpm.d/www.conf

Change the following parameters:

user = caddy
group = caddy
listen.acl_users = apache,nginx,caddy
  • Start and enable the PHP-FPM service
sudo systemctl start php-fpm && sudo systemctl enable php-fpm
  • Create info.php page:
sudo vim /var/www/example.com/info.php

Then add the following:

<?php phpinfo();
?>
  • Finally, open your fav browser and access the info.php page using the URL http://localhost/info.php as shown below:

How to Remove (Uninstall) Caddy

  • Remove Caddy by running the command below:
 sudo dnf remove caddy -y

Install Caddy on AlmaLinux -Conclusion

That’s it

Thanks.

Everything Linux, A.I, IT News, DataOps, Open Source and more delivered right to you.
Subscribe
"The best Linux newsletter on the web"
MQ-Jr
MQ-Jr
unixcop Admin

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest articles

Join us on Facebook