Nextcloud Installation on FreeBSD with Apache PHP Msyql Server

Nextcloud is one of the most popular open source alternative offline cloud storage solutions. Nextcloud features an attractive, visually easy to use and intuitive interface for remote access to your data. You can install Nextcloud on both FreeBSD and Linux servers to share files between colleagues. Or, if you want to install it on your VPS as an alternative to iCloud, Google Drive, or Dropbox, Nextcloud can do that too.

Nextcloud Hub provides a standalone solution for organizing collaboration between colleagues, friends and teams developing various projects. Maybe you are already familiar with Google Docs and Microsoft 365, in terms of features, Nextcloud is almost the same as them. With Nextcloud Hub you can deploy a fully controlled collaboration infrastructure, which operates on local servers and is not tied to external cloud services. Nextcloud source code is distributed under the AGPL license.

Nextcloud Hub combines several open add-on applications via the Nextcloud cloud platform, allowing you to work together with documents, files, and office information to plan tasks and events. The platform also includes add-ons for accessing email, messaging, organizing video conferences, and chat.

In this article we will install Nextcloud on a FreeSD system. For those who don't know, FreeBSD is an open source operating system designed specifically for servers and desktops.

1. System Requirements

OS: FreeBSD 13.2
PHP version: PHP 8.2.11
MySql Server: mysql80-server-8
Apache24: with php-fpm, mod php
Nextcloud: nextcloud-php82-27.1.0
IP Address:

2. PHP-FPM Configuration

PHP-FPM is the main library for running Nextcloud. PHP-FPM will connect the Apache Web server with the Nextcloud server. With PHP-FPM Nextcloud will run as a proxy, meaning Nextcloud performance will be faster.

In this article, we will not discuss PHP-FPM installation, you can read the previous article which explains the PHP-FPM installation and configuration process on FreeBSD.

To run PHP-FPM we will create a conf file in the same folder as Apache, namely "/usr/local/etc/apache24/Includes/php-fpm.conf". In the file "php-fpm.conf" write the script below.

<IfModule proxy_fcgi_module>
   <IfModule dir_module>
       DirectoryIndex index.php

   <FilesMatch "\.(php|phtml|inc)$">
SetHandler proxy:unix:/tmp/php-fpm.sock|fcgi://localhost/

So that PHP-FPM can run automatically on the FreeBSD server, create a script in the /etc/rc.conf file, and paste the script below.
root@ns6:~ # ee /etc/rc.conf
Restart PHP-FPM so it can run directly on FreeBSD.
root@ns6:~ # service php-fpm restart
Performing sanity check on php-fpm configuration:
[27-Nov-2023 20:04:52] NOTICE: configuration file /usr/local/etc/php-fpm.conf test is successful

Stopping php_fpm.
Waiting for PIDS: 2037.
Performing sanity check on php-fpm configuration:
[27-Nov-2023 20:04:53] NOTICE: configuration file /usr/local/etc/php-fpm.conf test is successful

Starting php_fpm.
root@ns6:~ #

3. Create a Nextcloud Database

Next to set up the database. Install database MySql Server and set it to start on boot. Nextcloud needs a database to store information and so on. We have to create a database inside MySQL for nextcloud, as well as a username and a password for Nextcloud to operate on that database.

You can read our previous article about Mysql Server installation guide.

Login to MySQL and create appropriate databases, username and password
root@ns6:/usr/ports/www/nextcloud # mysql -u root -p
Enter password: Enter password
and run the following SQL queries to create the nextcloud database and Nextclouduser username and password.
root@localhost [(none)]> CREATE DATABASE nextcloud;
Query OK, 1 row affected (0.14 sec)

root@localhost [(none)]> CREATE USER 'mary'@'localhost' IDENTIFIED BY 'mary123';
Query OK, 0 rows affected (0.04 sec)

root@localhost [(none)]> GRANT ALL PRIVILEGES ON nextcloud.* TO 'mary'@'localhost';
Query OK, 0 rows affected (0.04 sec)

