FreeBSD Server For Hosting Laravel

One of the popular programming languages used in web development is PHP. PHP is a programming language that is widely used to create the most popular CMS platform in the world, namely WordPress. PHP is a back-end programming language or used for server-side development.

When developing a website, one of the important things that must be considered is choosing the right framework. Frameworks usually contain several code templates and simplify the application development process from having to build programming code from scratch to something simpler by using features in the framework.

That way, the resulting website will be optimal because its features are tailored to your needs. One of the recommended frameworks for creating applications or websites is the Laravel framework.

In this article I will explain the installation of a web application environment using Laravel installed on FreeBSD 13.2.

1. System Requirements

OS: FreeBSD13.2 Stable
IP LAN Server:
Apache version: apache24 (We will not discuss this in this article, we will assume it is already installed)
Versi MySQL:  mysql80-server (We will not discuss this in this article, we will assume it is already installed)
php version: php82
php mod_fpm

In this tutorial I will use FreeBSD's pkg tool to install packages, pkg is similar to the package management tools you find in Ubuntu (aptitude) and CentOS (yum) and allows us to install these packages and upgrade them much faster than compiling with FreeBSD ports.

2. PHP installation

Because in this tutorial we assume that our FreeBSD server has apache24 and mysql80-server installed, so we will immediately install PHP.

root@router2:~ # pkg install php82 mod_php82 php82-mysqli
If the above application has been installed, continue with the installation

root@router2:~ # pkg install php82-gd php82-phar php82-ctype php82-filter php82-iconv php82-curl php82-mysqli php82-pdo php82-tokenizer php82-mbstring php82-session php82-simplexml php82-xml php82-zlib php82-zip php82-dom php82-pdo_mysql php82-ctype
If the above application has been installed, continue with the installation

root@router2:~ # cd /usr/local/etc
root@router2:/usr/local/etc # cp php.ini-production php.ini
To ensure that OpenSSL is working (Composer needs this file when accessing files over the web using SSL), we will create the file cacert.pem.

root@router2:~ # cd /etc/ssl
root@router2:/etc/ssl # wget
Now edit the php.ini file in the /usr/local/etc folder and follow the following script:


then add this script to the top of the script in the php.ini file, place it right after the word [PHP] or at the bottom of the word [PHP].

listen.owner = www = www
listen.mode = 0660

3. PHP-FPM configuration

Now we need to "glue" apache24 and PHP together, PHP-FPM stands for PHP Fork Process Manager and is the SAPI module we will use for this installation. The next step is to edit the file /usr/local/etc/php-fpm.d/www.conf and activate the following script in that file.

listen = /var/run/php-fpm.sock
listen.owner = www = www
listen.mode = 0660
The next step is to create an rc.d startup script for the boot process so that php-fpm can be loaded automatically. Add the script php_fpm_enable="YES" to the rc.conf file.

root@router2:~ # ee /etc/rc.conf
The final step in php-fpm configuration is to restart the application.

root@router2:~ # service php-fpm restart
Performing sanity check on php-fpm configuration:
[18-Jun-2023 20:19:39] NOTICE: configuration file /usr/local/etc/php-fpm.conf test is successful

Stopping php_fpm.
Waiting for PIDS: 2399.
Performing sanity check on php-fpm configuration:
[18-Jun-2023 20:19:39] NOTICE: configuration file /usr/local/etc/php-fpm.conf test is successful

Starting php_fpm.
root@router2:~ #

4. PHP MOD configuration

You need to remember once again, that in this tutorial we assume that the apache24 and mysql80-server applications have been installed on our FreeBSD server, so the httpd.conf file is also available in the /usr/local/etc/apache24 folder. To activate the PHP module we have to edit the httpd.conf file and include the PHP module script in the httpd.conf file.
The following script is to activate the php module in apache24, place the following script at the very bottom of the file /usr/local/etc/apache24/httpd.conf

LoadModule php_module         libexec/apache24/

AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz

AddType application/x-httpd-php .php
AddType application/x-httpd-php .php .phtml .php3
AddType application/x-httpd-php-source .phps

5. Composer and Laravel installation

The next stage is to install Composer and Laravel. Composer is a package manager for PHP and is widely used by Laravel.

root@router2:~ # curl -sS -o composer-setup.php
root@router2:~ #
php composer-setup.php --install-dir=/usr/local/bin --filename=composer
All settings correct for using Composer

Composer (version 2.5.8) successfully installed to: /usr/local/bin/composer
Use it: php /usr/local/bin/composer
root@router2:~ #

Test Composer, whether it is RUNNING or not.

root@router2:~ # composer --version
Composer version 2.5.8 2023-06-09 17:13:21
root@router2:~ #
If the words Composer version appear, it means Composer is RUNNING.
If Composer is RUNNING, we continue by installing Laravel. You can download the Laravel file from the Gihub website. Follow the script below to install Laravel.

root@router2:~ # cd /usr/local/www
root@router2:/usr/local/www #
git clone
Cloning into 'laravel'...
remote: Enumerating objects: 34429, done.
remote: Counting objects: 100% (584/584), done.
remote: Compressing objects: 100% (293/293), done.
remote: Total 34429 (delta 325), reused 435 (delta 278), pack-reused 33845
Receiving objects: 100% (34429/34429), 10.43 MiB | 492.00 KiB/s, done.
Resolving deltas: 100% (20330/20330), done.
root@router2:/usr/local/www #
If it has been downloaded, continue with the following script to grant access rights and ownership of the Laravel file.

root@router2:~ # chown -R www:www /usr/local/www/laravel/
root@router2:~ #
chmod -R g+w /usr/local/www/laravel/
If we have done all the steps above, now is the time to install Laravel.

root@router2:~ # cd /usr/local/www/laravel
root@router2:/usr/local/www/laravel # composer install
If the composer installation above fails, you can try the script below.

root@router2:~ # cd /usr/local/www/laravel
root@router2:/usr/local/www/laravel # composer install --ignore-platform-req=ext-fileinfo

Below is an image of the results of the Laravel installation process.

If the results of your installation are like the image above, it means that all the configurations you have done are not wrong, and now your FreeBSD server has Composer and Laravel installed. This Laravel application is not only used by the Apache Web Server, if you want to combine it with NGINX Laravel can also run well.
Iwan Setiawan

I Like Adventure: Mahameru Mount, Rinjani Mount I Like Writer FreeBSD

Post a Comment

Previous Post Next Post