Other Tutorials<\/a><\/li><\/ul><\/li><\/ul><\/nav><\/div>\n\n\n\nInstalling Apache Web Server on Debian 12<\/h2>\n\n\n\n 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
Run System Update<\/h3>\n\n\n\n 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
sudo apt update<\/code><\/pre>\n\n\n\nInstalling Apache Web Server on Debian 12<\/h3>\n\n\n\n Execute the command below to install Apache web server;<\/p>\n\n\n\n
apt install apache2<\/code><\/pre>\n\n\n\n\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\nStart Apache Service<\/h3>\n\n\n\n Once the installation is done, Apache is started and enabled to run on system boot.<\/p>\n\n\n\n
Thus, you can confirm the status using the command below;<\/p>\n\n\n\n
systemctl status apache2<\/code><\/pre>\n\n\n\n\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\nIf it is not started nor enabled to run on system boot, run the command below to start Apache service;<\/p>\n\n\n\n
systemctl enable --now apache2<\/code><\/pre>\n\n\n\nVerify Apache2 installation<\/h3>\n\n\n\n You can now try to access Apache from the browser to verify its installation.<\/p>\n\n\n\n
You can use the address http:\/\/server-IP<\/strong>.<\/p>\n\n\n\nIf Apache is installed and is working correctly, then you see Apache2 Test page;<\/p>\n\n\n\n <\/figure>\n\n\n\nCreating Custom Site with Apache<\/h3>\n\n\n\n You can create and server your own site using Apache.<\/p>\n\n\n\n
By default, Apache uses \/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\nSo if you want to serve your own page, you can create your application directory under \/var\/www\/<\/strong>.<\/p>\n\n\n\nIn this demo, we create a directory called kifarunix where will put our basic site html content.<\/p>\n\n\n\n
mkdir \/var\/www\/kifarunix<\/code><\/pre>\n\n\n\nThen this is our html configs;<\/p>\n\n\n\n
vim \/var\/www\/kifarunix\/index.html<\/code><\/pre>\n\n\n\n\n<!DOCTYPE html>\n<html>\n<head>\n <title>Welcome to Kifarunix.com<\/title>\n <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 <\/style>\n<\/head>\n<body>\n <div class=\"container\">\n <h1>Welcome to Kifarunix.com<\/h1>\n <p>This is a sample HTML page for my website.<\/p>\n <p>Feel free to customize this page with your own content.<\/p>\n <p>For more information, visit <a href=\"https:\/\/www.kifarunix.com\">kifarunix.com<\/a>.<\/p>\n <\/div>\n<\/body>\n<\/html>\n<\/code><\/pre>\n\n\n\nNext, update the ownership of the directory;<\/p>\n\n\n\n
chown -R www-data: \/var\/www\/kifarunix\/<\/code><\/pre>\n\n\n\nConfigure Apache to serve your site. Similarly, create your own Apache virtualhost config to server your site content;<\/p>\n\n\n\n
\ncat > \/etc\/apache2\/sites-available\/kifarunix.conf << 'EOL'\n<VirtualHost *:80>\n ServerName kifarunix.com\n DocumentRoot \/var\/www\/kifarunix\n\n <Directory \/var\/www\/kifarunix>\n Options Indexes FollowSymLinks\n AllowOverride All\n Require all granted\n <\/Directory>\n\n ErrorLog ${APACHE_LOG_DIR}\/mywebsite_error.log\n CustomLog ${APACHE_LOG_DIR}\/mywebsite_access.log combined\n<\/VirtualHost>\nEOL\n<\/code><\/pre>\n\n\n\nCheck Apache for configuration syntax errors;<\/p>\n\n\n\n
apachectl -t<\/code><\/pre>\n\n\n\nThe output should be, Syntax OK<\/code><\/strong> if everything is ok.<\/p>\n\n\n\nNext, enable your site;<\/p>\n\n\n\n
a2ensite kifarunix.conf<\/code><\/pre>\n\n\n\nDisable default Apache site;<\/p>\n\n\n\n
a2dissite 000-default.conf<\/code><\/pre>\n\n\n\nRestart and Verify Apache Installation<\/h4>\n\n\n\n Restart Apache2 service;<\/p>\n\n\n\n
systemctl restart apache2<\/code><\/pre>\n\n\n\nVerify your site processing from web browser, http:\/\/server-IP-or-resolvable-domain-name<\/strong>.<\/p>\n\n\n\n <\/figure>\n\n\n\nAllowing Apache on Firewall<\/h4>\n\n\n\n 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
UFW;<\/p>\n\n\n\n
ufw allow \"WWW\"<\/code><\/pre>\n\n\n\nIPTABLES;<\/p>\n\n\n\n
iptables -I INPUT -p tcp --dport 80 -j ACCEPT<\/code><\/pre>\n\n\n\nFirewalld;<\/p>\n\n\n\n
firewall-cmd --add-port=80\/tcp --permanent\nfirewall-cmd --reload<\/code><\/pre>\n\n\n\nIf you want to enable HTTPS on Apache, how can you go about it?<\/p>\n\n\n\n
Generate SSL\/TLS certificates<\/h4>\n\n\n\n Firs of all, you need to generate the SSL\/TLS certificates.<\/p>\n\n\n\n
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
Generate private key<\/p>\n\n\n\n
mkdir \/etc\/ssl\/kifarunix<\/code><\/pre>\n\n\n\nopenssl genrsa -out \/etc\/ssl\/kifarunix\/kifarunix-private.key 4096<\/code><\/pre>\n\n\n\nGenerate CSR<\/p>\n\n\n\n
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\nWhere;<\/p>\n\n\n\n
\n\/C=<\/code>: Country (2-letter ISO code)<\/li>\n\n\n\n\/ST=<\/code>: State or province<\/li>\n\n\n\n\/L=<\/code>: Locality or city<\/li>\n\n\n\n\/O=<\/code>: Organization<\/li>\n\n\n\n\/CN=<\/code>: Common Name (e.g., the domain name)<\/li>\n<\/ul>\n\n\n\nGenerate SSL\/TLS certificate;<\/p>\n\n\n\n
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\nSample output;<\/p>\n\n\n\n
Certificate request self-signature ok\nsubject=C = US, ST = CA, L = San Francisco, O = Organization, CN = kifarunix.com<\/code><\/pre>\n\n\n\nInstall\/Enable Apache SSL Modules<\/h4>\n\n\n\n Run the command below to install Apache SSL modules;<\/p>\n\n\n\n
When you install Apache, it installs alongside itself the SSL modules.<\/p>\n\n\n\n
All you need to do is enable the SSL modules for apache;<\/p>\n\n\n\n
a2enmod ssl<\/code><\/pre>\n\n\n\nConfirm with;<\/p>\n\n\n\n
apachectl -M | grep ssl<\/code><\/pre>\n\n\n\n ssl_module (shared)<\/code><\/pre>\n\n\n\nNow, update your config to use SSL\/TLS.<\/p>\n\n\n\n
We will update our config above. So update yours accordingly.<\/p>\n\n\n\n
vim \/etc\/apache2\/sites-available\/kifarunix.conf<\/code><\/pre>\n\n\n\n\n<VirtualHost *:80>\n ServerName kifarunix.com\n Redirect permanent \/ https:\/\/kifarunix.com\/\n<\/VirtualHost>\n\n<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 <Directory \/var\/www\/kifarunix>\n Options FollowSymLinks\n AllowOverride All\n Require all granted\n <\/Directory>\n\n<\/VirtualHost>\n<\/code><\/pre>\n\n\n\nSome of the settings;<\/p>\n\n\n\n
\nRedirect<\/code>: Redirects any HTTP requests to HTTPS<\/li>\n\n\n\nSSLEngine on<\/code> enables SSL\/TLS encryption.<\/li>\n\n\n\nSSLCertificateFile<\/code> and SSLCertificateKeyFile<\/code> point to the paths of your SSL certificate and private key files, respectively.<\/li>\n<\/ul>\n\n\n\nSave and exit the file.<\/p>\n\n\n\n
Enable Apache rewrite modules;<\/p>\n\n\n\n
a2enmod rewrite<\/code><\/pre>\n\n\n\nCheck Apache for any errors;<\/p>\n\n\n\n
apachectl -t<\/code><\/pre>\n\n\n\nif no errors, restart;<\/p>\n\n\n\n
systemctl restart apache2<\/code><\/pre>\n\n\n\nVerify that you can now access your site via HTTPS by visiting the https:\/\/domain-name.com<\/code><\/strong>.<\/p>\n\n\n\nSimilarly, 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
UFW;<\/p>\n\n\n\n
ufw allow \"WWW Secure\"<\/code><\/pre>\n\n\n\nIPTABLES;<\/p>\n\n\n\n
iptables -I INPUT -p tcp --dport 443 -j ACCEPT<\/code><\/pre>\n\n\n\nFirewalld;<\/p>\n\n\n\n
firewall-cmd --add-port=443\/tcp --permanent\nfirewall-cmd --reload<\/code><\/pre>\n\n\n\nThat is all on installing Apache web server on Debian Linux.<\/p>\n\n\n\n
Other Tutorials<\/h3>\n\n\n\n Install Apache Guacamole as Docker Container on Ubuntu<\/a><\/p>\n\n\n\nInstall Apache Maven on Rocky Linux 8<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"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}]}}