root@localhost [(none)]> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.02 sec)

root@localhost [(none)]> exit;
The SQL queries command above will create:
Database name: nextcloud
IP address: localhost (
Username: mary
Password: mary123

4. Nextcloud installation

Install PHP and all modules required by Nextcloud. I'm using PHP82 Nextcloud recommends using version 7.0 or later. PHP dependencies are really needed by Nextcloud, almost all libraries in PHP. Nextcloud uses PHP as a connector with the MySQL Database and Apache Web Browser.

Before we install PHP dependencies, first install PHP82
root@ns6:~ # cd /usr/ports/lang/php82
root@ns6:/usr/ports/lang/php82 # make config-recursive
root@ns6:/usr/ports/lang/php82 # make install clean
Install dependencies.
root@ns6:~ # pkg install php82-xmlreader php82-ctype pkgconf php82-filter php82-iconv php82-xmlwriter php82-bz2 php82-mbstring php82-pdo_mysql php82-opcache
root@ns6:~ # pkg install php82-bcmath php82-dom php82-gmp php82-pcntl php82-pdo php82-posix php82-simplexml php82-xsl php82-intl php82-ldap php82-sysvsem
OK, continue by installing Nextcloud. Use the FreeBSD ports system, because we will activate the MySQL server database module.
root@ns6:/usr/ports/lang/php82 # cd /usr/ports/www/nextcloud
root@ns6:/usr/ports/www/nextcloud # make config

Check the "MySQL database support" option.

root@ns6:/usr/ports/www/nextcloud # make config-recursive
root@ns6:/usr/ports/www/nextcloud # make install clean

5. Edit the httpd.conf file

The next step is to configure the Apache server, the goal is so that Nextcloud can connect to Web browsers such as Google Chrome, Yandex and others. The main Apache configuration file is httpd.conf, open the file using the default FreeBSD editor "ee" and enter the following script into the file "/usr/local/etc/apache24/httpd.conf".

Alias /nextcloud /usr/local/www/nextcloud
        AcceptPathInfo On
        <Directory /usr/local/www/nextcloud>
	#Options None
	#Options +FollowSymlinks
	Options Indexes ExecCGI FollowSymLinks
            AllowOverride All
            Require all granted

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

Enable several modules required by Nexcloud in the /usr/local/etc/apache24/httpd.conf file.

LoadModule mpm_prefork_module libexec/apache24/
LoadModule cache_module libexec/apache24/
LoadModule proxy_module libexec/apache24/
LoadModule proxy_connect_module libexec/apache24/
LoadModule proxy_ftp_module libexec/apache24/
LoadModule proxy_http_module libexec/apache24/
LoadModule proxy_fcgi_module libexec/apache24/
LoadModule proxy_scgi_module libexec/apache24/
LoadModule session_module libexec/apache24/
LoadModule rewrite_module libexec/apache24/
LoadModule php_module         libexec/apache24/

After the Nextcloud installation process is complete, a new folder will be created at /usr/local/www/nextcloud. Type the command below to grant file ownership rights.
root@ns6:/usr/ports/www/nextcloud # chown -R www:www /usr/local/www/nextcloud/

6. Test Nextcloud

Before you test Nextcloud, restart the entire application
root@ns6:/usr/ports/www/nextcloud # service mysql-server restart
root@ns6:/usr/ports/www/nextcloud # service php-fpm restart
root@ns6:/usr/ports/www/nextcloud # service apache24 restart
Buka Web Browser Google Chrome, pada menu address bar ketikkan "".

To display the "LogIn" menu, type the command "".

The only difficult problem with installing Nextcloud is connecting and creating the MySQL database, apart from that, inappropriate dependencies also affect the Nextcloud server not connecting with MySQL and Apache. Not only that, the existence of PHP-FPM also makes Nextcloud installation difficulties worse.
Iwan Setiawan

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

Post a Comment

Previous Post Next Post