A FAMP stack is a collection of open-source software used to enable a server to host a website or web application written in PHP language. FAMP uses FreeBSD as the operating system, Apache as the Web server, MySQL as the database management system, and PHP as the object-oriented scripting language.

Step 1 – Install Apache Web Server

By default, the Apache package is included in the FreeBSD default repo, so you can easily install it using the pkg command.

First, update all the packages using the following command.

pkg update

Next, install the Apache web server package with the following command.

pkg install apache24

Once Apache is installed, you can enable it to start at system reboot.

sysrc apache24_enable="YES"

Next, start the Apache service using the below command.

service apache24 start

To check the Apache service status, run the following command.

service apache24 status

Output:

apache24 is running as pid 1494.

Step 2 – Install MariaDB Server

By default, the MariaDB package is included in the default repository. You can search all available package versions using the following command.

pkg search mariadb

You will see the following list.

mariadb-connector-c-3.3.4      MariaDB database connector for C
mariadb-connector-odbc-3.1.17  MariaDB database connector for odbc
mariadb1011-client-10.11.5     Multithreaded SQL database (client)
mariadb1011-server-10.11.5     Multithreaded SQL database (server)
mariadb105-client-10.5.21      Multithreaded SQL database (client)
mariadb105-server-10.5.21      Multithreaded SQL database (server)
mariadb106-client-10.6.14      Multithreaded SQL database (client)
mariadb106-server-10.6.14      Multithreaded SQL database (server)
p5-DBD-MariaDB-1.21            MariaDB driver for the Perl5 Database Interface (DBI)

Next, install the MariaDB server and client package from the above list using the following command:

pkg install mariadb1011-server-10.11.5 mariadb1011-client-10.11.5

Once both packages are installed, enable the MariaDB package to start at system reboot.

sysrc mysql_enable="yes"

Next, start the MariaDB service.

service mysql-server start

Next, run the mysql_secure_installation script to secure the installation.

/usr/local/bin/mysql_secure_installation

Answer all the questions as shown below:

Enter current password for root (enter for none): 
Switch to unix_socket authentication [Y/n] Y
Change the root password? [Y/n] Y
New password: 
Re-enter new password: 
Remove anonymous users? [Y/n] Y
Disallow root login remotely? [Y/n] Y
Remove test database and access to it? [Y/n] Y
Reload privilege tables now? [Y/n] Y

Next, verify the MariaDB databases using the following command.

mysql -u root -p -e "show databases"

You will see all default databases in the following output.

+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+

Step 3 – Install PHP

You can install PHP with other extensions using the following command:

pkg install php80 mod_php80 php80-mbstring php80-zlib php80-curl php80-gd php80-mysqli nano-7.2

After installing PHP, you must create a PHP configuration file for the Apache web server. You can create it with the following command:

nano /usr/local/etc/apache24/Includes/php.conf

Add the following configurations:

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

Save and close the file, then create a simple info.php file to test the web server.

nano /usr/local/www/apache24/data/info.php

Add the following code:

<?php phpinfo();  ?>

Save and close the file, then restart the Apache service to apply the changes.

service apache24 restart

Now, open your web browser and access the info.php file using the URL http://your-server-ip/info.php. You will see the PHP information page.

PHP test page

Conclusion

This post showed you how to install Apache, MariaDB, and PHP (FAMP) stack on FreeBSD. Using this stack, you can deploy any web application easily on the internet. Try to deploy the FAMP stack on dedicated server hosting from Atlantic.Net!