1. 程式人生 > 其它 >centos7搭建nextcloud個人網盤

centos7搭建nextcloud個人網盤

nextcloud推薦在LAMP環境使用,所有得準備好lamp環境。我這裡準備的是cenots7/8 , php7.4 , mariadb ,和使用redis做快取。

cenots使用最小化安裝,

首先,安裝好yum/dnf源,加上epel源,這裡不做贅述。(我使用的是阿里雲的源)

安裝一些基礎包:

[root@bak ~]# yum install -y epel-release yum-utils unzip curl wget bash-completion policycoreutils-python-utils mlocate bzip2
#更新一下包
[root@bak ~]# yum -y update

1.安裝apache

[root@bak ~]# yum install -y httpd

配置虛擬主機:

新建配置檔案/etc/httpd/conf.d/nextcloud.conf,往裡面加入下面的配置

<VirtualHost *:80>
  DocumentRoot /var/www/html/nextcloud/
  ServerName  your.server.com

  <Directory /var/www/html/nextcloud/>
    Require all granted
    AllowOverride All
    Options FollowSymLinks MultiViews

    
<IfModule mod_dav.c> Dav off </IfModule> </Directory> </VirtualHost>

啟動httpd,並開機自啟

[root@bak ~]# systemctl enable --now httpd
Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.

2.安裝php

配置php的儲存庫

[root@bak ~]# yum -y install https://
rpms.remirepo.net/enterprise/remi-release-7.rpm [root@bak ~]# yum-config-manager --enable remi-php74

安裝php及擴充套件

[root@bak ~]# yum -y install php  php-cli php-fpm php-mysqlnd php-zip php-devel php-gd php-mcrypt php-mbstring php-curl php-xml php-pear php-bcmath php-json php-redis php-opcache php-pecl-apcu php-intl php-process php-imagick php-gmp
#中途下載後需要驗證,輸入即可
#完成後可將php.ini的memory_limit調高,預設128M

3.安裝資料庫

[root@bak ~]# yum install -y mariadb mariadb-server
[root@bak ~]# systemctl enable --now mariadb
Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.service.

初始化

[root@bak ~]# mysql_secure_installation
Enter current password for root (enter for none): 
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.

Set root password? [Y/n] y
New password: 
Re-enter new password: 
Password updated successfully!
Reloading privilege tables..
 ... Success!


By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] y
 ... Success!

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] y
 ... Success!

By default, MariaDB comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] y
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] y
 ... Success!

Cleaning up...

All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.

Thanks for using MariaDB!

建立nextcloud使用的資料庫

[root@bak ~]# mysql -uroot -p
Enter password: 

MariaDB [(none)]> create database nextcloud;
Query OK, 1 row affected (0.00 sec)

MariaDB [(none)]> grant all privileges on nextcloud.* to 'nextcloud'@'%' identified by 'nextcloud';
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.00 sec)

4.安裝redis

[root@bak ~]# yum install -y redis

[root@bak ~]# systemctl enable --now redis
Created symlink from /etc/systemd/system/multi-user.target.wants/redis.service to /usr/lib/systemd/system/redis.service.

5.配置nextcloud

上傳nextcloud,解壓

[root@bak ~]# ls
anaconda-ks.cfg  nextcloud-20.0.1.zip
[root@bak ~]# unzip nextcloud-20.0.1.zip 

複製到虛擬主機路徑

[root@bak ~]# cp -R nextcloud/ /var/www/html/

建立資料目錄

[root@bak ~]# mkdir /var/www/html/nextcloud/data

給apache有nextcloud的許可權

[root@bak ~]# chown -R apache:apache /var/www/html/nextcloud

重啟服務

systemctl restart httpd.service

通過IP訪問,配置好管理員和資料庫賬戶密碼

6.配置redis
完成web介面配置後,將生成/var/www/html/nextcloud/config/config.php

把下面的redis配置加入這個檔案(不知道在哪就載入檔案末尾的);的上一行)

 
'memcache.distributed' => '\OC\Memcache\Redis',
'memcache.locking' => '\OC\Memcache\Redis',
'memcache.local' => '\OC\Memcache\APCu',
'redis' => array(
  'host' => 'localhost',
  'port' => 6379,
),

重啟服務

