The FAMP stack, which resembles a LAMP stack on Linux, is a collection of open source software that is usually installed together to enable a FreeBSD server to host dynamic websites and web applications . FAMP is an acronym that stands for F reeBSD (operating system), A pache (HTTP server), M ySQL / M ariaDB (database server) and P HP (programming language for processing dynamic PHP content).
In this tutorial we will set up components in a FAMP stack on a FreeBSD 12.1 server with
pkg FreeBSD package manager.
Before you start this guide, you need the following:
- A FreeBSD 1
- A user with root privileges or
sudouser to make configuration changes.
- Basic knowledge of the FreeBSD system and command line interface is recommended.
Before you begin
Check the FreeBSD version:
Make sure your FreeBSD system is up to date:
freebsd-update fetch install
pkg update && pkg upgrade -y
Install required packages:
pkg install -y sudo vim bash curl
Create a new user account with your username. We use
# Username: johndoe
# Full name: John Doe
# Uid (leave blank by default):
# Login group [johndoe] :
# Login group is johndoe. Invite johndoe to other groups? : wheels
# Login class [default]:
# Shell (sh csh tcsh nology) [sh]: bash
# Home directory [/home/johndoe]:
# Home directory permissions (Leave blank by default) :
# Use password-based authentication? [yes]:
# Use an empty password? (yes / no) [no]:
# Use a random password? (yes / no) [no]:
# Enter password: your_secure_password
# Re-enter password: your_secure_password
# Unlock account after creation? [no]:
# OK? (yes / no): yes
# Add another user? (yes / no): no
visudo and divide
% wheel ALL = (ALL) ALL to allow members of the
wheel group to perform which command any time:
# Uncomment by removing the hash (#) character
#% wheel ALL = (ALL) ALL
Now switch to your newly created user with
su - johndoe
johndoe with your username.  Set the time zone:
Step 1 – Install Apache 2.4
The Apache web server is currently one of the most popular web servers in the world. It is a great choice for web hosting.
You can install Apache with FreeBSD's package manager,
pkg . A package manager allows you to install most software without any problem from an archive maintained by FreeBSD.
To install Apache, issue the following command:
sudo pkg install -y apache24
httpd - v
# Server Version: Apache / 2.4.41 (FreeBSD)
Now enable and start Apache:
sudo sysrc apache24_enable = yes
sudo service apache24 start
Make sure Apache has started you can run the following command:
sudo service apache24 status
As a result, you see something like:
apache24 runs as pid 17775.
You can verify that Apache was installed and working without errors by visiting the server's public IP address in your browser. Navigate to
http: // your_server_IP . You see the default value " It works! " Apache page.
Step 2 – Install MySQL 8.0
Now that your web server is running, it's time to install MySQL, relational database management system. The MySQL server will organize and provide access to databases where your server can store information.
Again, you can use
pkg to get and install your software.
To install MySQL
pkg use this command:
sudo pkg install -y mysql80-client mysql80 server
This command installs the latest version of The MySQL client and server, which is currently
# mysql Ver 8.0.17 for FreeBSD12.0 on amd64 (Source Distribution)
Now, enable and start MySQL:
sudo sysrc mysql_enable = yes
sudo service mysql-server start
To verify that MySQL has started, you can run the following command:
sudo service mysql-server status
You will see something like the following:
mysql is run as pid 19171.
As a good practice, you must run
mysql_secure_installation security script that will remove some insecure defaults and somewhat restrict access to your database system:
sudo mysql_sec1 ] You will be asked to set a password, followed by some other questions. Enter a strong password, and then press for the rest of the questions: key_enter: to select the default settings.
Step 3 - Install PHP 7.4
PHP is a server-side scripting language designed for web development. PHP is an indispensable component of the FAMP stack. Python or Perl is often used instead of PHP. But PHP as the most popular option is most often used. Along with the database, it will give your websites or apps dynamic behavior.
Again utilize the
pkgsystem to install PHP components.
To install PHP
pkgrun this command:
sudo pkg install -y php74 php74-mysqli mod_php74
php74  ] mod_php74and
Check PHP version:
php - version
# PHP 7.4.1 (cli) (built: Jan 2, 2020 1:32:38 PM) (NTS)
# Copyright (c) PHP Group
# Zend Engine v3.4.0, Copyright (c) Zend Technologies
Copy the sample PHP configuration file into place with this command:
sudo cp /usr/local/etc/php.ini -production /usr/local/etc/php.inivud19659011achteNow, enable and start PHP-FPM:
sudo sysrc php_fpm_enable = yes
sudo service php-fpm start
To verify that PHP-FPM has started d you can run the following command:
sudo service php-fpm status
As a result, you see something similar:
php_fpm runs as pid 23005.
Install PHP modules (optional)
To improve PHP's functionality, you can optionally install some additional modules.
To see currently compiled in PHP modules, you can run this:
# [PHP Modules]
# [Zend Modules]
To search for available PHP modules, you can use this command:
pkg search ^ php74 - *
The results are mostly PHP 7.4 modules that you can install:
# Output # php74-7.4.0 PHP Scripting Language # php74-Ice37-3.7.2_1 Modern alternative to middleware for objects like CORBA / COM / DCOM / COM + # php74-aphpbreakdown-2.2.2 Code Analyzer for Compatibility Check PHP # php74-aphpunit-1.9 Test framework for device tests # php74-bcmath-7.4.0 The shared bcmath extension for php # php74-fragli-0.7.0 Brotli extension for PHP # php74-bsdconv-11.5.0 PHP wrapper for bsdconv # php74-bz2-7.4.0 The shared bz2 extension for php # php74-calendar-7.4.0 The shared calendar extension for php # php74-composer-1.8.6 Dependency Manager for PHP # php74-ctype-7.4.0 Ctype shared extension for php # php74-curl-7.4.0 The shared curl extension for php #. . .
If, after researching, you decide that you need to install a package, you can do so using the command
pkg install. Most PHP web applications will require additional modules, so it's good to know how to search for them.
Step 4 - Configure Apache to use PHP module
Before using PHP, you must configure it to work with Apache.  Run
sudo vim /usr/local/etc/apache24/modules.d/001_mod-php.confebrit19459007] and fill in the file with the content below:
DirectoryIndex index.php index.html SetHandler application / x-httpd-php SetHandler application / x-httpd-php source
Save the file and exit from vim.
Check Apache configuration:
sudo apachectl configtest
Because you have made configuration changes in Apache, you must reload the service for those to be applied. Otherwise, Apache still works with the previous configuration:
sudo apachectl reboot
Step 5 - Test PHP Processing
To test that your system is configured correctly for PHP, you can create a very basic PHP script. You will call this script
info.php. By default,
DocumentRootis set to
/ usr / local / www / apache24 / data. You can create the
info.phpfile under that location by typing:
sudo vim /usr/local/www/apache24/data/info.phpebrit19659011achteAnd add this code to that file: 
http: //your_server_IP/info.phpand you will see the following page:
After FAMP stack installation and setup, you should delete the
info.phpfile to avoid revealing information about the server to the public:
sudo rm /usr/local/www/apache24/data/info.phpebrit19659109/11Closing19199009004achtConversions, you have installed FAMP stack on your FreeBSD 12.1 server. Now you have several choices for what to do next. You have installed a platform that allows you to install most types of websites and web software on top of it.