Nextcloud

-------

Nextcloud with Apache on CentOS 7

sudo setenforce 0 sudo sed -i 's/^SELINUX=.*/SELINUX=permissive/g' /etc/selinux/config

Step 1: Install PHP and httpd

We require PHP and Apache to run Nextcloud on CentOS 7. For PHP, we will use PHP 7.3 since it is the latest stable release of PHP available for CentOS 7. This is available on Remi repository which needs to be added prior to installation.

sudo yum -y install epel-release yum-utils sudo yum -y install http://rpms.remirepo.net/enterprise/remi-release-7.rpm

Disable default PHP 5.x enabled repository and enable one for PHP 7.3:

sudo yum-config-manager --disable remi-php54 sudo yum-config-manager --enable remi-php73

Then install Apache and PHP packages:

sudo yum -y install vim httpd php php-cli php-mysqlnd php-zip php-devel php-gd php-mcrypt php-mbstring php-curl php-xml php-pear php-bcmath php-json php-pdo php-pecl-apcu php-pecl-apcu-devel

Confirm your PHP version

$ php -v

PHP 7.3.1 (cli) (built: Jan  8 2019 13:55:51) ( NTS )

Copyright (c) 1997-2018 The PHP Group

Zend Engine v3.3.1, Copyright (c) 1998-2018 Zend Technologies

Step 2: Install and Configure MariaDB / MySQL

Install MariaDB / MySQL database server on CentOS 7 using our previous guides. Choose one, recommended is MariaDB.

Install MariaDB 10.x on Ubuntu 18.04 and CentOS 7

After the installation, login as a root user to MySQL console and create a new database for Nextcloud.

$ mysql -u root -p

CREATE USER 'nextcloud'@'localhost' IDENTIFIED BY "StrongPassword";

CREATE DATABASE nextcloud;

GRANT ALL PRIVILEGES ON nextcloud.* TO 'nextcloud'@'localhost';

FLUSH PRIVILEGES;

QUIT

Step 3: Download and Install Nextcloud on CentOS 7

Download the latest release of Nextcloud:

sudo yum -y install wget unzip wget https://download.nextcloud.com/server/releases/latest-18.zip

Unzip the downloaded file:

unzip latest-18.zip rm -f latest-18.zip

Move the resulting nextcloud folder to /var/www/html directory.

sudo mv nextcloud/ /var/www/html/

Create data directory to store Nextcloud uploaded files. This can be any path e.g NFS mount point, SAN mount point e.t.c.

sudo mkdir /var/www/html/nextcloud/data

sudo chown apache:apache -R /var/www/html/nextcloud/data

Give apache user and group the ownership of nextcloud folder.

sudo chown apache:apache -R /var/www/html/nextcloud

Step 4: Configure Apache VirtualHost – Without SSL

Now create an Apache configuration file for Nextcloud.

sudo vim /etc/httpd/conf.d/nextcloud.conf

Paste below content to the file.

<VirtualHost *:80>   ServerName files.example.com   ServerAdmin admin@example.com   DocumentRoot /var/www/html/nextcloud   <directory /var/www/html/nextcloud>     Require all granted     AllowOverride All     Options FollowSymLinks MultiViews     SetEnv HOME /var/www/html/nextcloud     SetEnv HTTP_HOME /var/www/html/nextcloud   </directory> </VirtualHost>

Set correct ServerName and change other settings to suit your use. When done, save the file and start httpd service.

sudo systemctl enable --now httpd sudo semanage fcontext -a -t httpd_sys_content_t "/var/www/html(/.*)?" sudo sudo restorecon -Rv /var/www/html

http://domain_name_or_ip_address/nextcloud

Configure Firewall:

If you have an active firewalld service, allow http and https ports.

sudo firewall-cmd --add-service={http,https} --permanent

sudo firewall-cmd --reload

Step 5: Configure Apache With Let’s Encrypt SSL

To use Let’s Encrypt SSL certificate, first install certbot

wget https://dl.eff.org/certbot-auto chmod a+x certbot-auto sudo mv certbot-auto /usr/local/bin

Then request for SSL certificate.

export DOMAIN="files.example.com"

export EMAIL="admin@example.com"

certbot-auto certonly --standalone -d $DOMAIN --preferred-challenges http --agree-tos -n -m $EMAIL --keep-until-expiring

Modify your VirtualHost configuration file to look like below.