[root@bak ~]# systemctl restart httpd
[root@bak ~]# systemctl restart redis

檢視redis

[root@bak ~]# redis-cli 
127.0.0.1:6379> keys * 
 1) "a50c55cb49086203752b976ed6b19d74/SCSS-cached-e7da93d63304cc862fc6857840bb5ca220.0.1.1/core/458e-6468-css-variables.css"
 2) "a50c55cb49086203752b976ed6b19d74/imagePath-e7da93d63304cc862fc6857840bb5ca2-photos-favicon-mask.svg"
 3) "a50c55cb49086203752b976ed6b19d74/imagePath-e7da93d63304cc862fc6857840bb5ca2-activity-favicon.ico"
 4) "a50c55cb49086203752b976ed6b19d74/SCSS-deps-e7da93d63304cc862fc6857840bb5ca2text-232d-6468-icons.css.deps"
 5) "a50c55cb49086203752b976ed6b19d74/imagePath-e7da93d63304cc862fc6857840bb5ca2-core-actions/logout.svg"
 6) "a50c55cb49086203752b976ed6b19d74/imagePath-e7da93d63304cc862fc6857840bb5ca2-core-places/files.svg"
 7) "a50c55cb49086203752b976ed6b19d74/imagePath-e7da93d63304cc862fc6857840bb5ca2-settings-admin.svg"
 8) "a50c55cb49086203752b976ed6b19d74/imagePath-e7da93d63304cc862fc6857840bb5ca2-activity-activity.svg"
 9) "a50c55cb49086203752b976ed6b19d74/imagePath-e7da93d63304cc862fc6857840bb5ca2-user_status-app.svg"
