Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to install Nextcloud in Linux

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article will explain in detail how to install Nextcloud in Linux. The editor thinks it is very practical, so I share it with you for reference. I hope you can get something after reading this article.

Nextcloud is an open source and free private cloud storage network disk project, which allows you to quickly and easily build a cloud synchronization network disk of your own or your team, thus achieving cross-platform and cross-device file synchronization, sharing, version control, team collaboration and other functions.

Prerequisites Root permissions for a 64-bit CentOS 7 server step 1-install Nginx and PHP7-FPM in CentOS 7

Before we start installing Nginx and php7-fpm, we'll also learn to add the repository source for the EPEL package. Use the following command:

Yum-y install epel-release

Now start installing Nginx from the EPEL repository:

Yum-y install nginx

Then we need to add another warehouse for php7-fpm. There are many remote repositories on the Internet that offer PHP 7 series packages, and I use webtatic here.

Add a PHP7-FPM webtatic repository:

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

Then it's time to install PHP7-FPM and some of the packages that Nextcloud needs.

Yum-y install php70w-fpm php70w-cli php70w-gd php70w-mcrypt php70w-mysql php70w-pear php70w-xml php70w-mbstring php70w-pdo php70w-json php70w-pecl-apcu php70w-pecl-apcu-devel

Finally, check the version number of PHP from the server terminal to verify that PHP is installed correctly.

Php-v

Step 2-configure PHP7-FPM

In this step, we will configure php-fpm to run in conjunction with Nginx. Php7-fpm will run with the nginx user and listen on port 9000.

Use vim to edit the default php7-fpm configuration file.

Vim / etc/php-fpm.d/www.conf

On lines 8 and 10, user and group are assigned nginx.

User = nginxgroup = nginx

On line 22, make sure php-fpm is running on the designated port.

Listen = 127.0.0.1 9000

Uncomment lines 366-370 and enable the system environment variable for php-fpm.

Env [HOSTNAME] = $HOSTNAMEenv [path] = / usr/local/bin:/usr/bin:/binenv [TMP] = / tmpenv [TMPDIR] = / tmpenv [TEMP] = / tmp

Save the file and exit the vim editor.

The next step is to create a new folder session under the / var/lib/ directory and change its owner to the nginx user.

Mkdir-p / var/lib/php/sessionchown nginx:nginx-R / var/lib/php/session/

Then start php-fpm and Nginx and set them to services that start with boot.

Sudo systemctl start php-fpmsudo systemctl start nginxsudo systemctl enable php-fpmsudo systemctl enable nginx

PHP7-FPM configuration complete

Step 3-install and configure MariaDB

I use MariaDB as the database of Nextcloud here. You can use the yum command directly to install the mariadb-server package from the CentOS default remote repository.

Yum-y install mariadb mariadb-server

Start MariaDB and add it to the service that starts with the system.

Systemctl start mariadbsystemctl enable mariadb

Now start configuring the root user password for MariaDB.

Mysql_secure_installation

Type Y, and then set the root password for MariaDB.

Set root password? [Y/n] YNew password:Re-enter new password:Remove anonymous users? [Y/n] YDisallow root login remotely? [Y/n] YRemove test database and access to it? [Y/n] YReload privilege tables now? [Y/n] Y

Now that the password is set, log in to mysql shell and create a new database and user for Nextcloud. Here I create a database named nextcloud_db and a user named nextclouduser with a password of nextclouduser@. Of course, choose a more secure password for your own system.

Mysql-u root-p

Enter the root password of MariaDB to log in to mysql shell.

Enter the following mysql query statement to create a new database and user.

Create database nextcloud_db;create user nextclouduser@localhost identified by 'nextclouduser@';grant all privileges on nextcloud_db.* to nextclouduser@localhost identified by' nextclouduser@';flush privileges

User creation of nextcloud_db database and nextclouduser database is complete

Step 4-generate a self-signed SSL certificate for Nextcloud

