Installing FAMP on FreeBSD
FreeBSD is a Unix like operating system that has attracted popularity among people. This OS is light which makes it a great choice for hosting aims. In this tutorial we will help you install FAMP stack on FreeBSD. This stack installation helps you to make your FreeBSD as a web server.
FAMP is an acronym that stands for FreeBSD , Apache ,MySQL ,and PHP that we will install all these options on FreeBSD OS.
Notice: In this tutorial we have used a raw FreeBSD to prevent software interference. We recommend you to use a raw OS.
Join us with Installing FAMP on FreeBSD
FAMP installation on FreeBSD
FAMP Packages Installation
Before starting installation process, issue the below commands to update your FreeBSD and make it ready to FAMP packages installation.
freebsd-update fetch
freebsd-update instal
Installing Apache
With the server up-to-date, we will install Apache web server in next step.
Install Apache 2.4 on FreeBSD
To install and update Apache 2.4, use this command:
pkg install apache24
Note: If you have not used pkg since now, it will prompt you about its installation. Press Y key to let it to install pkg then issue the above command again to start Apache installation.
Enter y at the confirmation prompt.
use the bellow command to add Apache service to startup services:
sysrc apache24_enable=yes
now restart Apache using the bellow command:
service apache24 start
You can now verify that Apache is installed correctly by typing http:// and your IP address on your browser (http://YOUR.IP.ADD.RESS ). You should see apache default page. You have installed Apache on FreeBSD now we will install MySQL in the next step.
Install MySQL on FreeBSD
First, execute the bellow command to install MySQL:
pkg install mysql56-server
During installation, it will ask you about installation confirmation. Enter y at the confirmation prompt.
use the bellow command to enable MySQL service to start automatically at system boot process:
sysrc mysql_enable=YES
Now start the MySQL server:
service mysql-server start
Now we want to configure our MySQL. Start the interactive script by running this command:
sudo mysql_secure_installation
reply the questions below one by one:
- hit Enter to start configuration.
- hit y to prompt for MySQL root password.
- enter root password.
- retype root password.
- hit y key to remove anonymous user.
- hit y to disable remote root logins.
- hit y to remove test database from MySQL.
- hit y to load these new rules.
Issue the following command to make sure that you have installed MySQL correctly and the settings you have made in the previous steps, are done properly:
mysql -u root -p
it will prompt for root password that you have created it in previous steps. hit CTRL+C key combination to exit from test.
At this point, your database system and Apache web server are installed and we can move on next step. Next step is PHP installation and configuration.
Install PHP on FreBSD
to install PHP and all its required tools, issue the bellow command:
pkg install mod_php56 php56-mysql php56-mysqli
to confirm installation, hit y key.
Before using PHP, you must configure it to work with Apache. Edit apache configuration file using bellow command:
vi /usr/local/etc/apache24/httpd.conf
Locate the DirectoryIndex line and add index.php in front of the existing index.html, so Apache reads the PHP files:
DirectoryIndex index.html
The line should look like the following:
DirectoryIndex index.php index.html
In order to add PHP handlers to Apache, add the following lines at the bottom of the configuration file:
<FilesMatch "\.php$">
SetHandler application/x-httpd-php
<FilesMatch "\.phps$">
SetHandler application/x-httpd-php-source
You can now save and exit file. Press Esc key and type “:wq” to do so.
restart Apache, so all your configuration take effect:
service apache24 restart
We have installed FAMP on FreeBSD.
Test PHP functionality
To verify and test PHP functionality, you can follow below steps:
switch to /usr/local/www/apache24/data directory using below command:
cd /usr/local/www/apache24/data
create a file named info.php with the command below:
vi info.php
Insert the following PHP code in the empty file then save and exit:
Restart the Apache HTTP service one last time so all the changes take effect:
service apache24 restart
Now open a browser and enter your server IP following with /info.php. You must see something like bellow:
Congratulations! In this article, you have learnt how to install FAMP stack on FreeBSD.
If you are facing any problem with the installation, feel free to comment here. We will help you to solve the issue.