10) "a50c55cb49086203752b976ed6b19d74/SCSS-cached-e7da93d63304cc862fc6857840bb5ca220.0.1.1/photos/62ab-6468-icons.css"
11) "a50c55cb49086203752b976ed6b19d74/imagePath-e7da93d63304cc862fc6857840bb5ca2-firstrunwizard-apps/groupfolders.svg"
12) "a50c55cb49086203752b976ed6b19d74/imagePath-e7da93d63304cc862fc6857840bb5ca2-files-favicon-touch.png"
13) "a50c55cb49086203752b976ed6b19d74/SCSS-deps-e7da93d63304cc862fc6857840bb5ca2core-458e-6468-css-variables.css.deps"
14) "a50c55cb49086203752b976ed6b19d74/theming-http://10.11.114.12shouldReplaceIcons"
15) "a50c55cb49086203752b976ed6b19d74/imagePath-e7da93d63304cc862fc6857840bb5ca2-files-app.svg"
16) "a50c55cb49086203752b976ed6b19d74/imagePath-e7da93d63304cc862fc6857840bb5ca2-core-actions/share.svg"
17) "a50c55cb49086203752b976ed6b19d74/imagePath-e7da93d63304cc862fc6857840bb5ca2-dashboard-favicon-touch.png"
18) "a50c55cb49086203752b976ed6b19d74/SCSS-cached-e7da93d63304cc862fc6857840bb5ca220.0.1.1/dashboard/d149-6468-dashboard.css"
19) "a50c55cb49086203752b976ed6b19d74/imagePath-e7da93d63304cc862fc6857840bb5ca2-activity-favicon-touch.png"
20) "a50c55cb49086203752b976ed6b19d74/imagePath-e7da93d63304cc862fc6857840bb5ca2-core-places/contacts.svg"
21) "a50c55cb49086203752b976ed6b19d74/imagePath-e7da93d63304cc862fc6857840bb5ca2-settings-users.svg"
22) "a50c55cb49086203752b976ed6b19d74/imagePath-e7da93d63304cc862fc6857840bb5ca2-files-favicon.ico"
23) "a50c55cb49086203752b976ed6b19d74/imagePath-e7da93d63304cc862fc6857840bb5ca2-photos-favicon-touch.png"
24) "a50c55cb49086203752b976ed6b19d74/SCSS-deps-e7da93d63304cc862fc6857840bb5ca2activity-c4f1-6468-style.css.deps"
25) "a50c55cb49086203752b976ed6b19d74/imagePath-e7da93d63304cc862fc6857840bb5ca2-photos-manifest.json"
26) "a50c55cb49086203752b976ed6b19d74/imagePath-e7da93d63304cc862fc6857840bb5ca2-core-logo/logo.svg"
27) "a50c55cb49086203752b976ed6b19d74/imagePath-e7da93d63304cc862fc6857840bb5ca2-settings-apps.svg"
28) "a50c55cb49086203752b976ed6b19d74/imagePath-e7da93d63304cc862fc6857840bb5ca2-firstrunwizard-apps/tasks.svg"
29) "a50c55cb49086203752b976ed6b19d74/imagePath-e7da93d63304cc862fc6857840bb5ca2-photos-favicon.ico"
30) "a50c55cb49086203752b976ed6b19d74/imagePath-e7da93d63304cc862fc6857840bb5ca2-activity-activity-dark.svg"
31) "a50c55cb49086203752b976ed6b19d74/SCSS-deps-e7da93d63304cc862fc6857840bb5ca2files_sharing-4039-6468-icons.css.deps"
32) "a50c55cb49086203752b976ed6b19d74/imagePath-e7da93d63304cc862fc6857840bb5ca2-activity-favicon-mask.svg"
33) "a50c55cb49086203752b976ed6b19d74/imagePath-e7da93d63304cc862fc6857840bb5ca2-core-actions/checkmark.svg"
34) "a50c55cb49086203752b976ed6b19d74/imagePath-e7da93d63304cc862fc6857840bb5ca2-photos-app.svg"
35) "a50c55cb49086203752b976ed6b19d74/SCSS-deps-e7da93d63304cc862fc6857840bb5ca2photos-62ab-6468-icons.css.deps"
36) "a50c55cb49086203752b976ed6b19d74/SCSS-cached-e7da93d63304cc862fc6857840bb5ca220.0.1.1/user_status/47cd-6468-user-status-menu.css"
37) "a50c55cb49086203752b976ed6b19d74/imagePath-e7da93d63304cc862fc6857840bb5ca2-firstrunwizard-apps/social.svg"
38) "a50c55cb49086203752b976ed6b19d74/SCSS-cached-e7da93d63304cc862fc6857840bb5ca220.0.1.1/notifications/0577-6468-styles.css"
39) "a50c55cb49086203752b976ed6b19d74/imagePath-e7da93d63304cc862fc6857840bb5ca2-settings-help.svg"
40) "a50c55cb49086203752b976ed6b19d74/imagePath-e7da93d63304cc862fc6857840bb5ca2-core-actions/user.svg"
41) "a50c55cb49086203752b976ed6b19d74/imagePath-e7da93d63304cc862fc6857840bb5ca2-dashboard-manifest.json"
42) "a50c55cb49086203752b976ed6b19d74/SCSS-deps-e7da93d63304cc862fc6857840bb5ca2dashboard-d149-6468-dashboard.css.deps"
43) "a50c55cb49086203752b976ed6b19d74/imagePath-e7da93d63304cc862fc6857840bb5ca2-core-filetypes/video.svg"
44) "a50c55cb49086203752b976ed6b19d74/imagePath-e7da93d63304cc862fc6857840bb5ca2-core-logo/logo.png"
45) "a50c55cb49086203752b976ed6b19d74/SCSS-deps-e7da93d63304cc862fc6857840bb5ca2user_status-47cd-6468-user-status-menu.css.deps"
46) "a50c55cb49086203752b976ed6b19d74/imagePath-e7da93d63304cc862fc6857840bb5ca2-core-filetypes/application-pdf.svg"
47) "a50c55cb49086203752b976ed6b19d74/imagePath-e7da93d63304cc862fc6857840bb5ca2-dashboard-dashboard.svg"
48) "a50c55cb49086203752b976ed6b19d74/SCSS-cached-e7da93d63304cc862fc6857840bb5ca220.0.1.1/activity/c4f1-6468-style.css"
49) "a50c55cb49086203752b976ed6b19d74/imagePath-e7da93d63304cc862fc6857840bb5ca2-core-filetypes/folder.svg"
50) "a50c55cb49086203752b976ed6b19d74/imagePath-e7da93d63304cc862fc6857840bb5ca2-core-places/calendar.svg"
51) "a50c55cb49086203752b976ed6b19d74/imagePath-e7da93d63304cc862fc6857840bb5ca2-files-manifest.json"
52) "a50c55cb49086203752b976ed6b19d74/imagePath-e7da93d63304cc862fc6857840bb5ca2-core-actions/comment.svg"
53) "a50c55cb49086203752b976ed6b19d74/imagePath-e7da93d63304cc862fc6857840bb5ca2-firstrunwizard-info.svg"
54) "a50c55cb49086203752b976ed6b19d74/SCSS-cached-e7da93d63304cc862fc6857840bb5ca220.0.1.1/core/458e-6468-server.css"
55) "a50c55cb49086203752b976ed6b19d74/imagePath-e7da93d63304cc862fc6857840bb5ca2-firstrunwizard-apps/deck.svg"
56) "a50c55cb49086203752b976ed6b19d74/SCSS-cached-e7da93d63304cc862fc6857840bb5ca220.0.1.1/files/d71e-6468-merged.css"
57) "a50c55cb49086203752b976ed6b19d74/imagePath-e7da93d63304cc862fc6857840bb5ca2-core-filetypes/x-office-document.svg"
58) "a50c55cb49086203752b976ed6b19d74/SCSS-cached-e7da93d63304cc862fc6857840bb5ca220.0.1.1/text/232d-6468-icons.css"
59) "a50c55cb49086203752b976ed6b19d74/imagePath-e7da93d63304cc862fc6857840bb5ca2-activity-manifest.json"
60) "a50c55cb49086203752b976ed6b19d74/imagePath-e7da93d63304cc862fc6857840bb5ca2-core-actions/star-dark.svg"
61) "a50c55cb49086203752b976ed6b19d74/theming-http://10.11.114.12getScssVariables"
62) "a50c55cb49086203752b976ed6b19d74/imagePath-e7da93d63304cc862fc6857840bb5ca2-firstrunwizard-apps/notes.svg"
63) "a50c55cb49086203752b976ed6b19d74/imagePath-e7da93d63304cc862fc6857840bb5ca2-dashboard-favicon.ico"
64) "a50c55cb49086203752b976ed6b19d74/imagePath-e7da93d63304cc862fc6857840bb5ca2-files-add-color.svg"
65) "a50c55cb49086203752b976ed6b19d74/imagePath-e7da93d63304cc862fc6857840bb5ca2-dashboard-favicon-mask.svg"
66) "a50c55cb49086203752b976ed6b19d74/imagePath-e7da93d63304cc862fc6857840bb5ca2-core-background.png"
67) "a50c55cb49086203752b976ed6b19d74/SCSS-deps-e7da93d63304cc862fc6857840bb5ca2notifications-0577-6468-styles.css.deps"
68) "a50c55cb49086203752b976ed6b19d74/imagePath-e7da93d63304cc862fc6857840bb5ca2-files-favicon-mask.svg"
69) "a50c55cb49086203752b976ed6b19d74/SCSS-deps-e7da93d63304cc862fc6857840bb5ca2core-458e-6468-server.css.deps"
70) "a50c55cb49086203752b976ed6b19d74/imagePath-e7da93d63304cc862fc6857840bb5ca2-core-actions/delete.svg"
71) "a50c55cb49086203752b976ed6b19d74/SCSS-deps-e7da93d63304cc862fc6857840bb5ca2files-d71e-6468-merged.css.deps"
72) "a50c55cb49086203752b976ed6b19d74/SCSS-cached-e7da93d63304cc862fc6857840bb5ca220.0.1.1/files_sharing/4039-6468-icons.css"
。。。。。省略。。。。。。