<VirtualHost *:80>    ServerName files.example.com    ServerAdmin admin@example.com    RewriteEngine On    RewriteCond %{HTTPS} off    RewriteRule ^(.*)$ https://%{HTTP_HOST}$1 [R=301,L] </VirtualHost>  <IfModule mod_ssl.c>    <VirtualHost *:443>      ServerName files.example.com      ServerAdmin admin@example.com      DocumentRoot /var/www/html/nextcloud      <directory /var/www/html/nextcloud>         Require all granted         AllowOverride All         Options FollowSymLinks MultiViews         SetEnv HOME /var/www/html/nextcloud         SetEnv HTTP_HOME /var/www/html/nextcloud     </directory>      SSLEngine on      SSLCertificateFile /etc/letsencrypt/live/files.example.com/fullchain.pem      SSLCertificateKeyFile /etc/letsencrypt/live/files.example.com/privkey.pem    </VirtualHost> </IfModule>

Step 6: Access Nextcloud UI and finish installation

Open your nextcloud server URL as configured on Apache: http://files.example.com

Create admin account on first page.

Provide admin username and password. Also configure MySQL / MariaDB database.

When done click the “Finish Setup” button

---------------------------X--------------------------------

mysql -u root -p  MariaDB [(none)]> CREATE DATABASE nextcloud; MariaDB [(none)]> GRANT ALL PRIVILEGES ON nextcloud.* TO 'nextclouduser'@'localhost' IDENTIFIED BY 'CREATE-PASSWORD-HERE' WITH GRANT OPTION; MariaDB [(none)]> FLUSH PRIVILEGES; MariaDB [(none)]> quit

 yum-config-manager --disable remi-php54

 yum install epel-release yum-utils

 yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm

 yum-config-manager --enable remi-php72

OR

# yum install epel-release

# rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm

# yum install httpd php72w php72w-dom php72w-mbstring php72w-gd php72w-pdo php72w-json php72w-xml php72w-zip php72w-curl php72w-pear php72w-intl setroubleshoot-server bzip2 php72w-pecl-imagick

#  yum install httpd php php-gd php-json php-mysql php-curl php-mbstring php-intl php-mcrypt php-imagick php-xml php-zip

****Downloading Nextcloud****

wget -P /tmp https://download.nextcloud.com/server/releases/nextcloud-15.0.0.zip

unzip /tmp/nextcloud-15.0.0.zip  -d /var/www/html

chown -R apache: /var/www/nextcloud

# vi /etc/httpd/conf.d/nextcloud.conf

Alias /nextcloud "/var/www/html/nextcloud/"

<Directory /var/www/html/nextcloud/>

  Options +FollowSymlinks

  AllowOverride All

 <IfModule mod_dav.c>

  Dav off

 </IfModule>

 SetEnv HOME /var/www/html/nextcloud

 SetEnv HTTP_HOME /var/www/html/nextcloud

</Directory>

systemctl restart httpd

http://domain_name_or_ip_address/nextcloud

the upload file size limit for nextcloud.

By default  maximum of 2MB file can be uploaded on nextcloud, if you wish to upload files larger than 2 MB then we need to change some parameter value in /etc/php.ini

#   vi /etc/php.ini

; Maximum amount of memory a script may consume (128MB) ; http://php.net/memory-limit memory_limit = 512M  ...     [Date] ; Defines the default timezone used by the date functions ; http://php.net/date.timezone date.timezone =Asia/Dhaka  ... cgi.fix_pathinfo=0  ... post_max_size = 512M  ... upload_max_filesize = 512M

Restart the Web server’s Service

[root@nextcloud ~]# systemctl restart httpd

           -----------------

Enable Caching (suggested)

NextCloud is good but it can be very slow if you don’t configure a caching solution. There are two caching solutions covered in this guide:

Enabling OPcache

CentOS

Open a terminal and input the following commands:

Now you need to edit a file located at /etc/php.d/10-opcache.ini . With your favorite editor, edit the file and make it look like this:

These values are suggested by NextCloud, but you’re free to tweak them to suit your needs. Once you’re done you can restart apache:

Installing and configuring Redis

CentOS

Open a terminal and input the following commands:

Now you must configure NextCloud to use Redis. To do so you need to edit the NextCloud configuration file located at /var/www/html/nextcloud/config/config.php . The file will look like this, add the highlighted lines:

These settings will enable NextCloud to use Redis for caching and file locks. Of course these settings are just an example, you can tweak them to suit your needs.

Now you need to modify (for some reason) the Redis port SELinux label in order to enable Apache to access Redis:

Lastly, enable and start Redis and restart the webserver:

------