To install and configure a FAMP stack (FreeBSD, Apache, MySQL, PHP) on a FreeBSD-based system, you can follow these steps:
Install Apache:
sudo pkg update
sudo pkg install apache24
Start Apache:
sudo sysrc apache24_enable=YES
sudo service apache24 start
Install MySQL:
sudo pkg install mysql80-server
Start MySQL:
sudo sysrc mysql_enable=YES
sudo service mysql-server start
Secure MySQL Installation:
sudo mysql_secure_installation
Follow the prompts to set a root password and secure your MySQL installation.
Install PHP:
sudo pkg install php80 mod_php80
Configure Apache to Use PHP:
sudo ee /usr/local/etc/apache24/httpd.conf
Add the following lines to the file:
LoadModule php_module libexec/apache24/libphp8.so
AddHandler php-script .php
Restart Apache:
sudo service apache24 restart
Test the Setup:
Create a PHP file to test if Apache is serving PHP files correctly:
You can now access this file in your browser (e.g., http://your_server_ip/info.php) to see PHP information.
Configure Firewall (if necessary):
sudo sysrc firewall_enable=YES
sudo service ipfw start
sudo sysrc firewall_type=workstation
sudo service ipfw restart
sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --reload
Optional: Install phpMyAdmin (for easier MySQL management):
sudo pkg install php80-mysqli php80-json php80-mbstring php80-session
sudo pkg install php80-mysqlnd
sudo pkg install php80-phpmyadmin
During installation, choose the web server (apache24), and follow the prompts.
Secure phpMyAdmin:
Configure phpMyAdmin to only allow access from specific IP addresses or via HTTPS.
That's it! You now have a fully functioning FAMP stack installed and configured on your FreeBSD system.