
Apache is an open-source high-performance webserver for delivering web applications. You can use Apache to serve static web content or integrate it with database servers like MySQL or PostgreSQL to serve dynamic web content.
In this guide, you'll install Apache webserver on FreeBSD 14.0, set up virtual hosts, and configure an SSL certificate to secure the webserver.
Before you begin:
app.example.com example domain.Apache is available in the default package repositories on FreeBSD 14.0. Follow the steps below to install Apache.
Update the server's package information index.
Install Apache.
Apache runs as apache24 system service in FreeBSD 14.0. Follow the steps below to manage the service.
Enable the Apache system service to automatically start at boot.
Output:
Start the Apache service.
Output:
View the Apache service status and verify it's running.
Output:
Stop the Apache service.
Output:
Restart Apache.
You can configure different Apache virtual hosts to run multiple websites and web applications on one server. Follow the steps below to create a new Apache virtual host for the app.example.com domain.
Create a new Apache virtual host configuration file in the /usr/local/etc/apache24/Includes/ directory. For example, app.example.com.conf.
Add the following contents to the file. Replace app.example.com with your domain and webadmin@example.com with your web administrator's email address.
Save and close the file.
The above Apache configuration creates a new virtual host that listens for incoming connections for the app.example.com domain. Then, the virtual host serves contents from the /usr/local/www/app.example.com directory. Within the configuration:
<VirtualHost *:80>: Configures Apache to listen for incoming requests on the HTTP port 80.ServerAdmin webadmin@example.com: Specifies the Apache web administrator's email for receiving critical error and alert emails.ServerName app.example.com: Sets the virtual host's domain name.DocumentRoot "/usr/local/www/app.example.com": Sets the virtual host's web root directory.DirectoryIndex index.html index.php: Sets the default index file order to serve when a user visits the virtual host domain app.example.com.<Directory "/usr/local/www/app.example.com">: Defines the web root directory configurations.Options -Indexes: Disables Apache directory listing.AllowOverride All: Allows the .htaccess configuration to override the Apache virtual host configuration.Require all granted: Allows all users to access files in the web root directory.ErrorLog "/var/log/app.example.com-error_log": Creates a custom log file to store Apache errors.CustomLog "/var/log/app.example.com-access_log" combined: Creates a custom log file to store the Apache access log with the combined log format.Create the virtual host's web root directory.
Create a new index.html web application file in the /usr/local/www/app.example.com directory using a text editor like vi.
Add the following contents to the index.html file.
Save and close the file.
The above HTML application displays a Greetings from Vultr message when you access your domain URL in a web browser.
Test the Apache configuration for errors.
Output:
Change the /usr/local/www/app.example.com directory ownership to www, the default Apache user and group.
Restart Apache to apply the configuration changes.
By default, Apache listens for HTTP connections on port 80. Follow the steps below to enable secure HTTPS connections on port 443 by installing an SSL certificate.
Install the Certbot Let's Encrypt client tool for Apache.
Enable the Apache mod_rewrite module.
Enable the mod_ssl module.
The above commands uncomment and enable the following modules in the /usr/local/etc/apache24/httpd.conf file.
Generate a new SSL certificate for your virtual host domain. Replace app.example.com with your actual domain and hello@example.com with your active email address.
Test the Certbot SSL certificate auto-renewal process.
Output:
Restart Apache to apply the SSL configuration changes.
FreeBSD supports multiple firewall packages that filter network traffic on the server. No default firewall package is active, and you can install or use any firewall tool, such as ipfw to allow network connections on the server. Follow the steps below to enable ipfw and allow HTTP and HTTPS connections on the server.
Enable the ipfw firewall service to automatically start ipfw at system boot.
Output:
Disable ipfw from outputting information to the standard output (STDOUT).
Output:
Set the firewall type to workstation.
Output:
Allow SSH, HTTP, and HTTPS network connections through the firewall.
Output:
Enable network connections from any host to your server.
Output:
Log all blocked network connections to /var/log/security.
Output:
View all active firewall configurations.
Output:
Start the ipfw firewall service.
Access your domain URL in a web browser such as Chrome and verify that your web application runs and displays the Greetings from Vultr message.
You have installed Apache webserver on FreeBSD 14.0, set up a virtual host, and configured an SSL certificate to secure the webserver. You can run multiple websites on the same server by configuring additional virtual hosts. For more information, visit the Apache documentation.
0 Comments
Be the first to comment and share your perspective with the community.