Nextcloud is a powerful and versatile open-source software that allows you to create your own file hosting service similar to Dropbox or Google Drive. With its extensive range of plugins and collaborative features, Nextcloud has become a popular choice for businesses and individuals looking for a secure and customizable cloud storage solution. In this comprehensive guide, we will walk you through the step-by-step process of installing Nextcloud on Rocky Linux 8.4, using the LAMP stack (Linux, Apache2/Httpd, MySQL/MariaDB, and PHP).
Prerequisites
Before we begin the installation process, make sure you have the following prerequisites:
- A Rocky Linux server with all packages updated to the latest versions.
- A user account with root privileges, which can obtain root access through the sudo command.
Installing Apache/Httpd Web Server
To start, we need to install the Apache or Httpd web server on your Rocky Linux server. Follow these steps:
- Open your terminal and execute the following command to install the Httpd web server:
sudo dnf install httpd
- Type “y” and press “Enter” to confirm and install the Httpd packages.
- Once the installation is complete, enable and start the Httpd service using the following commands:
sudo systemctl enable httpd sudo systemctl start httpd
- To verify the status of the Httpd service, run the following command:
sudo systemctl status httpd
If the Httpd service is active and running, you should see a similar output.
Congratulations! You have successfully installed and configured the Apache/Httpd web server on your Rocky Linux server.
Installing PHP on Rocky Linux
Nextcloud requires PHP 7.4 or higher for installation. In this section, we will install PHP 7.4 from the Remi repository. Follow these steps:
- Run the following command to add the EPEL and Remi repositories to your system:
sudo dnf install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm sudo dnf install https://rpms.remirepo.net/enterprise/remi-release-8.rpm
- Type “y” and press “Enter” to add the EPEL and Remi repositories.
- Once the installation is complete, verify the repositories by running the following command:
sudo dnf repolist
You should see the EPEL and Remi repositories listed.
- Reset the default PHP module repository and enable the PHP 7.4 module from the Remi repository. Execute the following commands:
sudo dnf module reset php sudo dnf module enable php:remi-7.4
- Install PHP and its necessary extensions by executing the following command:
sudo dnf install php php-ctype php-curl php-gd php-iconv php-json php-libxml php-mbstring php-openssl php-posix php-session php-xml php-zip php-zlib php-pdo php-mysqlnd php-intl php-bcmath php-gmp php-imagick php-apcu
- After the installation is complete, open the PHP configuration file “php.ini” using the nano editor:
sudo nano /etc/php.ini
- Make the following changes to the configuration:
- Set the value of “memory_limit” to at least 512M.
- Set the value of “uploadmaxfilesize” to the maximum size you want to allow for file uploads.
- Set the value of “postmaxsize” to a higher value than “uploadmaxfilesize”.
- Set the “date.timezone” option to match your local timezone.
- Optionally, increase the value of “maxexecutiontime” based on your server load.
Save the changes and exit the editor.
- Change the working directory to “/etc/php.d/” and edit the configuration file “10-opcache.ini” using the following commands:
cd /etc/php.d/ sudo nano10-opcache.ini
- Add the following configuration inside the file:
opcache.enable = 1 opcache.interned_strings_buffer = 8 opcache.max_accelerated_files = 10000 opcache.memory_consumption = 128 opcache.save_comments = 1 opcache.revalidate_freq = 1
Save the changes and exit the editor.
- Restart the Httpd service to apply the new PHP configuration:
sudo systemctl restart httpd
Congratulations! You have successfully installed and configured PHP on your Rocky Linux server.
Installing and Configuring MariaDB
In this section, we will install the MariaDB database server, secure the deployment, and create a new database and user for Nextcloud. Follow these steps:
- Install the MariaDB database server by executing the following command:
sudo dnf install mariadb mariadb-server
- Once the installation is complete, enable and start the MariaDB service using the following commands:
sudo systemctl enable mariadb sudo systemctl start mariadb
- To verify the status of the MariaDB service, run the following command:
sudo systemctl status mariadb
If the MariaDB service is active and running, you should see a similar output.
- Secure your MariaDB deployment by setting up the root password and removing some default configurations. Use the following command to run the MySQL Secure Installation script:
sudo mysql_secure_installation
- Follow the prompts to set up the root password, remove the default anonymous user, disable remote login for the root user, and remove the test database. After completing these steps, your MariaDB installation will be secure.
- Log in to the MariaDB shell using the following command:
sudo mysql -u root -p
- Create a new database for Nextcloud by executing the following query:
CREATE DATABASE nextcloud_db;
- Create a new database user for Nextcloud by executing the following query. Replace ‘StrongPassword’ with a strong password of your choice:
CREATE USER nextuser@localhost IDENTIFIED BY 'StrongPassword';
- Grant all privileges to the ‘nextuser’ for the ‘nextcloud_db’ database by executing the following query:
GRANT ALL PRIVILEGES ON nextcloud_db.* TO nextuser@localhost;
- Flush the privileges to apply the new database configuration:
FLUSH PRIVILEGES;
- Exit the MariaDB shell by typing “quit” and pressing “Enter”.
Congratulations! You have successfully installed and configured MariaDB on your Rocky Linux server.
Downloading Nextcloud Source Code
In this section, we will download the latest version of the Nextcloud source code and configure the necessary permissions. Follow these steps:
- Change the working directory to “/var/www” by executing the following command:
cd /var/www
- Download the latest version of Nextcloud source code using the wget command:
sudo wget https://download.nextcloud.com/server/releases/nextcloud-22.1.0.zip
- Extract the downloaded zip file and change the ownership of the “nextcloud” directory to the Apache user:
sudo unzip nextcloud-22.1.0.zip sudo chown -R apache:apache nextcloud
Congratulations! You have successfully downloaded and prepared the Nextcloud source code for installation.
Enabling Apache/Httpd mod_ssl Module
To secure your Nextcloud installation with SSL using Let’s Encrypt, we need to enable the mod_ssl module for the Apache/Httpd server. Follow these steps:
- Install the mod_ssl package by executing the following command:
sudo dnf install mod_ssl
- Generate a default SSL certificate for localhost using the openssl command. If you already have your own certificates, you can skip this step:
sudo openssl req -newkey rsa:2048 -nodes -keyout /etc/pki/tls/private/localhost.key -x509 -days 365 -out /etc/pki/tls/certs/localhost.crt
- Verify if the mod_ssl module is enabled on the Httpd server by running the following command:
sudo apachectl -M | grep ssl
If you see “ssl” in the output, the mod_ssl module is enabled.
Congratulations! You have successfully enabled the mod_ssl module on your Apache/Httpd server.
Generating SSL Letsencrypt with Certbot
In this section, we will install the Certbot tool and generate SSL certificates for your Nextcloud installation using Let’s Encrypt. We will use the webroot plugin for certificate generation. Follow these steps:
- Install the Certbot tool by executing the following command:
sudo dnf install certbot
- Create a directory for Let’s Encrypt authorization by running the following commands:
sudo mkdir -p /var/lib/letsencrypt/.well-known sudo chgrp apache /var/lib/letsencrypt sudo chmod g+s /var/lib/letsencrypt
- Change the working directory to “/etc/httpd/conf.d” and create a new configuration file “well-known.conf” using the nano editor:
cd /etc/httpd/conf.d sudo nano well-known.conf
- Add the following configurations to the “well-known.conf” file:
Alias /.well-known/acme-challenge/ "/var/lib/letsencrypt/.well-known/acme-challenge/" <Directory "/var/lib/letsencrypt/"> AllowOverride None Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec Require method GET POST OPTIONS </Directory>
Save the changes and exit the editor.
- Verify the Httpd configuration and restart the Httpd service by executing the following commands:
sudo apachectl configtest sudo systemctl restart httpd
- Before generating SSL certificates, make sure your domain name is resolved to the server’s IP address. Then, generate the Let’s Encrypt SSL certificates using the Certbot command. Replace the email address and domain name with your own:
sudo certbot certonly --agree-tos --email test@example.com --webroot -w /var/lib/letsencrypt/ -d files.domain.com -d example.io
Once the process is complete, your SSL certificates will be available in the “/etc/letsencrypt/live/files.domain.com/” directory.
Congratulations! You have successfully generated SSL certificates for your Nextcloud installation using Let’s Encrypt.
Setting Up Apache Virtual Host for Nextcloud
In this section, we will configure a new virtual host for Nextcloud on the Apache/Httpd server. Follow these steps:
- Change the working directory to “/etc/httpd/conf.d” and create a new configuration file “nextcloud.conf” using the nano editor:
cd /etc/httpd/conf.d sudo nano nextcloud.conf
- Replace the domain name and SSL path directory in the following configuration with your own details, and paste it into the “nextcloud.conf” file:
<VirtualHost *:80> ServerName files.domain.com ServerAlias www.files.domain.com Redirect permanent / https://files.domain.com/ </VirtualHost> <VirtualHost *:443> ServerName files.domain.com ServerAlias www.files.domain.com DocumentRoot /var/www/nextcloud/ Protocols h2 http/1.1 <If "%{HTTP_HOST} == 'www.files.domain.com'"> Redirect permanent / https://files.domain.com/ </If> ErrorLog /var/log/httpd/files.domain.com-error.log CustomLog /var/log/httpd/files.domain.com-access.log combined SSLEngine On SSLCertificateFile /etc/letsencrypt/live/files.domain.com/fullchain.pem SSLCertificateKeyFile /etc/letsencrypt/live/files.domain.com/privkey.pem <IfModule mod_headers.c> Header always set Strict-Transport-Security "max-age=15552000; includeSubDomains" </IfModule> <Directory /var/www/nextcloud/> Options +FollowSymlinks AllowOverride All <IfModule mod_dav.c> Dav off </IfModule> SetEnv HOME /var/www/nextcloud SetEnv HTTP_HOME /var/www/nextcloud </Directory> </VirtualHost>
Save the changes and exit the editor.
- Verify the Httpd configuration by executing the following command:
sudo apachectl configtest
If there are no errors, restart the Httpd service:
sudo systemctl restart httpd
Congratulations! You have successfully set up the Apache virtual host for your Nextcloud installation.
Installing Nextcloud
Now that all the server configurations are complete, you can proceed with the installation of Nextcloud through a web browser. Follow these steps:
- Open your web browser and enter the URL of your Nextcloud installation:
https://files.domain.com
- You will be redirected to a secure HTTPS connection, and the Nextcloud setup page will appear.
- Create an admin account by entering a username and password.
- Leave the “Data Folder” section as default for now.
- Select “MySQL/MariaDB” as the database option and enter the database details you configured earlier.
- Optionally, install recommended apps by checking the box, or uncheck the box if you prefer not to.
- Click the “Finish setup” button to complete the installation process.
Congratulations! You have successfully installed Nextcloud on your Rocky Linux server. You will be redirected to the Nextcloud dashboard.
Nextcloud Performance Tuning
To optimize the performance of your Nextcloud installation, you can follow these additional steps:
- Enable local memory caching by editing the Nextcloud configuration file “config.php”. Change the working directory to “/var/www/nextcloud/config” and edit the file:
cd /var/www/nextcloud/config sudo nano config.php
- Add the following configuration inside the ‘array(…)’ bracket:
'memcache.local' => '\OC\Memcache\APCu',
Save the changes and exit the editor.
- Nextcloud requires background tasks to run on a regular basis. To schedule these tasks, we need to set up a cronjob. Open the cronjob configuration for the “apache” user:
sudo crontab -u apache -e
- Add the following cronjob configuration to execute the Nextcloud cron.php script every 5 minutes:
*/5 * * * * php -f /var/www/nextcloud/cron.php
Save the changes and exit the editor.
Congratulations! You have successfully tuned the performance of your Nextcloud installation.
Conclusion
In this comprehensive guide, we have walked you through the step-by-step process of installing Nextcloud on Rocky Linux 8.4. You have learned how to set up the LAMP stack, configure the Apache/Httpd web server, install and configure PHP and MariaDB, and generate SSL certificates using Let’s Encrypt. Additionally, we covered the process of setting up an Apache virtual host, installing Nextcloud, and optimizing its performance.
Nextcloud offers a secure and customizable cloud storage solution that empowers businesses and individuals with efficient collaboration and file-sharing capabilities. With the power of the LAMP stack and the flexibility of Nextcloud’s extensive plugin ecosystem, you can tailor your cloud storage environment to meet your specific needs.
If you’re looking for a reliable and secure hosting provider for your Nextcloud installation, consider Shape.host’s Linux SSD VPS. Their scalable and high-performance virtual private servers are designed to provide optimal performance and security for your Nextcloud instance.