{"id":17199,"date":"2023-06-13T23:35:06","date_gmt":"2023-06-13T20:35:06","guid":{"rendered":"https:\/\/kifarunix.com\/?p=17199"},"modified":"2024-03-10T09:58:38","modified_gmt":"2024-03-10T06:58:38","slug":"install-apache-web-server-on-debian-12","status":"publish","type":"post","link":"https:\/\/kifarunix.com\/install-apache-web-server-on-debian-12\/","title":{"rendered":"Install Apache Web Server on Debian 12"},"content":{"rendered":"\n<p>How can i install Apache web server on Debian 12? Follow through the simple steps  in this guide to learn how to install <a href=\"https:\/\/httpd.apache.org\/\" target=\"_blank\" rel=\"noreferrer noopener\">Apache<\/a> web server. <\/p>\n\n\n\n<div class=\"wp-block-rank-math-toc-block\" id=\"rank-math-toc\"><h2>Table of Contents<\/h2><nav><ul><li><a href=\"#installing-apache-web-server-on-debian-12\">Installing Apache Web Server on Debian 12<\/a><ul><li><a href=\"#run-system-update\">Run System Update<\/a><\/li><li><a href=\"#installing-apache-web-server-on-debian-12-1\">Installing Apache Web Server on Debian 12<\/a><\/li><li><a href=\"#start-apache-service\">Start Apache Service<\/a><\/li><li><a href=\"#verify-apache-2-installation\">Verify Apache2 installation<\/a><\/li><li><a href=\"#creating-custom-site-with-apache\">Creating Custom Site with Apache<\/a><ul><li><a href=\"#restart-and-verify-apache-installation\">Restart and Verify Apache Installation<\/a><\/li><li><a href=\"#allowing-apache-on-firewall\">Allowing Apache on Firewall<\/a><\/li><\/ul><\/li><li><a href=\"#configure-apache-with-https\">Configure Apache with HTTPS<\/a><ul><li><a href=\"#generate-ssl-tls-certificates\">Generate SSL\/TLS certificates<\/a><\/li><li><a href=\"#install-enable-apache-ssl-modules\">Install\/Enable Apache SSL Modules<\/a><\/li><li><a href=\"#configure-apache-to-use-ssl-tls-certs\">Configure Apache to use SSL\/TLS certs<\/a><\/li><\/ul><\/li><li><a href=\"#other-tutorials\">Other Tutorials<\/a><\/li><\/ul><\/li><\/ul><\/nav><\/div>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"installing-apache-web-server-on-debian-12\">Installing Apache Web Server on Debian 12<\/h2>\n\n\n\n<p>Have you installed Debian 12 and want to run some web applications on it? You can install Apache, the number HTTP server on the internet and configure it to server your web application.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"run-system-update\">Run System Update<\/h3>\n\n\n\n<p>To ensure you are installing up-to-date packages on Debian 12, update the package cache by running the command below;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo apt update<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"installing-apache-web-server-on-debian-12-1\">Installing Apache Web Server on Debian 12<\/h3>\n\n\n\n<p>Execute the command below to install Apache web server;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>apt install apache2<\/code><\/pre>\n\n\n\n<pre class=\"scroll-box\"><code>\nReading package lists... Done\nBuilding dependency tree... Done\nReading state information... Done\nThe following additional packages will be installed:\n  apache2-data apache2-utils\nSuggested packages:\n  apache2-doc apache2-suexec-pristine | apache2-suexec-custom\nThe following NEW packages will be installed:\n  apache2 apache2-data apache2-utils\n0 upgraded, 3 newly installed, 0 to remove and 0 not upgraded.\nNeed to get 577 kB of archives.\nAfter this operation, 1,890 kB of additional disk space will be used.\nDo you want to continue? [Y\/n] y\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"start-apache-service\">Start Apache Service<\/h3>\n\n\n\n<p>Once the installation is done, Apache is started and enabled to run on system boot.<\/p>\n\n\n\n<p>Thus, you can confirm the status using the command below;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>systemctl status apache2<\/code><\/pre>\n\n\n\n<pre class=\"scroll-box\"><code>\n\u25cf apache2.service - The Apache HTTP Server\n     Loaded: loaded (\/lib\/systemd\/system\/apache2.service; enabled; preset: enabled)\n     Active: active (running) since Tue 2023-06-13 22:16:40 EAT; 2min 3s ago\n       Docs: https:\/\/httpd.apache.org\/docs\/2.4\/\n   Main PID: 3835 (apache2)\n      Tasks: 55 (limit: 2285)\n     Memory: 10.6M\n        CPU: 50ms\n     CGroup: \/system.slice\/apache2.service\n             \u251c\u25003835 \/usr\/sbin\/apache2 -k start\n             \u251c\u25003837 \/usr\/sbin\/apache2 -k start\n             \u2514\u25003838 \/usr\/sbin\/apache2 -k start\n\nJun 13 22:16:40 bookworm systemd[1]: Starting apache2.service - The Apache HTTP Server...\nJun 13 22:16:40 bookworm systemd[1]: Started apache2.service - The Apache HTTP Server.\n<\/code><\/pre>\n\n\n\n<p>If it is not started nor enabled to run on system boot, run the command below to start Apache service;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>systemctl enable --now apache2<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"verify-apache-2-installation\">Verify Apache2 installation<\/h3>\n\n\n\n<p>You can now try to access Apache from the browser to verify its installation.<\/p>\n\n\n\n<p>You can use the address <strong>http:\/\/server-IP<\/strong>.<\/p>\n\n\n\n<p>If Apache is installed and is working correctly, then you see Apache2 Test page;<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"891\" height=\"946\" src=\"https:\/\/kifarunix.com\/wp-content\/uploads\/2023\/06\/apache2-test-page.png\" alt=\"Install Apache Web Server on Debian 12\" class=\"wp-image-17209\" title=\"\" srcset=\"https:\/\/kifarunix.com\/wp-content\/uploads\/2023\/06\/apache2-test-page.png?v=1686684213 891w, https:\/\/kifarunix.com\/wp-content\/uploads\/2023\/06\/apache2-test-page-768x815.png?v=1686684213 768w\" sizes=\"(max-width: 891px) 100vw, 891px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"creating-custom-site-with-apache\">Creating Custom Site with Apache<\/h3>\n\n\n\n<p>You can create and server your own site using Apache.<\/p>\n\n\n\n<p>By default, Apache uses <strong><code>\/var\/www\/html<\/code><\/strong> as the document root directory. It is also known as web root directory, is the main directory where the web server looks for files to serve to clients.<\/p>\n\n\n\n<p>So if you want to serve your own page, you can create your application directory under <strong>\/var\/www\/<\/strong>.<\/p>\n\n\n\n<p>In this demo, we create a directory called kifarunix where will put our basic site html content.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>mkdir \/var\/www\/kifarunix<\/code><\/pre>\n\n\n\n<p>Then this is our html configs;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>vim \/var\/www\/kifarunix\/index.html<\/code><\/pre>\n\n\n\n<pre class=\"scroll-box\"><code>\n&lt;!DOCTYPE html>\n&lt;html>\n&lt;head>\n    &lt;title>Welcome to Kifarunix.com&lt;\/title>\n    &lt;style>\n        body {\n            display: flex;\n            justify-content: center;\n            align-items: flex-start;\n            min-height: 100vh;\n            text-align: center;\n            font-family: Arial, sans-serif;\n            margin: 0;\n        }\n        .container {\n            max-width: 600px;\n            margin-top: 20vh;\n        }\n        h1 {\n            font-size: 28px;\n            margin-bottom: 20px;\n        }\n        p {\n            font-size: 18px;\n            line-height: 1.5;\n            margin-bottom: 10px;\n        }\n        a {\n            color: #007bff;\n        }\n    &lt;\/style>\n&lt;\/head>\n&lt;body>\n    &lt;div class=\"container\">\n        &lt;h1>Welcome to Kifarunix.com&lt;\/h1>\n        &lt;p>This is a sample HTML page for my website.&lt;\/p>\n        &lt;p>Feel free to customize this page with your own content.&lt;\/p>\n        &lt;p>For more information, visit &lt;a href=\"https:\/\/www.kifarunix.com\">kifarunix.com&lt;\/a>.&lt;\/p>\n    &lt;\/div>\n&lt;\/body>\n&lt;\/html>\n<\/code><\/pre>\n\n\n\n<p>Next, update the ownership of the directory;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>chown -R www-data: \/var\/www\/kifarunix\/<\/code><\/pre>\n\n\n\n<p>Configure Apache to serve your site. Similarly, create your own Apache virtualhost config to server your site content;<\/p>\n\n\n\n<pre class=\"scroll-box\"><code>\ncat > \/etc\/apache2\/sites-available\/kifarunix.conf &lt;&lt; 'EOL'\n&lt;VirtualHost *:80>\n    ServerName kifarunix.com\n    DocumentRoot \/var\/www\/kifarunix\n\n    &lt;Directory \/var\/www\/kifarunix>\n        Options Indexes FollowSymLinks\n        AllowOverride All\n        Require all granted\n    &lt;\/Directory>\n\n    ErrorLog ${APACHE_LOG_DIR}\/mywebsite_error.log\n    CustomLog ${APACHE_LOG_DIR}\/mywebsite_access.log combined\n&lt;\/VirtualHost>\nEOL\n<\/code><\/pre>\n\n\n\n<p>Check Apache for configuration syntax errors;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>apachectl -t<\/code><\/pre>\n\n\n\n<p>The output should be, <strong><code>Syntax OK<\/code><\/strong> if everything is ok.<\/p>\n\n\n\n<p>Next, enable your site;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>a2ensite kifarunix.conf<\/code><\/pre>\n\n\n\n<p>Disable default Apache site;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>a2dissite 000-default.conf<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"restart-and-verify-apache-installation\">Restart and Verify Apache Installation<\/h4>\n\n\n\n<p>Restart Apache2 service;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>systemctl restart apache2<\/code><\/pre>\n\n\n\n<p>Verify your site processing from web browser, <strong>http:\/\/server-IP-or-resolvable-domain-name<\/strong>.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1296\" height=\"512\" src=\"https:\/\/kifarunix.com\/wp-content\/uploads\/2023\/06\/sample-site-apache.png\" alt=\"\" class=\"wp-image-17213\" title=\"\" srcset=\"https:\/\/kifarunix.com\/wp-content\/uploads\/2023\/06\/sample-site-apache.png?v=1686685565 1296w, https:\/\/kifarunix.com\/wp-content\/uploads\/2023\/06\/sample-site-apache-768x303.png?v=1686685565 768w\" sizes=\"(max-width: 1296px) 100vw, 1296px\" \/><\/figure>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"allowing-apache-on-firewall\">Allowing Apache on Firewall<\/h4>\n\n\n\n<p>If firewall is on on your system and you want to access your web server externally, open the ports  on firewall;<\/p>\n\n\n\n<p>UFW;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ufw allow \"WWW\"<\/code><\/pre>\n\n\n\n<p>IPTABLES;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>iptables -I INPUT -p tcp --dport 80 -j ACCEPT<\/code><\/pre>\n\n\n\n<p>Firewalld;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>firewall-cmd --add-port=80\/tcp --permanent\nfirewall-cmd --reload<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"configure-apache-with-https\">Configure Apache with HTTPS<\/h3>\n\n\n\n<p>If you want to enable HTTPS on Apache, how can you go about it?<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"generate-ssl-tls-certificates\">Generate SSL\/TLS certificates<\/h4>\n\n\n\n<p>Firs of all, you need to generate the SSL\/TLS certificates.<\/p>\n\n\n\n<p>We will use self signed SSL certs in this guide. The process to use commercial certs is out of scope of this guide.<\/p>\n\n\n\n<p>Generate private key<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>mkdir \/etc\/ssl\/kifarunix<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>openssl genrsa -out \/etc\/ssl\/kifarunix\/kifarunix-private.key 4096<\/code><\/pre>\n\n\n\n<p>Generate CSR<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>openssl req -new -key \/etc\/ssl\/kifarunix\/kifarunix-private.key \\\n-out \/etc\/ssl\/kifarunix\/kifarunix-csr.pem \\\n-subj \"\/C=US\/ST=CA\/L=San Francisco\/O=Organization\/CN=kifarunix.com\"<\/code><\/pre>\n\n\n\n<p>Where;<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>\/C=<\/code>: Country (2-letter ISO code)<\/li>\n\n\n\n<li><code>\/ST=<\/code>: State or province<\/li>\n\n\n\n<li><code>\/L=<\/code>: Locality or city<\/li>\n\n\n\n<li><code>\/O=<\/code>: Organization<\/li>\n\n\n\n<li><code>\/CN=<\/code>: Common Name (e.g., the domain name)<\/li>\n<\/ul>\n\n\n\n<p>Generate SSL\/TLS certificate;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>openssl x509 -req -days 3650 -in \/etc\/ssl\/kifarunix\/kifarunix-csr.pem \\\n-signkey  \/etc\/ssl\/kifarunix\/kifarunix-private.key -out \/etc\/ssl\/kifarunix\/kifarunix-cert.crt<\/code><\/pre>\n\n\n\n<p>Sample output;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Certificate request self-signature ok\nsubject=C = US, ST = CA, L = San Francisco, O = Organization, CN = kifarunix.com<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"install-enable-apache-ssl-modules\">Install\/Enable Apache SSL Modules<\/h4>\n\n\n\n<p>Run the command below to install Apache SSL modules;<\/p>\n\n\n\n<p>When you install Apache, it installs alongside itself the SSL modules.<\/p>\n\n\n\n<p>All you need to do is enable the SSL modules for apache;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>a2enmod ssl<\/code><\/pre>\n\n\n\n<p>Confirm with;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>apachectl -M | grep ssl<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code> ssl_module (shared)<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"configure-apache-to-use-ssl-tls-certs\">Configure Apache to use SSL\/TLS certs<\/h4>\n\n\n\n<p>Now, update your config to use SSL\/TLS.<\/p>\n\n\n\n<p>We will update our config above. So update yours accordingly.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>vim \/etc\/apache2\/sites-available\/kifarunix.conf<\/code><\/pre>\n\n\n\n<pre class=\"scroll-box\"><code>\n&lt;VirtualHost *:80>\n    ServerName kifarunix.com\n    Redirect permanent \/ https:\/\/kifarunix.com\/\n&lt;\/VirtualHost>\n\n&lt;VirtualHost *:443>\n    ServerName kifarunix.com\n\n    SSLEngine on\n    SSLCertificateFile \/etc\/ssl\/kifarunix\/kifarunix-cert.crt\n    SSLCertificateKeyFile \/etc\/ssl\/kifarunix\/kifarunix-private.key\n\n    DocumentRoot \/var\/www\/kifarunix\n\n    &lt;Directory \/var\/www\/kifarunix>\n        Options FollowSymLinks\n        AllowOverride All\n        Require all granted\n    &lt;\/Directory>\n\n&lt;\/VirtualHost>\n<\/code><\/pre>\n\n\n\n<p>Some of the settings;<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>Redirect<\/code>: Redirects any HTTP requests to HTTPS<\/li>\n\n\n\n<li><code>SSLEngine on<\/code> enables SSL\/TLS encryption.<\/li>\n\n\n\n<li><code>SSLCertificateFile<\/code> and <code>SSLCertificateKeyFile<\/code> point to the paths of your SSL certificate and private key files, respectively.<\/li>\n<\/ul>\n\n\n\n<p>Save and exit the file.<\/p>\n\n\n\n<p>Enable Apache rewrite modules;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>a2enmod rewrite<\/code><\/pre>\n\n\n\n<p>Check Apache for any errors;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>apachectl -t<\/code><\/pre>\n\n\n\n<p>if no errors, restart;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>systemctl restart apache2<\/code><\/pre>\n\n\n\n<p>Verify that you can now access your site via HTTPS by visiting the <strong><code>https:\/\/domain-name.com<\/code><\/strong>.<\/p>\n\n\n\n<p>Similarly, you need to open HTTPS port on firewall. Substitute the commands above with the correct app (UFW) and ports (iptables\/firewalld);<\/p>\n\n\n\n<p>UFW;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ufw allow \"WWW Secure\"<\/code><\/pre>\n\n\n\n<p>IPTABLES;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>iptables -I INPUT -p tcp --dport 443 -j ACCEPT<\/code><\/pre>\n\n\n\n<p>Firewalld;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>firewall-cmd --add-port=443\/tcp --permanent\nfirewall-cmd --reload<\/code><\/pre>\n\n\n\n<p>That is all on installing Apache web server on Debian Linux.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"other-tutorials\">Other Tutorials<\/h3>\n\n\n\n<p><a href=\"https:\/\/kifarunix.com\/install-apache-guacamole-as-docker-container-on-ubuntu\/\" target=\"_blank\" rel=\"noreferrer noopener\">Install Apache Guacamole as Docker Container on Ubuntu<\/a><\/p>\n\n\n\n<p><a href=\"https:\/\/kifarunix.com\/install-apache-maven-on-rocky-linux-8\/\" target=\"_blank\" rel=\"noreferrer noopener\">Install Apache Maven on Rocky Linux 8<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>How can i install Apache web server on Debian 12? Follow through the simple steps in this guide to learn how to install Apache web<\/p>\n","protected":false},"author":10,"featured_media":17215,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"rank_math_lock_modified_date":false,"footnotes":""},"categories":[121,254,34,1187,253],"tags":[6877,6876,6875,6878],"class_list":["post-17199","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-howtos","category-apache","category-security","category-ssl-tls","category-web-servers","tag-apache-ssl-tls-debian-12","tag-debian-12-apache-web-server","tag-install-apache-debian-12","tag-install-apache-with-ssl-on-debian-12","generate-columns","tablet-grid-50","mobile-grid-100","grid-parent","grid-50","resize-featured-image"],"_links":{"self":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/17199"}],"collection":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/users\/10"}],"replies":[{"embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/comments?post=17199"}],"version-history":[{"count":13,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/17199\/revisions"}],"predecessor-version":[{"id":20785,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/17199\/revisions\/20785"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/media\/17215"}],"wp:attachment":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/media?parent=17199"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/categories?post=17199"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/tags?post=17199"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}