How To Install Apache, MariaDB & PHP (FBAMP) on FreeBSD

When managing any operating system that is open source, it is ideal that we have in mind the various tools and applications that we can use to implement the potential of that system fully.

One of these operating systems is FreeBSD which is a derivative of BSD, the UNIX version for compatible x86 architectures.

In this opportunity, we will see how we can install FBAMP, or as we know in some versions of Linux as LAMP in this FreeBSD system.

What is FBAMP?

  • FB: FreeBSD
  • A: Apache, most popular open source web server today.
  • M: MariaDB, is a relational database management system.
  • P: PHP, an open source language for web development and that can be embedded in HTML.

Now we will see how to install these applications in FreeBSD in a practical way.

Install Apache on FreeBSD

By default, on FreeBSD, we will have multiple versions on hand which have different runtime modules for the Apache web server.

These versions are pre-compiled in a binary package and provided by FreeBSD PORTS repositories.

If we want to deploy all binary Apache packages provided by PORTS, it will be necessary to execute the following command in FreeBSD:

ls /usr/ports/www/ | grep apache

Another option to look for pre-compiled packages available from Apache on FreeBSD is to run the following command:

pkg search apache2

With this defined, the next step will be to install the latest version of the Apache HTTP server with all the necessary modules by executing the following command:

pkg install apache24

Once the Apache web server is installed in FreeBSD, we must run the following command to enable the daemon in the whole system.

sysrc apache24_enable="yes"

As another alternative to enable the Apache daemon, it would be to manually edit and add the line apache24_enable = “yes” in the file “/etc/rc.conf” using the desired editor:

nano /etc/rc.conf

Once the Daemon is enabled, we will execute the following command to start the Apache service in FreeBSD:

service apache24 start

service apache24 status

To verify that Apache has been installed correctly we will check the IP address of FreeBSD, and in some browser, we will enter the following syntax:

http://IP_FreeBSD

Note: The default webroot directory of the Apache web server in FreeBSD 11.1 will be on the route /usr/local/www/apache24/data/

Install PHP on FreeBSD

Like Apache, FreeBSD offers several packages packaged in binaries for the PHP language.

To obtain a list of all available PHP version packages provided by the FreeBSD Ports repositories, we will execute the following command:

ls /usr/ports/lang/ | grep php

We can also get this result by running the following command:

pkg search -o php

To find all available binaries provided by FreeBSD for a specific version of PHP, we will use the following commands (based on PHP version 5 or 7):

pkg search php5 |less

pkg search php7

In this case, we will install PHP 7.1, and for this, we will execute the following command to install PHP with some of the essential modules necessary for a standard installation of PHP:

pkg install php71 mod_php71 php71-mbstring php71-mcrypt php71-zlib php71-curl php71-gd php71-json

Now, it will be required to create the php.conf configuration file for the Apache web server in the directory /usr/local/etc/apache24/Includes/ and to do this we will execute the following:

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

In the new file we will paste the following:

<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 the changes and close the file.

Now we can go back to the browser and enter the following syntax to validate PHP:

http : //IP_FreeBSD/info.php

Install MariaDB on FreeBSD

The next step is to install the MariaDB database manager and to validate which components are available for the MariaDB databases we will execute the following command. We can see the various options available.

ls -al /usr/ports/databases/ | grep mariadb

In this case, we will install the mariadb102 package by executing the following command:

pkg install mariadb102-server mariadb102-client php71-mysqli

Now, we will enable the MariaDB server in FreeBSD and initiate the daemon of the database by running the following commands:

sysrc mysql_enable="yes"

service mysql-server start

Now we will ensure the installation of MariaDB by executing the mysql_secure_installation line in the following way:

/usr/local/bin/mysql_secure_installation

That command will initiate a series of questions that we must define based on the current needs:

By default, the MariaDB daemon listens for network connections outside localhost on port 3306 / TCP.

We can execute the commands netstat, lsof or sockstat to obtain the status of the MariaDB socket, since this configuration is dangerous and exposes the service to external network attacks affecting the data hosted there.

lsof -i4 -i6

sockstat -4 -6

If isn't necessary the remote access to MariaDB, we must make sure that the daemon of MariaDB only listens to the localhost, for it we execute the following command.

Then, restart the MariaDB service to apply the changes.

sysrc mysql_args="--bind-address=127.0.0.1"

service mysql-server restart

Test MariaDB on FreeBSD

Finally to test the connectivity to the database we will execute the following command.:

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

There we will enter the password that has been assigned, and this will be the result:

In this way we have installed Apache, PHP and MariaDB in FreeBSD in a simple way.

Similar Posts

Leave a Reply

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