{"id":2898,"date":"2019-05-11T18:48:31","date_gmt":"2019-05-11T15:48:31","guid":{"rendered":"https:\/\/kifarunix.com\/?p=2898"},"modified":"2019-05-11T18:48:33","modified_gmt":"2019-05-11T15:48:33","slug":"install-apache-with-self-signed-certificate-on-freebsd-12","status":"publish","type":"post","link":"https:\/\/kifarunix.com\/install-apache-with-self-signed-certificate-on-freebsd-12\/","title":{"rendered":"Install Apache with Self-signed Certificate on FreeBSD 12"},"content":{"rendered":"\n<p>Hello there. Today we are going to learn how to install Apache with Self-signed Certificate on FreeBSD 12. The use of TLS\/SSL certificates ensure a secured connection to and from the web server by encrypting traffic. The traffic is encrypted with public key that can only be decrypted with a private key that is stored in the web server.<\/p>\n\n\n\n<p>The use of Self-signed TLS\/SSL certificates is strictly not recommended for use in a public site where private information is involved. It can only be used locally for Apache testing purposes, on an intranet or on personal sites that doesn&#8217;t involve the transfer of critical data.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Install Apache with Self-Signed Certificate on FreeBDS 12<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">Install Apache on FreeBSD 12<\/h3>\n\n\n\n<p>To begin with, update your system packages.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>pkg update<br>pkg upgrade<\/code><\/pre>\n\n\n\n<p>Once the update is done, install Apache HTTP server.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>pkg install apache24<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>Updating FreeBSD repository catalogue...\nFreeBSD repository is up to date.\nAll repositories are up to date.\nThe following 12 package(s) will be affected (of 0 checked):\n\nNew packages to be INSTALLED:\n\tapache24: 2.4.39\n\tlibnghttp2: 1.37.0\n\tlibxml2: 2.9.8\n\texpat: 2.2.6_1\n\tperl5: 5.28.1_1\n\tpcre: 8.43\n\tapr: 1.6.5.1.6.1_1\n\tgdbm: 1.18.1\n\tindexinfo: 0.3.1\n\treadline: 7.0.5\n\tgettext-runtime: 0.19.8.1_2\n\tdb5: 5.3.28_7\n\nNumber of packages to be installed: 12\n\nThe process will require 153 MiB more space.\n34 MiB to be downloaded.\n\nProceed with this action? [y\/N]: y<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Start and Enable Apache<\/h3>\n\n\n\n<p>Once the installation is done, you can enable and start Apache by running the commands below;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>sysrc apache24_enable=yes<br>service apache24 start<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Generate Apache Self Signed Certificate<\/h2>\n\n\n\n<p>Now that Apache is installed and running on FreeBSD 12, proceed to generate your self signed SSL\/TLS certificate. This can be done using the <strong>openssl<\/strong> command. Hence, fire up your terminal and execute the command below;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout \/etc\/ssl\/private\/selfsigned.key -out \/etc\/ssl\/certs\/selfsigned.crt<\/code><\/pre>\n\n\n\n<p>When the command runs, you will be prompted to provide some information that will be incorporated into your certificate request. You can leave the defaults for most fields. The most important field however is the server hostname or IP address.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>-----\nCountry Name (2 letter code) [AU]:KE\nState or Province Name (full name) [Some-State]:Nairobi\nLocality Name (eg, city) []:Nairobi\nOrganization Name (eg, company) [Internet Widgits Pty Ltd]:Example Ltd\nOrganizational Unit Name (eg, section) []:ITSec  \nCommon Name (e.g. server FQDN or YOUR name) []:freebsd12.example.com\nEmail Address []: ENTER<\/code><\/pre>\n\n\n\n<p>This generates a new self signed certificate with a private key stored under <strong>\/etc\/ssl\/certs\/selfsigned.crt<\/strong> and <strong>\/etc\/ssl\/private\/selfsigned.key<\/strong> respectively with a validity period of 365 days.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Configure Apache to Use Self Signed Certificates<\/h3>\n\n\n\n<p>Next, you need to configure Apache to use the generated self signed certificate.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Enable Apache SSL module<\/h4>\n\n\n\n<p>To configure Apache to load the SSL modules, edit the main configuration file and uncomment the line, <strong>LoadModule ssl_module libexec\/apache24\/mod_ssl.so<\/strong>.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>vim \/usr\/local\/etc\/apache24\/httpd.conf<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>...\n#LoadModule slotmem_shm_module libexec\/apache24\/mod_slotmem_shm.so\n#LoadModule slotmem_plain_module libexec\/apache24\/mod_slotmem_plain.so\nLoadModule ssl_module libexec\/apache24\/mod_ssl.so\n#LoadModule dialup_module libexec\/apache24\/mod_dialup.so\n...<\/code><\/pre>\n\n\n\n<p>Next, edit the default Apache SSL virtual host file configuration and set the proper values for the <code>ServerAdmin<\/code>, <code>SSLCertificateFile<\/code>, and <code>SSLCertificateKeyFile<\/code> at the least. Before that, make a backup of the original configuration file.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>cp \/usr\/local\/etc\/apache24\/extra\/httpd-ssl.conf \/usr\/local\/etc\/apache24\/extra\/httpd-ssl.conf.bak<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>vim \/usr\/local\/etc\/apache24\/extra\/httpd-ssl.conf<\/code><\/pre>\n\n\n\n<p>You default server block should look like below.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>...\n&lt;VirtualHost _default_:443>\nDocumentRoot \"\/usr\/local\/www\/apache24\/data\"\nServerName freebsd12.example.com:443\nServerAdmin you@example.com\nErrorLog \"\/var\/log\/httpd-error.log\"\nTransferLog \"\/var\/log\/httpd-access.log\"\nSSLEngine on\nSSLCertificateFile \"\/etc\/ssl\/certs\/selfsigned.crt\"\nSSLCertificateKeyFile \"\/etc\/ssl\/private\/selfsigned.key\"\n&lt;FilesMatch \"\\.(cgi|shtml|phtml|php)$\">\n    SSLOptions +StdEnvVars\n&lt;\/FilesMatch>\n&lt;Directory \"\/usr\/local\/www\/apache24\/cgi-bin\">\n    SSLOptions +StdEnvVars\n&lt;\/Directory>\nBrowserMatch \"MSIE [2-5]\" \\\n         nokeepalive ssl-unclean-shutdown \\\n         downgrade-1.0 force-response-1.0\nCustomLog \"\/var\/log\/httpd-ssl_request.log\" \\\n          \"%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \\\"%r\\\" %b\"\n&lt;\/VirtualHost><\/code><\/pre>\n\n\n\n<p>Once you are done with configuration, verify the Apache configuration file to ensure that there are no syntax errors.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>apachectl -t<\/code><\/pre>\n\n\n\n<p>If you get such an error;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>AH00526: Syntax error on line 92 of \/usr\/local\/etc\/apache24\/extra\/httpd-ssl.conf:<br> SSLSessionCache: 'shmcb' session cache not supported (known names: ). Maybe you need to load the appropriate socache module (mod_socache_shmcb?).<\/code><\/pre>\n\n\n\n<p>Edit the main configuration file,<strong>\/usr\/local\/etc\/apache24\/httpd.conf<\/strong>, and enable the <code>socache_shmcb_module<\/code> by uncommenting the line below;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>LoadModule socache_shmcb_module libexec\/apache24\/mod_socache_shmcb.so<\/code><\/pre>\n\n\n\n<p>Run the syntax verification again.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>apachectl -t<br>Syntax OK<\/code><\/pre>\n\n\n\n<p>Restart Apache if there is no more errors.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>service apache24 restart\nPerforming sanity check on apache24 configuration:\nSyntax OK\nStopping apache24.\nWaiting for PIDS: 6873.\nPerforming sanity check on apache24 configuration:\nSyntax OK\nStarting apache24.<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"step-5-test-encryption\">Test HTTPS connection<\/h3>\n\n\n\n<p>You can now test HTTPS connection to your Apache Web server using the address, <strong>https:\/\/&lt;server-hostname&gt;<\/strong>. If all is well, you should see a &#8220;<strong>Your connection is not private<\/strong>&#8221; message since we are using a self-signed certificate.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"https:\/\/kifarunix.com\/wp-content\/uploads\/2019\/05\/https-connection.png\"><img loading=\"lazy\" decoding=\"async\" width=\"905\" height=\"579\" src=\"https:\/\/kifarunix.com\/wp-content\/uploads\/2019\/05\/https-connection.png\" alt=\"install Apache with Self-signed Certificate on FreeBSD 12\" class=\"wp-image-2918\" title=\"\" srcset=\"https:\/\/kifarunix.com\/wp-content\/uploads\/2019\/05\/https-connection.png 905w, https:\/\/kifarunix.com\/wp-content\/uploads\/2019\/05\/https-connection-768x491.png 768w\" sizes=\"(max-width: 905px) 100vw, 905px\" \/><\/a><\/figure>\n\n\n\n<p>To proceed to the server, click <strong>Advanced<\/strong> and <strong>Proceed to &lt;server&gt;<\/strong> unsafe.<\/p>\n\n\n\n<p>If you need to create a separate virtual host configuration, create your configuration under the <strong>\/usr\/local\/etc\/apache24\/extra\/httpd-vhosts.conf<\/strong>.<\/p>\n\n\n\n<p>Well, that is it on how to install Apache with Self-signed Certificate on FreeBSD 12. Feel free to drop your comments on the same.<\/p>\n\n\n\n<p>Want to see other FreeBSD 12 configurations, check the links below;<\/p>\n\n\n\n<p><a href=\"https:\/\/kifarunix.com\/install-phpmyadmin-with-nginx-on-freebsd-12\/\" target=\"_blank\" rel=\"noreferrer noopener\" aria-label=\" (opens in a new tab)\">Install phpMyAdmin with Nginx on FreeBSD 12<\/a><\/p>\n\n\n\n<p><a href=\"https:\/\/kifarunix.com\/install-nginx-mysql-php-femp-stack-on-freebsd-12\/\" target=\"_blank\" rel=\"noreferrer noopener\" aria-label=\" (opens in a new tab)\">Install Nginx, MySQL, PHP (FEMP) Stack on FreeBSD 12<\/a><\/p>\n\n\n\n<p><a href=\"https:\/\/kifarunix.com\/install-apache-mysql-php-famp-stack-on-freebsd-12\/\" target=\"_blank\" rel=\"noreferrer noopener\" aria-label=\" (opens in a new tab)\">Install Apache, MySQL, PHP (FAMP) Stack on FreeBSD 12<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hello there. Today we are going to learn how to install Apache with Self-signed Certificate on FreeBSD 12. The use of TLS\/SSL certificates ensure a<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"rank_math_lock_modified_date":false,"footnotes":""},"categories":[254,253],"tags":[202,278,943],"class_list":["post-2898","post","type-post","status-publish","format-standard","hentry","category-apache","category-web-servers","tag-apache","tag-freebsd-12","tag-ssl-tls","generate-columns","tablet-grid-50","mobile-grid-100","grid-parent","grid-50"],"_links":{"self":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/2898"}],"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\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/comments?post=2898"}],"version-history":[{"count":7,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/2898\/revisions"}],"predecessor-version":[{"id":2922,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/2898\/revisions\/2922"}],"wp:attachment":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/media?parent=2898"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/categories?post=2898"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/tags?post=2898"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}