How to install FAMP in FreeBSD

To install FAMP in FreeBSD

A FAMP stack is similar to a LAMP stack in Linux. It is a free source web application. Usually PHP based websites install FAMP for greater performance and low maintenance. FAMP stands for FreeBSD (operating system), Apache (web server), MySQL (database server), and PHP (to process dynamic PHP content). Installation of FAMP is explained in this manual.

To install Apache

Run the following command to install Apache.

root@linuxhelpBSD:~ # pkg install apache24  
Updating FreeBSD repository catalogue...
FreeBSD repository is up-to-date.
All repositories are up-to-date.
The following 2 package(s) will be affected (of 0 checked):
New packages to be INSTALLED:
    apache24: 2.4.23_1
    apr: 1.5.2.1.5.4_1

Number of packages to be installed: 2
The process will require 27 MiB more space.
.
.
.
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

- apache24 default build changed from static MPM to modular MPM
- more modules are now enabled per default in the port
- icons and error pages moved from WWWDIR to DATADIR

   If build with modular MPM and no MPM is activated in
   httpd.conf, then mpm_prefork will be activated as default
   MPM in etc/apache24/modules.d to keep compatibility with
   existing php/perl/python modules!

Please compare the existing httpd.conf with httpd.conf.sample
and merge missing modules/instructions into httpd.conf!

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!


Then start the Apache service by running the following command.

root@linuxhelpBSD:~ # service apache24 start 
Performing sanity check on apache24 configuration:
AH00557: httpd: apr_sockaddr_info_get() failed for linuxhelpBSD
AH00558: httpd: Could not reliably determine the server' s fully 
qualified domain name, using 127.0.0.1. Set the ' ServerName'  directive 
globally to suppress this message
Syntax OK
Starting apache24.
AH00557: httpd: apr_sockaddr_info_get() failed for linuxhelpBSD
AH00558: httpd: Could not reliably determine the server' s fully 
qualified domain name, using 127.0.0.1. Set the ' ServerName'  directive 
globally to suppress this message

To install MySQL

Run the following command to install MySQL server.

root@linuxhelpBSD:~ # pkg install mysql56-server 
Updating FreeBSD repository catalogue...
FreeBSD repository is up-to-date.
All repositories are up-to-date.
The following 2 package(s) will be affected (of 0 checked):

New packages to be INSTALLED:
    mysql56-server: 5.6.32
    mysql56-client: 5.6.32

Number of packages to be installed: 2

The process will require 129 MiB more space.
10 MiB to be downloaded.

Proceed with this action? [y/N]: y
Fetching mysql56-server-5.6.32.txz: 100%    8 MiB  85.0kB/s    01:40    
Fetching mysql56-client-5.6.32.txz: 100%    2 MiB 100.4kB/s    00:20    
Checking integrity... done (0 conflicting)
[1/2] Installing mysql56-client-5.6.32...
[1/2] Extracting mysql56-client-5.6.32: 100%
[2/2] Installing mysql56-server-5.6.32...
===>  Creating groups.
Creating group ' mysql'  with gid ' 88' .
===>  Creating users
.
.
.

* * * * * * * * * * * * * * * * * * * * * * * *
Message from mysql56-server-5.6.32:
************************************************************************

Remember to run mysql_upgrade the first time you start the MySQL server
after an upgrade from an earlier version.

************************************************************************


Enable startup service for MySQL.

root@linuxhelpBSD:~ # sysrc mysql_enable=yes 
mysql_enable:  ->  yes


Then start the MySQL service.

root@linuxhelpBSD:~ # service mysql-server start 
Starting mysql.


Run the “ mysql_secure_installation” command to complete the MySQL installation process.

root@linuxhelpBSD:~ # mysql_secure_installation 

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MySQL to secure it, we' ll need the current
password for the root user.  If you' ve just installed MySQL, and
you haven' t set the root password yet, the password will be blank,
so you should just press enter here.
Enter current password for root (enter for none): 
OK, successfully used password, moving on...
Setting the root password ensures that nobody can log into the MySQL
root user without the proper authorisation.
Set root password? [Y/n] y
New password: 
Re-enter new password: 
.
.
.