還有其他一些優化,官網和網上也能找到,作為個人使用已經完全足夠

搭建常見問題:

1.搭建完成,無法訪問,首先檢查伺服器防火牆是否關閉

2.出現下列問題

內部伺服器錯誤

伺服器發生一個內部錯誤並且無法完成你的請求.
如果多次出現這個錯誤, 請聯絡伺服器管理員, 請把下面的技術細節包含在您的報告中.
更多細節可以在伺服器日誌中找到.

直入正題

這個問題的出現是由於資料夾許可權設定的不到位。

如果直接簡單地去設定許可權,比如:

解決方式1:關閉selinux

解決方式2:

chown apache:apache nextcloud
chmod 770 nextcloud -Rf

那麼你就會得到“內部伺服器錯誤”的提示。

正確的做法是,

1.使用下面的配置指令碼(這個指令碼大概已經是第三遍被貼出來了):

隨便找個地方(不要在Nextcloud的程式目錄下),建立一個shell指令碼:

vim permission.sh

然後把下面的內容貼上進去(在vim中,你需要先按i,然後insert+shift鍵貼上)

#!/bin/bash
ocpath='/var/www/nextcloud/'   #修改為你Nextcloud所放置的目錄
htuser='apache'                #網頁伺服器使用者
htgroup='apache'               #網頁伺服器的組
rootuser='root'

