Install Apache, MySQL, PHP (FAMP) Stack on FreeBSD 12

0
8446

Install Apache, MySQL, PHP (FAMP) Stack on FreeBSD 12

Welcome to our tutorial on how to install Apache, MySQL, PHP (FAMP) 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.

In our previous tutorials, we have described installing LAMP Stack on Linux systems. You can check them on the links below;

Install Apache, MySQL, PHP (FAMP) Stack on FreeBSD 12

To install FAMP stack on FreeBSD 12, step through the following procedure;

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.

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

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

sysrc mysql_enable=yes

Start MySQL

service mysql-server start

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

Next, remove anonymous users, disallow remote root login , remove test databases and 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!

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.

pkg install php72 php72-mysqli mod_php72 php72-mbstring php72-zlib php72-curl php72-gd php72-json

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

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 to process PHP pages by creating a php.conf configuration file under /usr/local/etc/apache24/Includes/ with the following contents;

vim /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>

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.

vim /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 Apache, MySQL, PHP (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 Apache, MySQL, PHP (FAMP) Stack on FreeBSD 12. Thank you for reading. We hope this was informative. 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