How to Install Apache, PHP, and MySQL on a FreeBSD 12 Cloud Server?

18-01-2024 02:29:23

In this article, we will learn how to install a LAMP (Linux, Apache, MySQL, PHP) environment on a FreeBSD 12 cloud server. The installation process is divided into the following steps.

Updating the Operating System

Before beginning the installation, we update the operating system to the latest version and reboot the cloud server.

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

Installing Apache

Install Apache using the following command:

sudo pkg install -y apache24
sudo sysrc apache24_enable=yes
sudo service apache24 start

To check the version of Apache, use:

httpd -v

The output will display as follows:

Server version: Apache/2.4.41 (FreeBSD)
Server built:   unknown

If accessing the cloud server's IP address http://IPAddress in a browser shows Apache's default page, it indicates that Apache has been successfully installed.

Installing PHP

Install PHP using the following command:

sudo pkg install -y php73 php73-mysqli mod_php73

Enable PHP-FPM:

sudo sysrc php_fpm_enable=yes
sudo service php-fpm start

To check the PHP version, use:

php -v

The output will display as follows:

PHP 7.3.15 (cli) (built: Mar  3 2020 01:30:41) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.15, Copyright (c) 1998-2018 Zend Technologies

To view the installed PHP modules, use:

php -m

The output will display as follows:

[PHP Modules]
Core
date
libxml
mysqli
mysqlnd
pcre
Reflection
SPL
standard

[Zend Modules]

Installing MySQL

Install MySQL using the following command:

sudo pkg install -y mysql80-client mysql80-server
sudo sysrc mysql_enable=yes
sudo service mysql-server start

To check the MySQL version, use:

mysql -V

The output will display as follows:

mysql  Ver 8.0.19 for FreeBSD12.1 on amd64 (Source distribution)

Then, run the MySQL installation configuration wizard:

mysql_secure_installation

During the MySQL installation configuration wizard, we need to enter the root password and answer some security-related questions. Generally, it's sufficient to select the default values provided by the wizard.

Finally, restart Apache to work with PHP:

sudo apachectl restart

This concludes the tutorial on installing Apache, PHP, and MySQL on a FreeBSD 12 cloud server.