printf "Creating possible missing Directories\n"
mkdir -p $ocpath/data
mkdir -p $ocpath/assets
mkdir -p $ocpath/updater

printf "chmod Files and Directories\n"
find ${ocpath}/ -type f -print0 | xargs -0 chmod 0640
find ${ocpath}/ -type d -print0 | xargs -0 chmod 0750

printf "chown Directories\n"
chown -R ${rootuser}:${htgroup} ${ocpath}/
chown -R ${htuser}:${htgroup} ${ocpath}/apps/
chown -R ${htuser}:${htgroup} ${ocpath}/assets/
chown -R ${htuser}:${htgroup} ${ocpath}/config/
chown -R ${htuser}:${htgroup} ${ocpath}/data/
chown -R ${htuser}:${htgroup} ${ocpath}/themes/
chown -R ${htuser}:${htgroup} ${ocpath}/updater/

chmod +x ${ocpath}/occ

printf "chmod/chown .htaccess\n"
if [ -f ${ocpath}/.htaccess ]
then
  chmod 0644 ${ocpath}/.htaccess
  chown ${rootuser}:${htgroup} ${ocpath}/.htaccess
fi
if [ -f ${ocpath}/data/.htaccess ]
then
  chmod 0644 ${ocpath}/data/.htaccess
  chown ${rootuser}:${htgroup} ${ocpath}/data/.htaccess
fi

按ESC鍵切換到普通模式,然後輸入:wq儲存退出。

2.關閉或正確地配置SELinux

臨時的關閉可以用:

setenforce 0

永久關閉則可以編輯/etc/selinux/config 檔案:

vim /etc/selinux/config

找到SELINUX=enforcing,將它改為SELINUX=disabled。

再重新整理頁面,錯誤資訊就消失了:

解決過程

按CentOS中通常的步驟,YUM安裝httpd、php、maraidb,然後下載Nextcloud的安裝包,解壓,簡單地設定了一下許可權,關掉防火牆、SELinux,然後瀏覽器裡訪問,提示錯誤。

如果上述步驟是在Debian/Ubuntu中做,現在已經可以看到安裝介面了,而這個是什麼情況?!

按提示中所說,錯誤記錄在了日誌裡,於是檢查了一下error.log(一般位於/etc/httpd/logs裡,取決於你的配置),發現了這樣的錯誤資訊:

[Sat Nov 18 19:54:20.198935 2017] [php7:notice] [pid 24868] [client 192.168.3.66:65387] {"reqId":"WhAfbEVDNMLHuXKdeyBnUAAAAAI","level":3,"time":"2017-11-18T11:54:20+00:00","remoteAddr":"192.168.3.66","user":"--","app":"PHP","method":"GET","url":"\\/index.php","message":"chmod(): No such file or directory at \\/var\\/www\\/nextcloudtest\\/lib\\/private\\/Log\\/File.php#134","userAgent":"Mozilla\\/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit\\/537.36 (KHTML, like Gecko) Chrome\\/62.0.3202.94 Safari\\/537.36","version":""}

呃………原來是一個PHP函式的報錯。然而,chmod(): No such file or directory???

趕緊看下:

[root@imagineocean nextcloudtest]# ls lib/private/Log
ErrorHandler.php  Errorlog.php  File.php  Rotate.php  Syslog.php

這些檔案明明好好地躺在那裡!

第一反應是SELinux在搗鬼,於是檢查了一下:

[root@imagineocean nextcloud]# getenforce
Permissive

轉載:https://www.cnblogs.com/shipment/p/14011910.html

轉載:解決CentOS中安裝ownCloud/Nextcloud出現“內部伺服器錯誤”-雲碼酷-綜合自學教程 - Powered by 雲碼酷! (webzx.net)