Admin... by accident!

You may have chosen to be an admin. I didn't!

  • Home
  • FreeBSD
  • GNU/Linux
  • Security
  • Network
  • Virtualization
  • Politics
  • Github
  • Donate
  • Me

How to install Apache in FreeBSD with pkgng

April 26, 2017 by Albert Valbuena

The Apache Web Server is one of the most widely deployed web servers around the world. There are new and powerful alternatives you may have heard of, such as NGINX which seems to be the coolest thing around lately.

There are meaningful differences between the two. Both are great but for example Apache has set the bar first and that shows when you have to install any piece of software that has to play with it, since integration with Apache is something everyone takes for granted. Apache does also understand dynamic content. NGINX just plays static content out of the box. And many modern websites and CMS’s do use dynamic content. Obviously NGINX can play dynamic content after installing the appropriate software. PHP-FPM is a program that enables that functionality in NGINX. Mind this can be also installed on Apache. NGINX can also play other roles such as acting as a reverse proxy server or as a load balancer.

If you find the articles in Adminbyaccident.com useful to you, please consider making a donation.

Use this link to get $200 credit at DigitalOcean and support Adminbyaccident.com costs.

Get $100 credit for free at Vultr using this link and support Adminbyaccident.com costs.

Mind Vultr supports FreeBSD on their VPS offer.

Competition between the two is good and healthy for the web. And basically you can assume Apache is better documented and easier to configure. NGINX is now very popular and widely deployed but it is not as easy to tune for the newbie although things have improved dramatically lately and now the two seem to be head to head. Which is good for users after all.

To start playing with a web server, which will often be accompanied by WordPress, we’ll use Apache. Mind there are some WordPress plugins which expect certain things as default. That default means for example writing to a file called .htaccess. If you want to set pretty permalinks in WordPress you need that file or configure NGINX propperly to allow rewrites. That will allow you to have your own special crafted url. Instead of reading numbers and symbols in the url next to your domain, you can now put posts out to the world which have a human readable url. And the search engines spyders do also like it and your SEO strategy is a bit better. This doesn’t mean you can’t play WordPress on NGINX.

URL example with a numeric identifier instead of words:

An URL example with words (which is supposed to be more SEO friendly):

The NGINX team do also have their way and they say on a very nice explanatory article that “If you need .htacces, you’re probably doing it wrong”. As you can see this is a different mindset from what has been developed for many years. A rule of thumb to choose in between Apache and NGINX is: “First learn Apache. Once you fully understand it go and learn NGINX”. Afterwards your toolset is wider, your understanding more complete and you can take the best tool for the job at each time.

As you can read in the picture above we’ll install apache by typing:

sudo pkg install apache24

Now we’ll set apache to start at boot time by editing the /etc/rc.conf file.

sudo vi /etc/rc.conf

At the bottom of the file add:

apache24_enable="YES"

Time to start the service so the web server is working. Type the following:

sudo service apache24 onestart

Now go to your web browser and point it to the url or ip address your server sits on. You should see a message like:

If you don’t see the message “It works”, Apache isn’t working. Check the installation messages to find any errors or problems you may have missed.

Configure Apache as a backend web server

Apache is listening to port 80 by default. As almost any webserver since this is the default port for http requests. If you pretend to use Apache and you will not put any proxy server in front or any other program as an http accelerator you don’t need to change this.
Since some people will install Varnish, an http accelerator,  or will put a reverse proxy in front of the Apache instance such as NGINX, we will change the port Apache is listening to. Instead of 80 we’ll set 8080 in this case.

sudo vi /usr/local/etc/apache24/httpd.conf

Listen 8080
Servername ipnumber or localhost:8080

Launch Apache

sudo service apache24 start

If you visit the webserver ip you should see the “It works” message as before.

If you find the articles in Adminbyaccident.com useful to you, please consider making a donation.

Use this link to get $200 credit at DigitalOcean and support Adminbyaccident.com costs.

Get $100 credit for free at Vultr using this link and support Adminbyaccident.com costs.

Mind Vultr supports FreeBSD on their VPS offer.

 

Filed Under: How To's

Recent Posts

  • How to install Redis for WordPress on FreeBSD
  • How to compile cloudflared in FreeBSD 13/14
  • How to configure FreeBSD to use a webcam (version 12 and 13)
  • Symbolic and Hard Links in UNIX and Linux
  • How to import iocage jails to Bastille on FreeBSD 13
  • How to load and unload kernel modules in Linux
  • How to use find in GNU/Linux and FreeBSD
  • How to install Mate on FreeBSD 12/13
  • How to install Nessus 10 on FreeBSD 12
  • How to enable TLS traffic from the origin server on Cloudflare Argo Tunnel
  • How to use Cloudflare’s Argo Tunnel service to publish a website on FreeBSD 12/13
  • How to setup MariaDB master-slave replication on FreeBSD
  • How to upload a FreeBSD custom image on DigitalOcean
  • How to install Drupal 9 on FreeBSD 13.0
  • How to manage site visitors based on IP Geolocation
  • How to enable Geolocation in AWStats on FreeBSD 13.0
  • How to install AWStats on FreeBSD 13.0
  • How to configure Modsecurity 3 for WordPress on FreeBSD
  • How to configure Apache HTTP with a TLS reverse proxy backend on FreeBSD
  • How to detect a WAF – Web Application Firewall

Archives

  • November 2024
  • October 2024
  • August 2023
  • July 2023
  • June 2023
  • May 2023
  • April 2023
  • February 2023
  • January 2023
  • December 2022
  • April 2022
  • March 2022
  • October 2021
  • September 2021
  • June 2021
  • May 2021
  • April 2021
  • March 2021
  • February 2021
  • January 2021
  • December 2020
  • July 2020
  • June 2020
  • May 2020
  • April 2020
  • March 2020
  • February 2020
  • January 2020
  • December 2019
  • November 2019
  • October 2019
  • August 2019
  • July 2019
  • June 2019
  • May 2019
  • April 2019
  • March 2019
  • February 2019
  • January 2019
  • September 2018
  • June 2018
  • May 2018
  • April 2018
  • February 2018
  • January 2018
  • November 2017
  • April 2017

RSS Admin… by accident!

  • How to install Redis for WordPress on FreeBSD
  • How to compile cloudflared in FreeBSD 13/14
  • How to configure FreeBSD to use a webcam (version 12 and 13)
  • Symbolic and Hard Links in UNIX and Linux
  • How to import iocage jails to Bastille on FreeBSD 13
  • How to load and unload kernel modules in Linux
  • How to use find in GNU/Linux and FreeBSD
  • How to install Mate on FreeBSD 12/13
  • How to install Nessus 10 on FreeBSD 12
  • How to enable TLS traffic from the origin server on Cloudflare Argo Tunnel

Copyright © 2025 · Magazine Pro Theme on Genesis Framework · WordPress · Log in