23.8 C
Guru Unix /Linux and GNU supporter

How to Install Apache PHP7 and MariaDB on FreeBSD12

Some People are  calling this FAMP because its related to install  Apache PHP and Mysql on  Freebsd instead of Linux.  let me guide you in this  installation of FAMP on my   local FreeBSD 12 just  released today .

My FreeBSD have IP

First  Updates all your FreeBSD  ports

portsnap fetch update
portsnap extract
portsnap update
- Advertisement -

1-Install apache  on FreeBSD12

the package installer of FreeBSD is  pkg

install  with this  comand

pkg  install apache24

enable the daemon system-wide in FreeBSD.

Start Apache

#service apache24 start

Check  the status 

#service apache24  status

Apche24 root Directory is /usr/local/www/apache24/data you can edit the index.html to anything you want like my example bellow.

Please browse to the host : http://ip or http://fqdn

2-Install PHP7 on FreeBSD12

you have two ways to install PHP7

Install php 7 via  Ports

ls /usr/ports/lang/ | grep php
cd /usr/ports/lan/php73
make install clean

Also do the same for the  php extensions  but to avoid any dependencies issues i will advice to install php from the pkg manager

install php7 via package manager on FreeBSD 12  

Find latest php7  release from FreeBSD repositories

seach for the latest release from repo. for now is php72  is the latest release i think  php73 will be sonn pushed to the repo

pkg search  php72

Install  php72  and some  needed  pjp  modules  on FreeBSD 12

pkg install php72 mod_php72 php72-mbstring php71-mcrypt php72-zlib php72-curl php72-gd php72-json

you see i’m using php71-mycript because the version 72  is not yet released  till today

to make php  working with apache we need extra php file configuration  (/usr/local/etc/apache24/Includes/php.conf)  with  this  content

<IfModule dir_module>
DirectoryIndex index.php index.html
<FilesMatch "\.php$">
SetHandler application/x-httpd-php
<FilesMatch "\.phps$">
SetHandler application/x-httpd-php-source

How to test the PHP configuration.

Please do the  follow  command

echo '<?php phpinfo();  ?>' | tee -a /usr/local/www/apache24/data/info.php

Now restart  apache  and  checlk  http://ip/info.php

service apache24 restart


Looks good 🙂

3-Install MariaDB on FreeBSD12

Now we will continue using the binary package method

root@:/usr/local/www/apache24/data # pkg search mariadb
mariadb-connector-c-3.0.6 MariaDB database connector for C
mariadb-connector-odbc-3.0.3 MariaDB database connector for odbc
mariadb102-client-10.2.19 Multithreaded SQL database (client)
mariadb102-server-10.2.19 Multithreaded SQL database (server)
mariadb103-client-10.3.11 Multithreaded SQL database (client)
mariadb103-server-10.3.11 Multithreaded SQL database (server)
root@:/usr/local/www/apache24/data #

Install Mariadb server and client

pkg install mariadb103-server-10.3.11 mariadb103-client-10.3.11 php72-mysqli1 php72-mysqli

Enable MariaDB server system-wide and start the database daemon

# sysrc mysql_enable="yes" 
# service mysql-server start

Configure and set root  mysql password 

root@:/usr/local/www/apache24/data # /usr/local/bin/mysql_secure_installation


In order to log into MariaDB to secure it, we'll need the current
password for the root user. If you've just installed MariaDB, 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 MariaDB
root user without the proper authorisation.

Set root password? [Y/n] y
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
... Success!

By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB 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? [Y/n] 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? [Y/n] y
... Success!

By default, MariaDB 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? [Y/n] 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? [Y/n] y
... Success!

Cleaning up...

All done! If you've completed all of the above steps, your MariaDB
installation should now be secure.

Thanks for using MariaDB!

You are  Done.

Please  login to see if your root password is working.

mysql -u root -p

Sockstat command

This Sockstat will show you  all  connection listening  on Ipv4

- Advertisement -
Everything Linux, A.I, IT News, DataOps, Open Source and more delivered right to you.
"The best Linux newsletter on the web"


Please enter your comment!
Please enter your name here

Latest article