BAMP Server
App Recommendations | Apps | Tutorials | Website

How to Set up An Apache Website in FreeBSD

In this tutorial, I will show you how to create a website on a FreeBSD server. We will be setting up a BAMP stack (BSD, Apache, MySQL, PHP), which is basically a LAMP stack but for FreeBSD. This tutorial will not tell you how to actually code your website. You will have to do that yourself with HTML/CSS/JavaScript/PHP or install a premade website editor like WordPress. If you haven’t done so already, please go through our tutorial on basic FreeBSD setup: First Things to Do After Installing FreeBSD.

Step 1: Installing Apache in FreeBSD

In this tutorial, we will be using Apache 2.4. If you’re reading from a later date, please adjust to the latest release of Apache in FreeBSD so that you can get security updates.

The Apache Logo

Without further ado, enter the following command to install Apache:

sudo pkg install apache24

Now that you’ve installed apache, you will still need to enable it with rc and start apache with the following commands:

sudo sysrc apache24_enable="YES"
sudo service apache24 start

Step 2: Installing MySQL

The same rules apply here for apache as did MySQL. If you’re reading this article from a later date, and the current version of MySQL is later than MySQL 8.0, then install the current package.

sudo pkg install mysql80-server

Now, you have to start mysql and enable it to start on reboot:

sudo sysrc mysql_enable="YES"
sudo service mysql-server start

Now that you’re done with that, you’re going to want to lock up the mysql server and install everything:

sudo mysql_secure_installation

Go through the wizard. The questions are pretty straightforward, so I’ll let you choose what’s right for your server.

The MySQL Logo

If you don’t know how to write SQL statements, consider learning from here:

Step 3: Installing PHP

Now you need to install PHP. As per usual, if you’re reading the article from a later date, you’ll want to install the latest version of PHP. The current version is PHP 7.4, so we’ll be using that. I will also walk you through installing the needed modules. Enter the following command to install PHP and its modules:

sudo pkg install php74 php74-gettext php74-json php74-mbstring php74-mysqli php74-session php74-zip mod_php74

Now you’ll want to secure and install your php installation.

sudo cp /usr/local/etc/php.ini-production /usr/local/etc/php.ini

Now you need to allow apache to know that .php files are a thing and they need to be handled by the PHP module. Open up “/usr/local/etc/apache24/Includes/php.conf” in vim or nano and enter in the following code:

<IfModule dir_module>
    DirectoryIndex index.php index.html
    <FilesMatch "\.php$">
        SetHandler application/x-httpd-php
    <FilesMatch "\.phps$">
        SetHandler application/x-httpd-php-source

Now you’re going to want to restart apache:

sudo apachectl restart

Now let’s test your PHP installation. Open up “/usr/local/www/apache24/data/info.php” in your preferred editor. Enter in the following code:

<?php phpinfo(); ?>

Now go into your web browser. We’ll use localhost, but you just need to replace the name of the host with whatever the IP address of your server is. Enter in the following URL:


You should see a table listing all sorts of variables and installations having to do with PHP. If you see that, you’re successful in your installation.


Well, I will be doing more tutorials on FreeBSD later, so stay tuned! I will post more in this conclusion section as it comes out.

Latest posts by Frank (see all)

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *