Install LAMP on FreeBSD 12.x

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

im happy to start the first article on this blog about LAMP on FreeBSD 12.x. maybe we have to call it FAMP instead of LAMP because it’s FreeBSD based and Not Linux based. Hier we have talking about install A apache / M Mysql of Mariadb and P PHP.

Before to start let me inform you about my environment.

-IP Server 51.79.68.50

-FreeBSD 12.1

-User with Sudo Rechten

Lets first start with updating our FreeBSD packages and repositories

freebsd-update fetch install
pkg update && pkg upgrade -y

There is two ways to install AMP , Via ports and via pkg FreeBSD package manager allowing to install all thing from FreeBSD repositories .

1-Lets start with Apache

Install apache with the command .

sudo pkg install -y apache24

To run apache www server from startup, add apache24_enable=”yes”
in your /etc/rc.conf. Extra options can be found in startup script.

you can also do it with these commands bellow

sudo sysrc apache24_enable=yes
sudo service apache24 start

Check the status with

sudo service apache24 status

Or with ps command in FreeBSD

sudo ps auwwx

Where to find apache confguration in FreeBSD ?

/usr/local/etc/apache24/httpd.conf

What is the DocumentRoot standard in FreeBSD ?

DocumentRoot "/usr/local/www/apache24/data"

2-Install Mysql 8

lets remember we have also the choice to install Mariadb , but this time we go with the original Mysql

How to install Mysql in FreeBSD 12

sudo pkg install -y mysql80-client mysql80-server

Check installed my version

[unixcop@vps-cdce6394 ~]$ mysql --version
mysql Ver 8.0.23 for FreeBSD12.2 on amd64 (Source distribution)

Enable and start Mysql

sudo sysrc mysql_enable=yes
sudo service mysql-server start

Set Root Mysql password

sudo mysql_secure_installation

Chcek if ur access to mysql working
[unixcop@vps-cdce6394 ~]$ mysql  -u root -p 
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 20
Server version: 8.0.23 Source distribution

Copyright (c) 2000, 2021, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

root@localhost [(none)]> create database UNIXCOP;
Query OK, 1 row affected (0.01 sec)

root@localhost [(none)]> 

3- Install PHP8 in FreeBSD

PHP is needed to run your web applications lets try to install latest PHP on FreeBSD

sudo pkg install -y php80 php80-mysqli mod_php80

Check PHP version in FreeBSD

[unixcop@vps-cdce6394 ~]$ php -v
PHP 8.0.2 (cli) (built: Feb 9 2021 01:22:53) ( NTS )
Copyright (c) The PHP Group
Zend Engine v4.0.2, Copyright (c) Zend Technologies

Enable php.ini file

sudo cp /usr/local/etc/php.ini-production /usr/local/etc/php.ini


Now, enable and start PHP-FPM:

sudo sysrc php_fpm_enable=yes
sudo service php-fpm start

To check if PHP-FPM has started you can run the following command:

sudo service php-fpm status

How to find installed PHP modules

use the command php-m

[unixcop@vps-cdce6394 ~]$ php -m
[PHP Modules]
Core
date
hash
json
libxml
mysqli
mysqlnd
pcre
Reflection
SPL
standard

[Zend Modules]


How to Search PHP Modules in FreeBSD

sudo pkg search ^php80-*

Configure Php to work with Apache

Run sudo vim /usr/local/etc/apache24/modules.d/001_mod-php.conf and add to the file the below content:

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

Restart Apache

sudo apachectl restart

Test of PHP page . please add this code to /usr/local/www/apache24/data/test.php

<?php phpinfo(); ?>

Please call the page http://IP/test.php

Congrats your Servers is ready to user as Webserver included Apache/Mysql and PHP

Everything Linux, A.I, IT News, DataOps, Open Source and more delivered right to you.
Subscribe
"The best Linux newsletter on the web"
Mel
Melhttps://unixcop.com
Unix/Linux Guru and FOSS supporter

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest articles

Join us on Facebook