Some weeks ago I installed FreeBSD 11 in my computer in order to use it as a testing machine for some web projects I wanted to work on.

To do that I needed to install the traditional combo of Apache, MySQL, and PHP, and configure it properly. I did not install the ports system when I installed FreeBSD, therefore I used the package system instead.

Install apache

This one was the most straightforward: I installed the package

pkg install apache24

Added line apache24_enable=yes to rc.conf:

sysrc apache24_enable=YES

And started the service:

service apache24 start

In order to test if that part was actually working correctly I opened with the browser the home url, and was rewarded with the following message:

It works!

Ok, I ‘ll believe that it is working 🙂

If you come from a Linux background you might be a bit confused when you start configuring things, since the file structure in FreeBSD is slightly different. Let’s remember some useful paths:

    • httpd.conf : /usr/local/etc/apache24
    • default website folder: /usr/local/www/apache24/data
    • apache logs: /var/log

(and check httpd-error.log)

Install MySQL

Next was MySQL turn.

I remembered from the last time I had tried FreeBSD many years ago, that it offered the possibility to choose between different versions of the same software:

I took, therefore, a look at the available MySQL versions.

pkg search mysql | grep server

And this is what I got:

MySQL availabe versions

So I could choose between MySQL 5.5, 5.6, 5.7, and 8. I decided on the current stable 5.7, and similarly to which I had done with apache, I added the corresponding line to rc.conf, and started the service:

pkg install mysql57-server
sysrc mysql-server=YES
service mysql_enabled start

With MySQL installed and running, I needed to configure it, and assign a password to the root user:


The script asks some questions on securing the installation, such as restricting access to anonymous users, etc:

Securing MySQL script

Securing MySQL ...

Install PHP

As with MySQL, there were various versions of PHP available to choose from: 5.6, 7.0, 7.1.

I installed the package for the 7.1 version of PHP, and the corresponding module to allow PHP to communicate with MySQL databases:

pkg install mod_php71  php71-mysqli

Install PHP 7.1 in FreeBSD 11

PHP provides 2 templates of php.ini files: one for production, and one for development. In this case, since I was setting up a testing machine for software development, I used php.ini-development as the base for a php.ini.

cp /usr/local/etc/php.ini-development /usr/local/etc/php.ini

Next I need to configure apache so that is able to recognize, and handle properly PHP files; otherwise when requesting a PHP file from the server, it would offer to download the file, instead of displaying it.

In order to configure that I needed to edit the httpd.conf file:

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

I  made sure that the line to load the php7_module did exist, and that it was uncommented, and configure the mime type to associate  the .php extension to php content.

LoadModule php7_module libexec/apache24/
AddType application/x-httpd-php .php

In the dir_module entry, I added index.php to the existing index.html in the DirectoryIndex:

<IfModule dir_module>
    DirectoryIndex index.php index.html

I did run rehash, to make sure the system recognized the changes:


Finally I wrote in the web directory a test.php file with the typical phpinfo() line:

<?php phpinfo(); ?>

If you access it from the web browser you should see a table with information on your php configuration.


Testing everything works: installing adminer

At this point FAMP is up, and running, and we can start installing whatever software we want to run on it. A very simple way to check that all parts are working nicely together would be to install something like adminer.

Adminer is a database web manager written in PHP. Installing it is really simple since it requires only uploading a file. So it is a quick/simple way to check that everything is working as expected.

Download the file:

Move it to the /usr/local/www/apache24/data folder (or the location of our web folder, if we modified httpd.conf to use a different one):

move adminer-4.3.1-en.php /usr/local/www/apache24/data/adminer-MNCH.php

Now from the browser we try to access our adminer site:


And we should see something like this:

Adminer login screen

Here we should be able to log in and, create, or edit existing databases using web interfaces.

That’s all 🙂 . If you found this post interesting, you can subscribe to my blog (click at the “follow” button at the bottom) so you can be notified of new posts.