Install Apache MariaDB and PHP 7 on FreeBSD 11

0
53

I know this wonderful system for a very long time. I like it and it’s giving me the feeling of security and transparency, the system was hacked some years ago but now, it looks strong and more open. One of the most powerful things on FreeBSD is the stability and the Solid File system.  let me tell you how I have installed FAMP  (FreeBSD Apache MariaDB PHP)  on my VirtualBox.

My Test Server is FreeBSD based on VirtualBox tool and its running fine

root@osradarBSD:~ # uname -a
FreeBSD osradarBSD 11.1-RELEASE FreeBSD 11.1-RELEASE #0 r321309: Fri Jul 21 02:08:28 UTC 2017 root@releng2.nyi.freebsd.org:/usr/obj/usr/src/sys/GENERIC amd64
root@osradarBSD:~ #

Install Apache 2.4 in FreeBSD

To install Apache, please use the tool pkg to avoid any dependencies issues:

root@osradarFreeBSD:~ # pkg install apache24
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):
New packages to be INSTALLED:
apache24: 2.4.33
libnghttp2: 1.31.1
apr: 1.6.3.1.6.1_1
db5: 5.3.28_6
Number of packages to be installed: 4
The process will require 77 MiB more space.
18 MiB to be downloaded.
Proceed with this action? [y/N]:

Start Apache at boot

To run apache www server from startup, add

apache24_enable="yes"

Start Apache

root@osradarFreeBSD:~ # service apache24 start
Performing sanity check on apache24 configuration:
Syntax OK
Starting apache24.
root@osradarFreeBSD:~ #

Apache conf file in FreeBSD is  “/usr/local/etc/apache24/httpd.conf”

Apache DocumentRoot in FreeBSD is under  “/usr/local/www/apache24/data”

Check if  Apache web server is running

Go to http://IP

It works!!

How to install  MariaDB On FreeBSD 11.x

Show the available release:

root@osradarFreeBSD:/usr/ports/databases # pkg search mariadb
mariadb-connector-c-3.0.3_1 MariaDB database connector for C
mariadb-connector-odbc-3.0.3 MariaDB database connector for odbc
mariadb100-client-10.0.34 Multithreaded SQL database (client)
mariadb100-server-10.0.34 Multithreaded SQL database (server)
mariadb101-client-10.1.33 Multithreaded SQL database (client)
mariadb102-client-10.2.14 Multithreaded SQL database (client)
mariadb102-server-10.2.14 Multithreaded SQL database (server)
mariadb55-client-5.5.60 Multithreaded SQL database (client)
mariadb55-server-5.5.60 Multithreaded SQL database (server)
root@osradarFreeBSD:/usr/ports/databases #

Now, install the latest Server and Client release 

root@osradarFreeBSD:/usr/ports/databases # pkg install mariadb102-server-10.2.14 mariadb102-client-10.2.14
Updating FreeBSD repository catalogue...
FreeBSD repository is up to date.
All repositories are up to date.
The following 3 package(s) will be affected (of 0 checked):
New packages to be INSTALLED:
mariadb102-server: 10.2.14
mariadb102-client: 10.2.14
unixODBC: 2.3.5
Number of packages to be installed: 3
The process will require 239 MiB more space.
32 MiB to be downloaded.
Proceed with this action? [y/N]:

Now set mysql_enable to YES in /etc/rc.conf  to automate starting MySQL server on next reboot

I’m setting up a medium sized server, so I’m going to copy /usr/local/share/mysql/my-medium.cnf to /usr/local/etc/ directory using cp command: # cp /usr/local/share/mysql/my-medium.cnf /usr/local/etc/my.cnf

Set MySQL root password

'/usr/local/bin/mysqladmin' -u root password 'new-password'

Alternatively, you can run:

'/usr/local/bin/mysql_secure_installation'

If facing any problem, don’t hesitate to remove all files inside /var/db/mysql :

root@osradarFreeBSD:~ # rm -rf /var/db/mysql/*

Restart MySQL and check

