Configure apache24, php70 and mysql57 on FreeBSD 11.0

1. Install and configure Apache 2.4

Let’s install Apache 2.4 first. You may do so by running the following command:

pkg install apache24

On a brand-new system, you may get a message asking you to install the package management tool. If so, just enter “y” here because you will need this tool to complete the tutorial.

When asked to proceed with installing apache24 (and several other packages), enter “y” here as well.

Next, edit /etc/rc.conf with the editor of your choice and add the following line to start Apache on reboot:


Now start Apache with the following command:

service apache24 start

Navigate to your IP address in your browser and you should see the default “It works!” Apache page indicating the installation was successful.

Apache 2.4 is now installed on your system. The next step is to install MySQL 5.7.

Tip: Your site files are located in /usr/local/www/apache24/data/ . This is where you’ll also find the default “It works!” Apache page.

2. Install and configure MySQL 5.7

The next step to install is MySQL 5.7. Do that now by running the following command:

pkg install mysql57-server

When asked to proceed with installing mysql56-server (and a few other packages, including mysql57-client), enter “y” here.

Edit /etc/rc.conf again and add the following line to start MySQL on reboot:


Now you may start MySQL with:

service mysql-server start

At this point you will need to make some security modifications to your MySQL installation, particularly setting a root password and removing test and anonymous data. Do that with the following command:

  1. Press “Enter” at Enter current password for root (enter for none)
  2. Enter “y” at Set root password? [Y/n]
  3. Now enter a new secure password for the root MySQL user
  4. At Remove anonymous users? [Y/n], enter “y”
  5. Enter “y” at Disallow root login remotely? [Y/n]
  6. Remove the test database by entering “y” at Remove test database and access to it? [Y/n]
  7. g. Reload the privilege tables so your changes take effect by entering “y” at Reload privilege tables now? [Y/n]

Try accessing your MySQL databases now on the command line by using:

mysql -u root -p

That command should drop you into the MySQL shell. Congratulations, you’ve successfully installed MySQL 5.7 on FreeBSD 11.0! Now it’s time to install PHP 5.6.

3. Install and configure PHP 7.0

Again, we will use the pkg tool to install PHP 7.0. Do so with the following command:

pkg install mod_php70 php70-mysql php70-mysqli php70-extensions

Enter “y” when asked to proceed with installing the php70 packages.

Now edit /usr/local/etc/apache24/httpd.conf; the PHP file handler needs to be added and DirectoryIndex should contain index.php.

Locate the following block in httpd.conf:

<IfModule dir_module>
DirectoryIndex index.html

Change it to the following if you want Apache to serve index.php first (swap them if you want Apache to prefer index.html):

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

Now restart Apache so your changes to httpd.conf take effect:

service apache24 restart

Test that PHP is working correctly by creating a PHP file in /usr/local/www/apache24/data/. Create a file there called “index.php” and paste in the following code:

echo "Hello world!";

Reload your IP address in your browser and you should see “Hello world!” instead of the default “It works!” Apache message from earlier in the tutorial.

You may need to restart Apache one last time if you still see “It works!” with:

service apache24 restart

That’s it! You now have a fully functioning FAMP server ready to host your website.

For certain websites like magento or wordpress you need to also enable mod_rewrite in apache24. To do this, uncomment the line

#LoadModule rewrite_module libexec/apache24/

The next step is to also change this is http.conf.

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

find the section that contains the DocumentRoot:

DocumentRoot "/usr/local/www/apache24/data"
<Directory "/usr/local/www/apache24/data"


AllowOverride None


AllowOverride All

Restart the apache web server!

Leave a comment

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