Step 1: Installing Apache in FreeBSD
In this tutorial, we will be using Apache 2.4. If you’re reading from a later date, please adjust to the latest release of Apache in FreeBSD so that you can get security updates.
Without further ado, enter the following command to install Apache:
sudo pkg install apache24
Now that you’ve installed apache in FreeBSD, you will still need to enable it with rc and start apache with the following commands:
sudo sysrc apache24_enable="YES" sudo service apache24 start
Step 2: Installing MySQL
The same rules apply here for apache as did MySQL. If you’re reading this article from a later date, and the current version of MySQL is later than MySQL 8.0, then install the current package.
sudo pkg install mysql80-server
Now, you have to start mysql and enable it to start on reboot:
sudo sysrc mysql_enable="YES" sudo service mysql-server start
Now that you’re done with that, you’re going to want to lock up the mysql server and install everything:
Go through the wizard. The questions are pretty straightforward, so I’ll let you choose what’s right for your server.
If you don’t know how to write SQL statements, consider learning from here: https://www.tutorialspoint.com/mysql/index.htm.
Step 3: Installing PHP to Apache in FreeBSD
Now you need to install PHP. As per usual, if you’re reading the article from a later date, you’ll want to install the latest version of PHP. The current version is PHP 7.4, so we’ll be using that. I will also walk you through installing the needed modules. Enter the following command to install PHP and its modules:
sudo pkg install php74 php74-gettext php74-json php74-mbstring php74-mysqli php74-session php74-zip mod_php74
Now you’ll want to secure and install your php installation.
sudo cp /usr/local/etc/php.ini-production /usr/local/etc/php.ini
Now you need to allow apache to know that .php files are a thing and they need to be handled by the PHP module. Open up “/usr/local/etc/apache24/Includes/php.conf” in vim or nano and enter in the following code:
<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>
Now you’re going to want to restart apache in FreeBSD:
sudo apachectl restart
Now let’s test your PHP installation. Open up “/usr/local/www/apache24/data/info.php” in your preferred editor. Enter in the following code:
<?php phpinfo(); ?>
Now go into your web browser. We’ll use localhost, but you just need to replace the name of the host with whatever the IP address of your server is. Enter in the following URL:
You should see a table listing all sorts of variables and installations having to do with PHP. If you see that, you’re successful in your installation.
Well, I will be doing more tutorials on FreeBSD later, so stay tuned! I will post more in this conclusion section as it comes out. That was how to install Apache in FreeBSD.