root@osradarFreeBSD:~ # mysql -u root -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 10
Server version: 10.2.14-MariaDB-log FreeBSD Ports
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> show databases
-> ;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+
4 rows in set (0.00 sec)
MariaDB [(none)]>create database osradar1;
Query OK, 1 row affected (0.00 sec)
MariaDB [(none)]> CREATE USER 'osradaruser'@'localhost' IDENTIFIED BY '222';
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> GRANT ALL ON osradar1.* TO 'osradaruser'@'localhost';
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> FLUSH privileges;
Query OK, 0 rows affected (0.00 sec)

Install   PHP 7 on FreeBSD 11

You need 2 packages  mod_php71 php71-mysqli

root@osradarFreeBSD:~ # pkg install mod_php71 php71-mysqli
Updating FreeBSD repository catalogue...
FreeBSD repository is up to date.
All repositories are up to date.
The following 3 package(s) will be affected (of 0 checked):
New packages to be INSTALLED:
mod_php71: 7.1.17
php71-mysqli: 7.1.17
php71: 7.1.17
Number of packages to be installed: 3
The process will require 27 MiB more space.
4 MiB to be downloaded.
Proceed with this action? [y/N]:

Copy your php.ini from the template:

root@osradarFreeBSD:~ # ls /usr/local/etc/php.*
php.conf php.ini-development php.ini-production
root@osradarFreeBSD:~ # cp /usr/local/etc/php.ini-development /usr/local/etc/php.ini

In order to configure PHP, you needed to edit the httpd.conf file.

Make sure that the line to load the php7_module did exist, and add the  AddType below:

LoadModule php7_module libexec/apache24/libphp7.so AddType application/x-httpd-php .php
 In the dir_module entry, added index.php to the existing index.html in the DirectoryIndex:
<IfModule dir_module>     DirectoryIndex index.php index.html </IfModule>

Also, add the following lines at the end of the file:

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

Exit.

Check if the syntaxes are ok.

root@osradarFreeBSD:~ # httpd -t
Syntax OK

Now, create the PHP info test  page

vi /usr/local/www/apache24/data/test.php

Add

<?php phpinfo(); ?>

Restart  apache and  check http://ip/test.php

Install phpMyAdmin on FreeBSD 11

phpMyAdmin is also available in default repository of FreeBSD. You can install phpMyAdmin directly by running the following command.

Please find the release of phpMyAdmin:

root@osradarFreeBSD:/usr/local/www/apache24/data # pkg search phpmyadmin
phpMyAdmin-php56-4.8.0.1 Set of PHP-scripts to manage MySQL over the web
phpMyAdmin-php70-4.8.0.1 Set of PHP-scripts to manage MySQL over the web
phpMyAdmin-php71-4.8.0.1 Set of PHP-scripts to manage MySQL over the web
phpMyAdmin-php72-4.8.0.1 Set of PHP-scripts to manage MySQL over the web
root@osradarFreeBSD:/usr/local/www/apache24/data #

Install now the release compatible with your PHP:

pkg install phpMyAdmin-php71-4.8.0.1
New packages to be INSTALLED:
phpMyAdmin-php71: 4.8.0.1
php71-session: 7.1.17
php71-xml: 7.1.17
php71-ctype: 7.1.17
php71-openssl: 7.1.17
php71-filter: 7.1.17
php71-gd: 7.1.17
php71-json: 7.1.17
php71-mbstring: 7.1.17
oniguruma: 6.8.1
php71-zlib: 7.1.17
php71-zip: 7.1.17
libzip: 1.3.2
php71-bz2: 7.1.17

The above command will download and install phpMyAdmin. The application will be installed in /usr/local/www/phpMyAdmin/ directory.

Copy the sample phpMyAdmin configuration  from the templates:

cp /usr/local/www/phpMyAdmin/config.sample.inc.php /usr/local/www/phpMyAdmin/config.inc.php

Make an symbolik of phpmyadmin in Root apache  folder .

ln -s /usr/local/www/phpMyAdmin/ /usr/local/www/apache24/data/phpmyadmin

Restart the Apache web server by running:

service apache24 restart

Access phpMyAdmin

you can access from http://ip/phpmyadmin

 

Spread the love
  • 11
    Shares

LEAVE A REPLY

Please enter your comment!
Please enter your name here