Install FAMP Stack on FreeBSD 12

|
Last Updated:
|
|
Install FAMP Stack on FreeBSD 12

Welcome to our tutorial on how to install FAMB Stack on FreeBSD 12. FAMP Stack is an acronym for FreeBSD, the Operating System, Apache the web server, MySQL the database server and PHP the server side scripting language.

Installing FAMP Stack on FreeBSD 12

Update Package Repository

Run the command below to update FreeBSD package repository;

pkg update

Install Apache on FreeBSD 12

Apache Web server is available on the default FreeBSD repositories and can be installed using the pkg package manager.

pkg install apache24

Start and Enable Apache

To start and enable Apache web server to run on system boot, run the commands below;

sysrc apache24_enable=yes

This will add the line apache24_enable="yes" at the end of the /etc/rc.conf configuration file.

Start Apache

service apache24 start

You can check the status of Apache as shown below;

service apache24 status
apache24 is running as pid 1206.

Note that we are using the default Apache FreeBSD configurations in this demo.

To verify that you can actually access you web server from the browser, navigate to the browser and type the IP address of your web server. If everything is working fine, you should be able to see the default FreeBSD Apache web page which says, “It Works!“.

Install MySQL on FreeBSD 12

Just like Apache, MySQL can be installed directly from default FreeBSD 12 default repositories using the package manager. To install MySQL 8.0, run the command below;

pkg install mysql80-server

Start and Enable MySQL Service

Enable MySQL as a service so it can start on system boot.

sysrc mysql_enable=yes

The start it;

service mysql-server start

Run MySQL Initial Secure Script

Run the normal MySQL security script to remove some default configurations.

mysql_secure_installation

The script may prompt you whether to enforce strong password creation. If you need to enforce secure password creation, then press y to accept and choose the level of password validation policy.


VALIDATE PASSWORD COMPONENT can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD component?

Press y|Y for Yes, any other key for No: y

There are three levels of password validation policy:

LOW    Length >= 8
MEDIUM Length >= 8, numeric, mixed case, and special characters
STRONG Length >= 8, numeric, mixed case, special characters and dictionary                  file

Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 1
Please set the password for root here.

New password: STRONG PASS

Re-enter new password: STRONG PASS

Estimated strength of the password: 100 
Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : y

Next;

  • remove anonymous users,
  • disallow remote root login,
  • remove test databases
  • reload privilege tables to effect the changes.

By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.

Remove anonymous users? (Press y|Y for Yes, any other key for No) : y
Success.


Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network.

Disallow root login remotely? (Press y|Y for Yes, any other key for No) : y
Success.

By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.


Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y
 - Dropping test database...
Success.

 - Removing privileges on test database...
Success.

Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.

Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y
Success.

All done!

You can now login to your MySQL server and create your databases!

Install PHP on FreeBSD 12

PHP works with HTML to generate dynamic web content. In order for PHP to connect to MySQL database to retrieve information for serving to the web server, you need to install PHP Apache and MySQL extensions. The following command installs the most common PHP modules.

Note that as of this writing, PHP 8.2 is the current stable release available on FreeBSD 12 repositories.

pkg install php82 php82-mysqli mod_php82 php82-mbstring php82-zlib php82-curl php82-gd

If you require other PHP extensions, you can simply search and install them as shown above.

Configure PHP

Copy the sample PHP configuration file into place and regenerate system cached information about installed binaries.

cp /usr/local/etc/php.ini{-production,}
rehash

Configure Apache Web Server

Configure Apache to process PHP pages by creating a php.conf configuration file under /usr/local/etc/apache24/Includes/ with the following contents;

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

<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 exit the file.

Test Apache PHP Processing

Create PHP test configuration file under the Apache default document root directory to verify whether PHP is working well with Apache web server. The default document root directory is /usr/local/www/apache24/data/test.php.

vi /usr/local/www/apache24/data/test.php
<?php phpinfo(); ?>

Save the file and restart Apache for the changes to take effect.

service apache24 restart

Navigate to the browser and the address in the format, http://server_IP_address/test.php.

Install FAMP Stack on FreeBSD 12

Beautiful. Now remove the test file from your server to avoid exposing the information about server to the public.

rm -rf /usr/local/www/apache24/data/test.php

That is all it takes to install FAMP Stack on FreeBSD 12.

Other Tutorials

You can as well check our other articles by following the links below;

Install Nginx, MySQL, PHP (FEMP) Stack on FreeBSD 12.

Install and Configure OpenVPN Server FreeBSD 12

Install and Configure Telegraf on FreeBSD 12

How to Install phpMyAdmin on FreeBSD 12

How to Install FreeBSD 12 on VirtualBox

Install phpMyAdmin with Nginx on FreeBSD 12