In this guide, we are going to set up NextCloud on a Centos 8 server hosted with Nginx and php (LEMP stack). We will be using Mysql 8 and PHP 7.4 for this guide.This will also work for RHEL derivatives like Alma Linux 8, Rocky Linux 8 and RHEL 8.
Nextcloud is an Open Source suite of client-server software for creating and using file hosting services. It is a Ā a free self-hosted cloud storage solution similar to Dropbox, Google Drive, etc. With Nextcloud, you donāt have to worry about the pricey alternatives and since you will host your own files, you donāt have to worry about privacy or someone collecting your data.
NextCloud can be installed on a private home server or a virtual private server in the cloud. Files can then be uploaded and then synced to a local desktop, laptop or even a smartphone. This way you have full control of your data.
Features of NextCloud
- NextCloud has sync clients for Linux, Mac OS, Windows, Android and IOS
- End to end encryption ā files are encrypted while being uploaded to the server
- NextCloud is free and Open Source
- Can be integrated with an online office suite (Collobora, OnlyOffice) so you can create and edit your doc, ppt, xls files directly from NextCloud.
- The app store contains hundreds of apps to extend functionality (like calendar app, notes-taking app, video conferencing app, etc).
Related Content
Prerequisites
To follow along this guide, ennsure that you have:
- An up to date Rocky Linux/RHEL 8 based Server
- Internet access
- Root acces to the server or sudo access
Table of Content
- Ensure that the server packages are up to date
- Disable SELinux
- Installing mysql
- Creating mysql user for NextCloud
- Installing PHP
- Install Nginx
- Download and configure Nextcloud
- Configure Nginx to serve NextCloud from a virtual host
- Update PHP Configuration
- Accessing Nextcloud from the web url
Ensure that the server packages are up to date
Let us make sure that our server packages are up to date with this command:
sudo dnf -y update
Disable SELinux
Next, let us disable SELinux. We are going to set SELinux to permisive. Edit this file:
vim /etc/selinux/config
Then update this line:
SELINUX=permisive
Installing mysql
Mysql is a popular relational managementn system. It is available in the default repositories asĀ mysql-server
.
Install it with this command:
sudo dnf install mysql-server
You will need to start and enable to ensure its always started when the server starts.
sudo systemctl start mysql
sudo systemctl status mysqld
Once the mysql service is running, you need to secure it. Mysql provides a commandline utility that will do that:
sudo mysql_secure_installation
The above command will take you throuh prompts to secure and set a root password for the mysql instance.
Check more info on Installing and setting up mysql in this guideĀ here
Creating mysql user for NextCloud
It is always recommended to have a dedicated user for each app that connects to the DB. Check out this guide on managing mysql permissionsĀ here. We will set up a database, user and password to be used by nextcloud:
Connect to mysql server:
mysql -u root -p
After Supplying your password, enter the following to the mysql prompt:
create database nextcloud;
create user '<meta charset="utf-8">nextcloud_user'@'%' identified by 'S0mStrongPa$$word';
grant all privileges on <meta charset="utf-8">nextcloud.* to '<meta charset="utf-8">nextcloud_user'@'%';
Now that we have configured our mysql connection, lets go to the next section where we install and configure PHP and Nginx.
Installing PHP
NextCloud works fine with PHP 6.4. To install php 7.4, we need to enable remi repository so we get the latest version.
Enable Remi repo with this command:
sudo dnf install dnf-utils http://rpms.remirepo.net/enterprise/remi-release-8.rpm
Enable php 7.4 using dnf module:
sudo dnf module enable php:remi-7.4
Then install php and dependancies
sudo dnf install -y php php-gd php-curl php-zip php-dom php-xml php-simplexml php-mbstring php-intl php-json
For more info on setting up Apache and PHP, check this guideĀ here. Check out about the remi releaseĀ here.
Installing Nginx
Next, let us install Nginx in our system. Use this command to install nginx
sudo dnf install -y nginx
Start and check the status of Nginx
$ sudo systemctl start nginx
$ sudo systemctl status nginx
● nginx.service - The nginx HTTP and reverse proxy server
Loaded: loaded (/usr/lib/systemd/system/nginx.service; disabled; vendor preset: disabled)
Drop-In: /usr/lib/systemd/system/nginx.service.d
└─php-fpm.conf
Active: active (running) since Fri 2021-10-15 17:33:39 UTC; 7s ago
Process: 1138614 ExecStart=/usr/sbin/nginx (code=exited, status=0/SUCCESS)
Process: 1138607 ExecStartPre=/usr/sbin/nginx -t (code=exited, status=0/SUCCESS)
Process: 1138605 ExecStartPre=/usr/bin/rm -f /run/nginx.pid (code=exited, status=0/SUCCESS)
Main PID: 1138615 (nginx)
Tasks: 3 (limit: 23800)
Memory: 5.3M
CGroup: /system.slice/nginx.service
├─1138615 nginx: master process /usr/sbin/nginx
├─1138616 nginx: worker process
└─1138617 nginx: worker process
Oct 15 17:33:38 test-app-server systemd[1]: Starting The nginx HTTP and reverse proxy server...
Oct 15 17:33:39 test-app-server nginx[1138607]: nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
Active: active (running)
indicate that the service is now up and running.
Download and configure Nextcloud
Now that we have successfully configured the LEMP server in our system, let us download and set up NextCloud. You can get the latest version of NextCloud from the NextCloud installation page. Use this command to download the server NextCloud:
cd /tmp
curl -LO https://download.nextcloud.com/server/releases/nextcloud-22.2.0.zip
Now let us change into a directory path to serve NextCloud in /var/www
then extract the downloaded file there:
cd /var/www
sudo unzip /tmp/nextcloud-22.2.0.zip
sudo chown -R nginx:<meta charset="utf-8">nginx nextcloud
sudo chmod -R 755 nextcloud
Nextcloud required a directory to keep its data. So create a data directory and set the proper permissions on nextcloud directory
sudo mkdir -p /var/nextcloud/data sudo chown -R nginx:nginx /var/nextcloud sudo chmod -R 755 /var/nextcloud
Configure Nginx to serve NextCloud from a virtual host
We managed to download the NextCloud content to /var/www/nextcloud
. The next bit it to set up Nginx to serve it.
Letās create virtual site in the directory that nginx serves content hereĀ /etc/nginx/conf.d
:
sudo vim /etc/nginx/conf.d/nextcloud.conf
Add the following content:
server {
listen 80;
server_name nextcloud.citizix.com;
root /var/www/nextcloud;
index index.php;
location / {
try_files $uri $uri/ /index.php?$args;
}
location = /favicon.ico {
log_not_found off;
access_log off;
}
location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
expires max;
log_not_found off;
}
location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}
location ~ \.php$ {
include /etc/nginx/fastcgi_params;
fastcgi_pass unix:/run/php-fpm/www.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
Updating PHP Configuration
Next let us take care of some php config. We are using php-fpm to serve our php content. It is configured to work with apache by default so letās update the user and group in the file
/etc/php-fpm.d/www.conf
to nginx.
Edit the file
vim /etc/php-fpm.d/www.conf
Then update these
user = nginx
group = nginx
Let us also change the session directoory for us to login. Update PHP session directory to be owned by nginx:
sudo chown nginx.nginx -R /var/lib/php/session/
Once the abve changes have been made, we need to restart the nginx server and the php-fom server. Use these commands in the terminal to achieve that.
sudo systemctl restart php-fpm nginx
Accessing Nextcloud from the web url
Then head to your set domain, http://nextcloud.citizix.com/nextcloud
for me. You will be asked to create the user account. Ente the username and password to be using for the new user:
Then enter the Database Details:
After that Click Finish. You will be redirected to the login page where you will use the details for the created user to login. On Successful login you will get the Dashboard.
Conclusion
In this guide, we managed to set up LEMP on Rocky Linux 8 or RHEL based Server to serve Next cloud.