How to Install Caddy Web Server on CentOS 7?

By on January 22nd, 2018

How to Install Caddy Web Server on CentOS 7?

Caddy is a new an open source webserver. it is very user-friendly and simple. One of Caddy’s most
notable features is enabling HTTPS by default. If you’re dealing with very high traffic, nginx or apache is
the best choice. For anything else, I think Caddy has the better feature set while also being easier to
configure.

1) Update all available packages on the server using the below command.
# yum clean all
# yum -y update

2) Simply install Caddy server using the below script.
# curl -s https://getcaddy.com | bash

After finishing the script, the caddy server is installed on the server. You can verify the same by
running the below command.
# which caddy

3) Create a user named caddy using the below command.
# adduser -r -d /var/www -s /sbin/nologin caddy

4) Create a directory for hosting caddy files.
# mkdir /etc/caddy

5) Change the user owner to the root user.
# chown -R root:caddy /etc/caddy

6) Install Caddy as a System Service using the following command.
# curl -s https://raw.githubusercontent.com/mholt/caddy/master/dist/init/linux-
systemd/caddy.service -o /etc/systemd/system/caddy.service

 

7) Open the caddy service file and make the changes as below.
# vi /etc/systemd/system/caddy.service
; User and group the process will run as.
User=caddy
Group=caddy

8) Restart and enable caddy service to enable the changes.
# systemctl daemon-reload
# systemctl enable caddy.service
# systemctl status caddy.service

9) Create a test web page for caddy so that we can test it after the installation.
# /var/www/index.html
<h1>Hello World!</h1>

10) Open caddy file and add the below code to it.
# vi /etc/caddy/Caddyfile
http:// {
root /var/www
gzip
}
The above code will help the caddy to bind the HTTP port 80.

11) At last you need to start and enable caddy service.

# systemctl start caddy
# systemctl enable caddy

12) Adding both the HTTP and HTTPS service to server firewall.
# firewall-cmd — permanent — zone=public — add-service=http
# firewall-cmd — permanent — zone=public — add-service=https
# firewall-cmd –reload

That is how we can install caddy webserver on centos7.

Leave a Reply