Deploy your personal web drive “NAS” on raspberry PI with Nextcloud

This time I used the latest Raspbian Stretch system, which is based on Debian 9.

The software program is Nextcloud 12.0.4

Because you only want to use it on a local area network, you use the simplest deployment mode, which is equivalent to minimal configuration.

Therefore, this solution is not recommended for external servers because it is not secure.

Write, > > > 14/01/2018. 17:00.

1) Download the program image:

Reference commands:

The links https://download.nextcloud.com/server/releases/nextcloud-12.0.4.zipCopy the code

Official page: Portal

2) Install dependent software and arrange file system:

A) Installation of dependent software:

Since I have other sites running Nginx, I use Nginx here as well.

One is easy to manage together, and the other is relatively light compared to Apache2, after all, pie performance is so small.

Apache solution can refer to the official Tutorial, quite easy to put up the Tutorial Page

Reference commands:

All commands should be preceded by sudo as user root
sudo su

# apt Install all dependencies
# nginx uses phP-fpm
# Nextcloud only supports Php up to version 7.0FPM nginx apt install php7.0 FPM nginx apt install php7.0-gd php7.0-json php7.0-mysql php7.0-curl php7.0-mbstring apt install Php7.0-intl php7.0-mcrypt php7.0-imagick php7.0-xml php7.0-zip# install MySQL
apt install mysql-server

# apt install mysql-client && sudo apt-get install libmysqlclient-dev
The second sentence does not need to be run, because it is found that when the first sentence is run on the pie, it automatically installs everything.
No need to set root password. Also, it installs MariaDB instead of MySQL. But that doesn't matter.
Copy the code
B) Layout of file system:

Note: All paths in the following commands should be replaced if you use them differently

Reference commands:

All commands should be preceded by sudo as user root
sudo su

# decompress imageUnzip nextcloud - 12.0.4. ZipCreate a directory and move the program to the directory you want
mkdir /www && mv nextcloud /www/nextcloud

# Change permission related
cd /www
chmod -R 0770 nextcloud/
chown -R www-data nextcloud/
chgrp -R  www-data nextcloud/

Create data directory and change permissions
mkdir nextcloud.data
chmod -R 0770 nextcloud.data/
chown -R www-data nextcloud.data/
chgrp -R  www-data nextcloud.data/

Create.log and.sock files/ WWW /logs/nextcloud/ create php7.0-fpm. Sock in/WWW /logs/nextcloud/ create php7.0-fpm. Sock in/WWW /logs/nextcloud/Copy the code
C) Layout data system:

Reference commands:

Set root password
mysqladmin -u root -p password YOUR_PASSWORD_HERE

Log in as root
mysql -uroot -p
Copy the code
All commands below this are presentSQLCreate database inside Shellcreatedatabase nextcloud; Create user and add permissioncreate user 'www'@'localhost' identified by 'YOUR_PASSWORD_HERE';
grant all privileges on nextcloud.* to 'www'@'localhost' identified by 'YOUR_PASSWORD_HERE'; # Set it up here. The rest of the program will take care of itself.Copy the code

3) Set Php related:

Modify the contents of /etc/php.7.0/fpm /php.ini file:

opcache.enable=1
opcache.enable_cli=1
opcache.interned_strings_buffer=8
opcache.max_accelerated_files=10000
opcache.memory_consumption=128
opcache.save_comments=1
opcache.revalidate_freq=1
Copy the code

Shell run printenv PATH reproduced by the content of the modified/etc/PHP / 7.0 / FPM/pool. D/www.conf file contents:

Env [PATH] = what you get aboveCopy the code

4) Set Nginx related:

Create the nextcloud.conf file in /etc/nginx/sites-available/

Here are the Settings on my pie, very simple Settings, using Http instead of Https. Content Reference:

