How to Install Caddy on Rocky Linux 8
Tags: neutroncloud, rockylinux, caddy, linux
Published: 2021-09-12 09:27:56

<!-- wp:paragraph -->
<p>In this article, we'll explain you how to install Caddy on Rocky Linux 8.&nbsp; Host your website on Caddy web server.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>The <a href="https://caddyserver.com/" target="_blank" rel="noreferrer noopener">Caddy web server</a> is an open-source web server written in Go. It is designed around simplicity and security that comes with a number of features that are useful for hosting websites. Caddy is both a flexible, efficient static file server and a powerful, scalable reverse proxy.</p>
<!-- /wp:paragraph -->

<!-- wp:heading {"level":4} -->
<h4>Prerequisites</h4>
<!-- /wp:heading -->

<!-- wp:list -->
<ul><li>A Rocky Linux 8 installed <a class="rank-math-link" href="https://neutroncloud.in/pricing.html">cloud instance</a>.</li><li>A root user access or normal user with administrative privileges.</li></ul>
<!-- /wp:list -->

<!-- wp:html -->
<a href="https://neutroncloud.in/docs/how-to-install-caddy-on-rocky-linux-8/">Install Caddy on Rocky Linux 8</a>
<!-- /wp:html -->

<!-- wp:heading {"level":4} -->
<h4>1. Keep the server up to date</h4>
<!-- /wp:heading -->

<!-- wp:quote -->
<blockquote class="wp-block-quote"><p># dnf update -y</p></blockquote>
<!-- /wp:quote -->

<!-- wp:heading {"level":4} -->
<h4>2. Install Caddy</h4>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>Following command will install and automatically starts and runs Caddy for you as a systemd service named <em>caddy</em> using our official <em>caddy.service</em> unit file.</p>
<!-- /wp:paragraph -->

<!-- wp:quote -->
<blockquote class="wp-block-quote"><p># dnf install 'dnf-command(copr)'</p><p># dnf copr enable @caddy/caddy</p><p># dnf install caddy -y</p></blockquote>
<!-- /wp:quote -->

<!-- wp:paragraph -->
<p>Next, start and enable <em>caddy.service</em> using following command:</p>
<!-- /wp:paragraph -->

<!-- wp:quote -->
<blockquote class="wp-block-quote"><p># systemctl start caddy &amp;&amp; systemctl enable caddy</p></blockquote>
<!-- /wp:quote -->

<!-- wp:paragraph -->
<p>Configure Firewall</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Assuming that you are using <em>firewalld</em> as your server's firewall, run following command to add the HTTP and HTTPS port in the firewall.</p>
<!-- /wp:paragraph -->

<!-- wp:quote -->
<blockquote class="wp-block-quote"><p># firewall-cmd --add-port=80/tcp --permanent</p><p># firewall-cmd --add-port=443/tcp --permanent</p><p># firewall-cmd --reload</p></blockquote>
<!-- /wp:quote -->

<!-- wp:paragraph -->
<p>Now, navigate to your browser and enter your server IP or domain name:</p>
<!-- /wp:paragraph -->

<!-- wp:quote -->
<blockquote class="wp-block-quote"><p>http://Server-IP</p><p>OR</p><p>http://example.com</p></blockquote>
<!-- /wp:quote -->

<!-- wp:image {"id":1998} -->
<figure class="wp-block-image"><img src="https://www.hostnextra.com/kb/wp-content/uploads/2021/03/install-caddy-on-ubuntu-20-04-1024x759.png" alt="Install Caddy on Rocky Linux 8" class="wp-image-1998"/></figure>
<!-- /wp:image -->

<!-- wp:heading {"level":4} -->
<h4>3. Configure Domain with Caddy</h4>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>Before moving following, first set up domain's A/AAAA&nbsp; DNS record at your registrar or control panel.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Note: Replace neutroncloud.in with your domain name</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Create a directory for your website files</p>
<!-- /wp:paragraph -->

<!-- wp:quote -->
<blockquote class="wp-block-quote"><p># mkdir /usr/share/neutroncloud.in/</p></blockquote>
<!-- /wp:quote -->

<!-- wp:paragraph -->
<p>Now, open Caddy's configuration file and add your domain name and change website's root directory.</p>
<!-- /wp:paragraph -->

<!-- wp:quote -->
<blockquote class="wp-block-quote"><p># vi /etc/caddy/Caddyfile</p></blockquote>
<!-- /wp:quote -->

<!-- wp:paragraph -->
<p>Replace&nbsp;<em>:80</em> with your domain name and change the site root to&nbsp;<em>/usr/share/neutroncloud.in/</em> as</p>
<!-- /wp:paragraph -->

<!-- wp:image {"id":2018} -->
<figure class="wp-block-image"><img src="https://www.hostnextra.com/kb/wp-content/uploads/2021/03/install-caddy-webserver.png" alt="install caddy webserver" class="wp-image-2018"/></figure>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p>Once you done with the changes reload the <em>caddy.service</em> to reflect the changes.</p>
<!-- /wp:paragraph -->

<!-- wp:quote -->
<blockquote class="wp-block-quote"><p># systemctl reload caddy</p></blockquote>
<!-- /wp:quote -->

<!-- wp:paragraph -->
<p>Now, create a index.html file in <em>/var/www/html/neutroncloud.in</em> using following command:</p>
<!-- /wp:paragraph -->

<!-- wp:quote -->
<blockquote class="wp-block-quote"><p># echo '&lt;!doctype html&gt;&lt;head&gt;&lt;title&gt;Hello from Caddy!&lt;/title&gt;&lt;/head&gt;&lt;body&gt;&lt;h1 style="font-family: sans-serif"&gt;This page is being served via Caddy&lt;/h1&gt;&lt;/body&gt;&lt;/html&gt;' | sudo tee /usr/share/neutroncloud.in/index.html</p></blockquote>
<!-- /wp:quote -->

<!-- wp:paragraph -->
<p>Finally, refresh the page in your browser and you will see our newly created <em>index.html</em>.</p>
<!-- /wp:paragraph -->

<p>In this article, we have seen how to install Caddy on Rocky Linux 8.</p>

<a href="https://neutroncloud.in/pricing.html">Deploy cloud servers in India</a>