Reload privilege tables now? [Y/n] y
 ... Success!
All done!  If you' ve completed all of the above steps, your MySQL
installation should now be secure.
Thanks for using MySQL!
Cleaning up...

To install php

Next start installing php by using “ pkg install” command.

root@linuxhelpBSD:~ # pkg install mod_php56 php56-mysql php56-mysqli 
Updating FreeBSD repository catalogue...
FreeBSD repository is up-to-date.
All repositories are up-to-date.
The following 4 package(s) will be affected (of 0 checked):
.
.
.
Message from mod_php56-5.6.25:
***************************************************************

Make sure index.php is part of your DirectoryIndex.

You should add the following to your Apache configuration file:

< FilesMatch " .php$" > 
    SetHandler application/x-httpd-php
< /FilesMatch> 

< FilesMatch " .phps$" > 
    SetHandler application/x-httpd-php-source
< /FilesMatch> 

***************************************************************


Then copy " php.ini-production" file to " php.ini" file.

root@linuxhelpBSD:~ # cp /usr/local/etc/php.ini-production  /usr/local/etc/php.ini 


After copying the configuration file, run the “ rehash” command to reload the changes.

root@linuxhelpBSD:~ # rehash 


Edit the httpd.conf file and add the following lines into it.

root@linuxhelpBSD:~ # nano /usr/local/etc/apache24/httpd.conf 
.
.
.

# DirectoryIndex: sets the file that Apache will serve if a directory
# is requested.
#
< IfModule dir_module> 

DirectoryIndex index.php index.html

< /IfModule> 

#
.
.
.
Include etc/apache24/Includes/*.conf

< FilesMatch " .php$" > 
 SetHandler application/x-httpd-php
< /FilesMatch> 

< FilesMatch " .phps$" > 
 SetHandler application/x-httpd-php-source
< /FilesMatch> 


Run the following command to create a sample.php file to test the FAMP configuration.

root@linuxhelpBSD:~ # nano /usr/local/www/apache24/data/sample.php 
< ?php phpinfo()  ?> 


Then restart the Apache servcie by utilizing the below command.

root@linuxhelpBSD:~ # service apache24 restart 
Performing sanity check on apache24 configuration:
AH00557: httpd: apr_sockaddr_info_get() failed for linuxhelpBSD
AH00558: httpd: Could not reliably determine the server' s fully
qualified domain name, using 127.0.0.1. Set the ' ServerName'  directive
globally to suppress this message
Syntax OK
Stopping apache24.
Waiting for PIDS: 1610.
Performing sanity check on apache24 configuration:
AH00557: httpd: apr_sockaddr_info_get() failed for linuxhelpBSD
AH00558: httpd: Could not reliably determine the server' s fully
qualified domain name, using 127.0.0.1. Set the ' ServerName'  directive
globally to suppress this message
Syntax OK
Starting apache24.
AH00557: httpd: apr_sockaddr_info_get() failed for linuxhelpBSD
AH00558: httpd: Could not reliably determine the server' s fully
qualified domain name, using 127.0.0.1. Set the ' ServerName'  directive
globally to suppress this message


Open the browser and navigate to http://< IP_address>

Open a new tab and type the URL http://< IP_address> /sample.php

Tag : FAMP
FAQ
Q
why should we remove other users?
A
Removing anonymous user helps you to login pnly as a root
Q
Shall I use Mariadb instead of Mysql in FAMP?
A
You can use any DB as per your preference in FAMP
Q
It is ok to remove the test database in FAMP?
A
Yes, it's the part of securing the DB in FAMP.
Q
Do we need PHP modules in FAMP?
A
Yes depends on the version of PHP you use in FAMP
Q
Why can't I able to see the password on DB in FAMP?
A
For security reasons you can't visually see the password while tyoing.