upstream php-handler {
    I prefer to use the.sock file mapping directly
    # server 127.0.0.1:9000;
    serverUnix: / run/PHP/php7.0 - FPM. The sock. }server {
    # listen on port 80, no domain name, file path
    listen               80;
    server_name          _;
    root                 /www/nextcloud;

    # character set Settings
    charset              utf-8;

    # log, which corresponds to the previous creation
    access_log           /www/logs/nextcloud/access.log;
    error_log            /www/logs/nextcloud/error.log;

    # these add_headers are fine
    add_header           X-Content-Type-Options nosniff;
    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;

    # the location set
    location = /robots.txt {
        allow all;
        log_not_found off;
        access_log off;
    }

    location = /.well-known/carddav {
        return 301 $scheme://$host/remote.php/dav;
    }


    location = /.well-known/caldav {
        return 301 $scheme://$host/remote.php/dav;
    }

    # Maximum upload size
    client_max_body_size 512M;
    fastcgi_buffers 64 4K;

    Set # Gzip
    gzip on;
    gzip_vary on;
    gzip_comp_level 4;
    gzip_min_length 256;
    gzip_proxied expired no-cache no-store private no_last_modified no_etag auth;
    gzip_types application/atom+xml application/javascript application/json application/ld+json application/manifest+json application/rss+xml application/vnd.geo+json application/vnd.ms-fontobject application/x-font-ttf application/x-web-app-manifest+json application/xhtml+xml application/xml font/opentype image/bmp image/svg+xml image/x-icon text/cache-manifest text/css text/plain text/vcard text/vnd.rim.location.xloc text/vtt text/x-component text/x-cross-domain-policy;

    # the location set
    location / {
        rewrite ^ /index.php$uri;
    }


    location ~ ^ / (? :build|tests|config|lib|3rdparty|templates|data)/ {
        deny all;
    }

    location ~ ^ / (? :\.|autotest|occ|issue|indie|db_|console) {
        deny all;
    }

    # Php related
    location ~ ^ / (? :index|remote|public|cron|core/ajax/update|status|ocs/v[12]|updater/.+|ocs-provider/.+)\.php(? : $| /) {
        fastcgi_split_path_info ^(.+\.php)(/.*)$;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param PATH_INFO $fastcgi_path_info;
        fastcgi_param HTTPS off;

        #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;
    }

    # Js Css cache Settings
    This should be written under Php Settings
    location ~ \. (? :css|js|woff|svg|gif)$ {
        try_files $uri /index.php$uri$is_args$args;
        add_header Cache-Control "public, max-age=15778463";
        add_header X-Content-Type-Options nosniff;
        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;
        access_log off;
    }

    Static file correlation
    location ~ \. (? :png|html|ttf|ico|jpg|jpeg)$ {
        try_files $uri /index.php$uri$is_args$args;
        access_log off; }}Copy the code

5) Settings:

This is all done, open the corresponding IP address, page Settings:

  1. Create a supermanaged account
  2. Point the data folder to the one we created above/www/nextcloud.datafolder
  3. Point the database to the user we created above:

It’s like this, if you change the port or something just do it,

Note that you should use localhost for both the database and here instead of 127.0.0.1, because I found that the 127.0.0.1 I started with didn’t recognize it, for unknown reasons, or maybe I’m an exception.

Database User:     www
Database Password: YOUR_PASSWORD_HERE
Database Name:     nextcloud
Database Host:     localhost:3306
Copy the code

5) Others:

Why do I choose this program? Because it’s so powerful! After installing the Settings, don’t forget to click “Settings > Apply” on the upper right! There’s a huge market for apps. You can have almost anything you need, such as:

  • Live chat, video call, backup cell phone
  • Application of kanban
  • Youtube, Http, Https, BT download
  • Create a website
  • Coffer application and password management
  • GPS related record and edit
  • Mind maps for DrawIO
  • Markdown editor
  • Office Online editor
  • All kinds of online editing online preview…

Check it out here: The App Market