In the tutorial, I will have the client run Nextcloud over a https connection. You can use a free SSL certificate such as let's encrypt, or create your own self-signed (self signed) SSL certificate. Here I use OpenSSL to create my own self-signed SSL certificate.

Create a new directory for the SSL file:

Mkdir-p / etc/nginx/cert/

As follows, use openssl to generate a new SSL certificate.

Openssl req-new-x509-days 365-nodes-out / etc/nginx/cert/nextcloud.crt-keyout / etc/nginx/cert/nextcloud.key

Finally, use the chmod command to set the permissions for all certificate files to 600.

Chmod 700 / etc/nginx/certchmod 600 / etc/nginx/cert/*

Step 5-download and install Nextcloud

I use the wget command directly to download Nextcloud to the server, so I need to install wget first. In addition, unzip needs to be installed for decompression. Use the yum command to install both programs.

Yum-y install wget unzip

Enter the / tmp directory first, and then use wget to download the latest Nextcloud 10 from the official website.

Cd / tmpwget https://download.nextcloud.com/server/releases/nextcloud-10.0.2.zip

Extract the Nextcloud and move it to the / usr/share/nginx/html/ directory.

Unzip nextcloud-10.0.2.zipmv nextcloud/ / usr/share/nginx/html/

Next, go to the web root of Nginx to create a data folder for Nextcloud.

Cd / usr/share/nginx/html/mkdir-p nextcloud/data/

Change the owner of the nextcloud directory to nginx users and groups.

Chown nginx:nginx-R nextcloud/ step 6-configure a virtual host for Nextcloud in Nginx

In step 5 we have downloaded the Nextcloud source code and configured it to run on the Nginx server, but we also need to configure a virtual host for it. Create a new virtual host profile, nextcloud.conf, under the conf.d directory of Nginx.

Cd / etc/nginx/conf.d/vim nextcloud.conf

Paste the following into the virtual host configuration file:

Upstream php-handler {server 127.0.0.1 server 9000; # server unix:/var/run/php5-fpm.sock;} server {listen 80; server_name cloud.nextcloud.co; # enforce https return 301 https://$server_name$request_uri;}server {listen 443 ssl; server_name cloud.nextcloud.co; ssl_certificate / etc/nginx/cert/nextcloud.crt; ssl_certificate_key / etc/nginx/cert/nextcloud.key # Add headers to serve security related headers # Before enabling Strict-Transport-Security headers please read into this # topic first. Add_header Strict-Transport-Security "max-age=15768000; includeSubDomains; preload;"; add_header X-Content-Type-Options nosniff; add_header X-Frame-Options "SAMEORIGIN"; add_header X-XSS-Protection "1; mode=block"; add_header X-Robots-Tag none; add_header X-Download-Options noopen; add_header X-Permitted-Cross-Domain-Policies none; # Path to the root of your installation root / usr/share/nginx/html/nextcloud/ Location = / robots.txt {allow all; log_not_found off; access_log off;} # The following 2 rules are only needed for the user_webfinger app. # Uncomment it if you're planning to use this app. # rewrite ^ / .well-known/host-meta / public.php?service=host-meta last; # rewrite ^ / .well-known/host-meta.json / public.php?service=host-meta-json # last; location = / .well-known/carddav {return 301$ scheme://$host/remote.php/dav;} location = / .well-known/caldav {return 301$ scheme://$host/remote.php/dav;} # set max upload size client_max_body_size 512m Fastcgi_buffers 64 4K; # Disable gzip to avoid the removal of the ETag header gzip off; # Uncomment if your server is build with the ngx_pagespeed module # This module is currently not supported. # pagespeed off; error_page 403 / core/templates/403.php; error_page 404 / core/templates/404.php; location / {rewrite ^ / index.php$uri;} location ~ ^ / (?: build | tests | config | lib | 3rdparty | data) / {deny all;} location ~ ^ / (?: /. | autotest | occ | issue | indie | db_ | console) {deny all } location ~ ^ / (?: index | remote | public | cron | core/ajax/update | status | ocs/v [12] | updater/.+ | ocs-provider/.+ | core/templates/40 [34]) / .php (?: $| /) {include fastcgi_params; fastcgi_split_path_info ^ (. + / .php) (/. *) $; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param PATH_INFO $fastcgi_path_info; fastcgi_param HTTPS on # Avoid sending the security headers twice fastcgi_param modHeadersAvailable true; fastcgi_param front_controller_active true; fastcgi_pass php-handler; fastcgi_intercept_errors on; fastcgi_request_buffering off;} location ~ ^ / (?: updater | ocs-provider) (?: $| /) {try_files $uri/ = 404; index index.php } # Adding the cache control header for js and css files # Make sure it is BELOW the PHP block location ~ * /. (?: css | js) ${try_files $uri / index.php$uri$is_args$args; add_header Cache-Control "public, max-age=7200"; # Add headers to serve security related headers (It is intended to # have those duplicated to the ones above) # Before enabling Strict-Transport-Security headers please read into # this topic first. Add_header Strict-Transport-Security "max-age=15768000; includeSubDomains; preload;"; add_header X-Content-Type-Options nosniff; add_header X-Frame-Options "SAMEORIGIN"; add_header X-XSS-Protection "1; mode=block"; add_header X-Robots-Tag none; add_header X-Download-Options noopen; add_header X-Permitted-Cross-Domain-Policies none # Optional: Don't log access to assets access_log off;} location ~ * /. (?: svg | gif | png | html | ttf | woff | ico | jpeg) ${try_files $uri / index.php$uri$is_args$args; # Optional: Don't log access to other assets access_log off;}}

Save the file and exit vim.

Download and test the following Nginx configuration file for errors, and if not, you can restart the service.

Nginx-tsystemctl restart nginx step 7-configure SELinux and FirewallD rules for Nextcloud

In this tutorial, we will run SELinux in mandatory mode, so we need a SELinux management tool to configure SELinux for Nextcloud.

Use the following command to install the SELinux management tools.

Yum-y install policycoreutils-python

Then run the following command as the root user to make Nextcloud run under the SELinux environment. If you are using a directory with a different name, remember to replace nextcloud.

Semanage fcontext-a-t httpd_sys_rw_content_t'/ usr/share/nginx/html/nextcloud/data (/. *)? 'semanage fcontext-a-t httpd_sys_rw_content_t' / usr/share/nginx/html/nextcloud/config (/. *)? 'semanage fcontext-a-t httpd_sys_rw_content_t' / usr/share/nginx/html/nextcloud/apps (/. *)? 'semanage fcontext-a-t httpd_sys_rw_content_t '/ usr/share/nginx/html/nextcloud/assets (/. *)?' semanage fcontext-a-t httpd_sys_rw_content_t'/ usr/share/nginx/html/nextcloud/.htaccess'semanage fcontext-a-t httpd_sys_rw_content_t'/ usr/share/nginx/html/nextcloud/.user.ini'restorecon-Rv'/ usr/share/nginx/html/nextcloud/'

Next, we will enable the firewalld service and open both the http and https ports for Nextcloud.

Start firewalld and set it to boot with the system.

Systemctl start firewalldsystemctl enable firewalld

Now use the firewall-cmd command to open the http and https ports, and then reload the firewall.

Firewall-cmd-permanent-add-service=httpfirewall-cmd-permanent-add-service=httpsfirewall-cmd-reload

At this point, the server configuration is complete.

Step 8-Nextcloud installation

Open your Web browser, enter the domain name you set for Nextcloud, I set it to cloud.nextcloud.co here, and then redirect to a more secure https connection.

Set your administrator username and password, then enter the data validation information, and click 'finish installation (Finish Setup)'.

The Nextcloud management panel is roughly as follows:

Install Nextcloud in CentOS 7 install Nextcloud in CentOS 7

Nextcloud user Settings:

Management Settings:

This is the end of this article on "how to install Nextcloud in Linux". I hope the above content can be helpful to you, so that you can learn more knowledge. if you think the article is good, please share it out for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report