Nextcloud(CentOS 7)安装与配置(LNMP平台)

这篇文章主要介绍CentOS 7  LNMP平台上部署nextcloud的方法,具体的调优和内网穿透,请参照后面的文章

一、环境准备
1、准备Yum源
先安装必须的yum源,centos自带的BASE/EXTRAS/UPDATES必须齐全,同时安装fedora的epel,源不够的自行百度装好。
[root@ftpserver ~]# yum install -y epel*
Loaded plugins: fastestmirror
base | 3.6 kB 00:00
epel/x86_64/metalink | 8.9 kB 00:00
epel | 3.2 kB 00:00
extras | 3.4 kB 00:00
updates | 3.4 kB 00:00
(1/6): epel/x86_64/updateinfo | 935 kB 00:00
(2/6): base/7/x86_64/group_gz | 166 kB 00:00
(3/6): extras/7/x86_64/primary_db | 154 kB 00:00
(4/6): updates/7/x86_64/primary_db | 1.3 MB 00:00
(5/6): epel/x86_64/primary | 3.6 MB 00:00
(6/6): base/7/x86_64/primary_db | 6.0 MB 00:01
Loading mirror speeds from cached hostfile
* base: mirrors.cn99.com
* epel: mirrors.aliyun.com
* extras: mirrors.163.com
* updates: mirrors.163.com
epel 12738/12738
Package epel-release-7-11.noarch already installed and latest version
Resolving Dependencies
–> Running transaction check
—> Package epel-rpm-macros.noarch 0:7-19 will be installed
–> Processing Dependency: python2-rpm-macros for package: epel-rpm-macros-7-19.noarch
–> Processing Dependency: python-srpm-macros for package: epel-rpm-macros-7-19.noarch
–> Processing Dependency: python-rpm-macros for package: epel-rpm-macros-7-19.noarch
–> Running transaction check
—> Package python-rpm-macros.noarch 0:3-22.el7 will be installed
—> Package python-srpm-macros.noarch 0:3-22.el7 will be installed
—> Package python2-rpm-macros.noarch 0:3-22.el7 will be installed
–> Finished Dependency Resolution

Dependencies Resolved

================================================================================
Package Arch Version Repository Size
================================================================================
Installing:
epel-rpm-macros noarch 7-19 epel 13 k
Installing for dependencies:
python-rpm-macros noarch 3-22.el7 epel 7.5 k
python-srpm-macros noarch 3-22.el7 epel 7.0 k
python2-rpm-macros noarch 3-22.el7 epel 6.3 k

Transaction Summary
================================================================================
Install 1 Package (+3 Dependent packages)

Total download size: 34 k
Installed size: 29 k
Downloading packages:
(1/4): epel-rpm-macros-7-19.noarch.rpm | 13 kB 00:00
(2/4): python-rpm-macros-3-22.el7.noarch.rpm | 7.5 kB 00:00
(3/4): python-srpm-macros-3-22.el7.noarch.rpm | 7.0 kB 00:00
(4/4): python2-rpm-macros-3-22.el7.noarch.rpm | 6.3 kB 00:00
——————————————————————————–
Total 48 kB/s | 34 kB 00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : python-srpm-macros-3-22.el7.noarch 1/4
Installing : python-rpm-macros-3-22.el7.noarch 2/4
Installing : python2-rpm-macros-3-22.el7.noarch 3/4
Installing : epel-rpm-macros-7-19.noarch 4/4
Verifying : epel-rpm-macros-7-19.noarch 1/4
Verifying : python-srpm-macros-3-22.el7.noarch 2/4
Verifying : python-rpm-macros-3-22.el7.noarch 3/4
Verifying : python2-rpm-macros-3-22.el7.noarch 4/4

Installed:
epel-rpm-macros.noarch 0:7-19

Dependency Installed:
python-rpm-macros.noarch 0:3-22.el7 python-srpm-macros.noarch 0:3-22.el7
python2-rpm-macros.noarch 0:3-22.el7

Complete!
[root@ftpserver ~]# yum repolist
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.cn99.com
* epel: mirrors.aliyun.com
* extras: mirrors.163.com
* updates: mirrors.163.com
repo id repo name status
base/7/x86_64 CentOS-7 – Base 10,019
epel/x86_64 Extra Packages for Enterprise Linux 7 – x86_64 12,738
extras/7/x86_64 CentOS-7 – Extras 314
updates/7/x86_64 CentOS-7 – Updates 598
repolist: 23,669

2、除此之外,还需要安装一个webtatic源用来安装php
[root@ftpserver ~]# rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
Retrieving https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
warning: /var/tmp/rpm-tmp.NgHqYF: Header V4 RSA/SHA1 Signature, key ID 62e74ca5: NOKEY
Preparing… ################################# [100%]
Updating / installing…
1:webtatic-release-7-3 ################################# [100%]
[root@ftpserver ~]# yum repolist
Loaded plugins: fastestmirror
webtatic | 3.6 kB 00:00
(1/2): webtatic/x86_64/group_gz | 448 B 00:01
(2/2): webtatic/x86_64/primary_db | 424 kB 00:02
Loading mirror speeds from cached hostfile
* base: mirrors.cqu.edu.cn
* epel: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
* webtatic: uk.repo.webtatic.com
repo id repo name status
base/7/x86_64 CentOS-7 – Base 10,019
epel/x86_64 Extra Packages for Enterprise Linux 7 – x86_64 12,738
extras/7/x86_64 CentOS-7 – Extras 314
updates/7/x86_64 CentOS-7 – Updates 598
webtatic/x86_64 Webtatic Repository EL7 – x86_64 1,305
repolist: 24,974

3、安装php环境
(注意,截至到我写这个教程之前,php-72w-mcrypt还找到合适的Yum源,所以只好安装php-71w系列,实际上php-72w已经出来了)
yum -y install php71w-fpm php71w-cli php71w-gd php71w-mcrypt php71w-pear php71w-xml php71w-mbstring php71w-pdo php71w-json php71w-pecl-apcu php71w-pecl-apcu-devel
代码如下
[root@fencatn ~]# yum -y install php71w-fpm php71w-cli php71w-gd php71w-mcrypt php71w-pear php71w-xml php71w-mbstring php71w-pdo php71w-json php71w-pecl-apcu php71w-pecl-apcu-devel
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.cqu.edu.cn
* epel: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
* webtatic: uk.repo.webtatic.com
Resolving Dependencies
–> Running transaction check
—> Package php71w-cli.x86_64 0:7.1.24-1.w7 will be installed
—> Package php71w-common.x86_64 0:7.1.24-1.w7 will be installed
—> Package php71w-fpm.x86_64 0:7.1.24-1.w7 will be installed
—> Package php71w-gd.x86_64 0:7.1.24-1.w7 will be installed
—> Package php71w-mbstring.x86_64 0:7.1.24-1.w7 will be installed
—> Package php71w-mcrypt.x86_64 0:7.1.24-1.w7 will be installed
–> Processing Dependency: libmcrypt.so.4()(64bit) for package: php71w-mcrypt-7.1.24-1.w7.x86_64
–> Processing Dependency: libltdl.so.7()(64bit) for package: php71w-mcrypt-7.1.24-1.w7.x86_64
—> Package php71w-pdo.x86_64 0:7.1.24-1.w7 will be installed
—> Package php71w-pear.noarch 1:1.10.4-1.w7 will be installed
–> Processing Dependency: php71w-posix for package: 1:php71w-pear-1.10.4-1.w7.noarch
—> Package php71w-pecl-apcu.x86_64 0:5.1.9-1.w7 will be installed
—> Package php71w-pecl-apcu-devel.x86_64 0:5.1.9-1.w7 will be installed
–> Processing Dependency: php-devel for package: php71w-pecl-apcu-devel-5.1.9-1.w7.x86_64
—> Package php71w-xml.x86_64 0:7.1.24-1.w7 will be installed
–> Running transaction check
—> Package libmcrypt.x86_64 0:2.5.8-13.el7 will be installed
—> Package libtool-ltdl.x86_64 0:2.4.2-22.el7_3 will be installed
—> Package php71w-devel.x86_64 0:7.1.24-1.w7 will be installed
—> Package php71w-process.x86_64 0:7.1.24-1.w7 will be installed
–> Finished Dependency Resolution

Dependencies Resolved

========================================================================================================================
Package Arch Version Repository Size
========================================================================================================================
Installing:
php71w-cli x86_64 7.1.24-1.w7 webtatic 3.0 M
php71w-common x86_64 7.1.24-1.w7 webtatic 1.2 M
php71w-fpm x86_64 7.1.24-1.w7 webtatic 1.5 M
php71w-gd x86_64 7.1.24-1.w7 webtatic 133 k
php71w-mbstring x86_64 7.1.24-1.w7 webtatic 543 k
php71w-mcrypt x86_64 7.1.24-1.w7 webtatic 26 k
php71w-pdo x86_64 7.1.24-1.w7 webtatic 90 k
php71w-pear noarch 1:1.10.4-1.w7 webtatic 340 k
php71w-pecl-apcu x86_64 5.1.9-1.w7 webtatic 81 k
php71w-pecl-apcu-devel x86_64 5.1.9-1.w7 webtatic 22 k
php71w-xml x86_64 7.1.24-1.w7 webtatic 127 k
Installing for dependencies:
libmcrypt x86_64 2.5.8-13.el7 epel 99 k
libtool-ltdl x86_64 2.4.2-22.el7_3 base 49 k
php71w-devel x86_64 7.1.24-1.w7 webtatic 2.6 M
php71w-process x86_64 7.1.24-1.w7 webtatic 39 k

Transaction Summary
========================================================================================================================
Install 11 Packages (+4 Dependent packages)

Total download size: 9.8 M
Installed size: 45 M
Downloading packages:
(1/15): libmcrypt-2.5.8-13.el7.x86_64.rpm | 99 kB 00:00:00
(2/15): libtool-ltdl-2.4.2-22.el7_3.x86_64.rpm | 49 kB 00:00:00
(3/15): php71w-common-7.1.24-1.w7.x86_64.rpm | 1.2 MB 00:00:02
(4/15): php71w-cli-7.1.24-1.w7.x86_64.rpm | 3.0 MB 00:00:02
(5/15): php71w-fpm-7.1.24-1.w7.x86_64.rpm | 1.5 MB 00:00:00
(6/15): php71w-gd-7.1.24-1.w7.x86_64.rpm | 133 kB 00:00:00
(7/15): php71w-mbstring-7.1.24-1.w7.x86_64.rpm | 543 kB 00:00:00
(8/15): php71w-mcrypt-7.1.24-1.w7.x86_64.rpm | 26 kB 00:00:00
(9/15): php71w-pdo-7.1.24-1.w7.x86_64.rpm | 90 kB 00:00:00
(10/15): php71w-pear-1.10.4-1.w7.noarch.rpm | 340 kB 00:00:00
(11/15): php71w-pecl-apcu-5.1.9-1.w7.x86_64.rpm | 81 kB 00:00:00
(12/15): php71w-process-7.1.24-1.w7.x86_64.rpm | 39 kB 00:00:00
(13/15): php71w-pecl-apcu-devel-5.1.9-1.w7.x86_64.rpm | 22 kB 00:00:00
(14/15): php71w-xml-7.1.24-1.w7.x86_64.rpm | 127 kB 00:00:00
(15/15): php71w-devel-7.1.24-1.w7.x86_64.rpm | 2.6 MB 00:00:17
————————————————————————————————————————
Total 578 kB/s | 9.8 MB 00:00:17
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : php71w-common-7.1.24-1.w7.x86_64 1/15
Installing : php71w-cli-7.1.24-1.w7.x86_64 2/15
Installing : php71w-devel-7.1.24-1.w7.x86_64 3/15
Installing : php71w-xml-7.1.24-1.w7.x86_64 4/15
Installing : php71w-process-7.1.24-1.w7.x86_64 5/15
Installing : 1:php71w-pear-1.10.4-1.w7.noarch 6/15
Installing : php71w-pecl-apcu-5.1.9-1.w7.x86_64 7/15
Installing : libmcrypt-2.5.8-13.el7.x86_64 8/15
Installing : libtool-ltdl-2.4.2-22.el7_3.x86_64 9/15
Installing : php71w-mcrypt-7.1.24-1.w7.x86_64 10/15
Installing : php71w-pecl-apcu-devel-5.1.9-1.w7.x86_64 11/15
Installing : php71w-gd-7.1.24-1.w7.x86_64 12/15
Installing : php71w-fpm-7.1.24-1.w7.x86_64 13/15
Installing : php71w-mbstring-7.1.24-1.w7.x86_64 14/15
Installing : php71w-pdo-7.1.24-1.w7.x86_64 15/15
Verifying : php71w-cli-7.1.24-1.w7.x86_64 1/15
Verifying : php71w-gd-7.1.24-1.w7.x86_64 2/15
Verifying : php71w-xml-7.1.24-1.w7.x86_64 3/15
Verifying : php71w-devel-7.1.24-1.w7.x86_64 4/15
Verifying : php71w-mcrypt-7.1.24-1.w7.x86_64 5/15
Verifying : 1:php71w-pear-1.10.4-1.w7.noarch 6/15
Verifying : php71w-fpm-7.1.24-1.w7.x86_64 7/15
Verifying : php71w-mbstring-7.1.24-1.w7.x86_64 8/15
Verifying : libtool-ltdl-2.4.2-22.el7_3.x86_64 9/15
Verifying : php71w-common-7.1.24-1.w7.x86_64 10/15
Verifying : php71w-process-7.1.24-1.w7.x86_64 11/15
Verifying : php71w-pecl-apcu-5.1.9-1.w7.x86_64 12/15
Verifying : libmcrypt-2.5.8-13.el7.x86_64 13/15
Verifying : php71w-pecl-apcu-devel-5.1.9-1.w7.x86_64 14/15
Verifying : php71w-pdo-7.1.24-1.w7.x86_64 15/15

Installed:
php71w-cli.x86_64 0:7.1.24-1.w7 php71w-common.x86_64 0:7.1.24-1.w7 php71w-fpm.x86_64 0:7.1.24-1.w7
php71w-gd.x86_64 0:7.1.24-1.w7 php71w-mbstring.x86_64 0:7.1.24-1.w7 php71w-mcrypt.x86_64 0:7.1.24-1.w7
php71w-pdo.x86_64 0:7.1.24-1.w7 php71w-pear.noarch 1:1.10.4-1.w7 php71w-pecl-apcu.x86_64 0:5.1.9-1.w7
php71w-pecl-apcu-devel.x86_64 0:5.1.9-1.w7 php71w-xml.x86_64 0:7.1.24-1.w7

Dependency Installed:
libmcrypt.x86_64 0:2.5.8-13.el7 libtool-ltdl.x86_64 0:2.4.2-22.el7_3 php71w-devel.x86_64 0:7.1.24-1.w7
php71w-process.x86_64 0:7.1.24-1.w7

Complete!

还有一个php-mysql忘了装了,这里补上
[root@fencatn ~]# yum install -y php71w-mysql
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.cqu.edu.cn
* epel: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
* webtatic: uk.repo.webtatic.com
Resolving Dependencies
–> Running transaction check
—> Package php71w-mysql.x86_64 0:7.1.24-1.w7 will be installed
–> Finished Dependency Resolution

Dependencies Resolved

==================================================================================================================================
Package Arch Version Repository Size
==================================================================================================================================
Installing:
php71w-mysql x86_64 7.1.24-1.w7 webtatic 82 k

Transaction Summary
==================================================================================================================================
Install 1 Package

Total download size: 82 k
Installed size: 347 k
Downloading packages:
php71w-mysql-7.1.24-1.w7.x86_64.rpm | 82 kB 00:00:01
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : php71w-mysql-7.1.24-1.w7.x86_64 1/1
Verifying : php71w-mysql-7.1.24-1.w7.x86_64 1/1

Installed:
php71w-mysql.x86_64 0:7.1.24-1.w7

Complete!

检查并确认php版本号
[root@fencatn ~]# php -v
PHP 7.1.24 (cli) (built: Nov 11 2018 08:03:49) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2018 Zend Technologies

4、安装nginx(不建议源码安装,后期维护麻烦,LNMP版本更新很快)
[root@ftpserver ~]# yum install -y nginx
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.cqu.edu.cn
* epel: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
Resolving Dependencies
–> Running transaction check
—> Package nginx.x86_64 1:1.12.2-2.el7 will be installed
–> Processing Dependency: nginx-filesystem = 1:1.12.2-2.el7 for package: 1:nginx-1.12.2-2.el7.x86_64
–> Processing Dependency: nginx-all-modules = 1:1.12.2-2.el7 for package: 1:nginx-1.12.2-2.el7.x86_64
–> Processing Dependency: nginx-filesystem for package: 1:nginx-1.12.2-2.el7.x86_64
–> Processing Dependency: libprofiler.so.0()(64bit) for package: 1:nginx-1.12.2-2.el7.x86_64
–> Running transaction check
—> Package gperftools-libs.x86_64 0:2.6.1-1.el7 will be installed
—> Package nginx-all-modules.noarch 1:1.12.2-2.el7 will be installed
–> Processing Dependency: nginx-mod-stream = 1:1.12.2-2.el7 for package: 1:nginx-all-modules-1.12.2-2.el7.noarch
–> Processing Dependency: nginx-mod-mail = 1:1.12.2-2.el7 for package: 1:nginx-all-modules-1.12.2-2.el7.noarch
–> Processing Dependency: nginx-mod-http-xslt-filter = 1:1.12.2-2.el7 for package: 1:nginx-all-modules-1.12.2-2.el7.noarch
–> Processing Dependency: nginx-mod-http-perl = 1:1.12.2-2.el7 for package: 1:nginx-all-modules-1.12.2-2.el7.noarch
–> Processing Dependency: nginx-mod-http-image-filter = 1:1.12.2-2.el7 for package: 1:nginx-all-modules-1.12.2-2.el7.noarch
–> Processing Dependency: nginx-mod-http-geoip = 1:1.12.2-2.el7 for package: 1:nginx-all-modules-1.12.2-2.el7.noarch
—> Package nginx-filesystem.noarch 1:1.12.2-2.el7 will be installed
–> Running transaction check
—> Package nginx-mod-http-geoip.x86_64 1:1.12.2-2.el7 will be installed
—> Package nginx-mod-http-image-filter.x86_64 1:1.12.2-2.el7 will be installed
–> Processing Dependency: gd for package: 1:nginx-mod-http-image-filter-1.12.2-2.el7.x86_64
–> Processing Dependency: libgd.so.2()(64bit) for package: 1:nginx-mod-http-image-filter-1.12.2-2.el7.x86_64
—> Package nginx-mod-http-perl.x86_64 1:1.12.2-2.el7 will be installed
—> Package nginx-mod-http-xslt-filter.x86_64 1:1.12.2-2.el7 will be installed
—> Package nginx-mod-mail.x86_64 1:1.12.2-2.el7 will be installed
—> Package nginx-mod-stream.x86_64 1:1.12.2-2.el7 will be installed
–> Running transaction check
—> Package gd.x86_64 0:2.0.35-26.el7 will be installed
–> Processing Dependency: libpng15.so.15(PNG15_0)(64bit) for package: gd-2.0.35-26.el7.x86_64
–> Processing Dependency: libpng15.so.15()(64bit) for package: gd-2.0.35-26.el7.x86_64
–> Processing Dependency: libfontconfig.so.1()(64bit) for package: gd-2.0.35-26.el7.x86_64
–> Processing Dependency: libXpm.so.4()(64bit) for package: gd-2.0.35-26.el7.x86_64
–> Processing Dependency: libX11.so.6()(64bit) for package: gd-2.0.35-26.el7.x86_64
–> Running transaction check
—> Package fontconfig.x86_64 0:2.13.0-4.3.el7 will be installed
–> Processing Dependency: freetype >= 2.8-7 for package: fontconfig-2.13.0-4.3.el7.x86_64
–> Processing Dependency: fontpackages-filesystem for package: fontconfig-2.13.0-4.3.el7.x86_64
–> Processing Dependency: dejavu-sans-fonts for package: fontconfig-2.13.0-4.3.el7.x86_64
—> Package libX11.x86_64 0:1.6.5-2.el7 will be installed
–> Processing Dependency: libX11-common >= 1.6.5-2.el7 for package: libX11-1.6.5-2.el7.x86_64
–> Processing Dependency: libxcb.so.1()(64bit) for package: libX11-1.6.5-2.el7.x86_64
—> Package libXpm.x86_64 0:3.5.12-1.el7 will be installed
—> Package libpng.x86_64 2:1.5.13-7.el7_2 will be installed
–> Running transaction check
—> Package dejavu-sans-fonts.noarch 0:2.33-6.el7 will be installed
–> Processing Dependency: dejavu-fonts-common = 2.33-6.el7 for package: dejavu-sans-fonts-2.33-6.el7.noarch
—> Package fontpackages-filesystem.noarch 0:1.44-8.el7 will be installed
—> Package freetype.x86_64 0:2.4.11-15.el7 will be updated
—> Package freetype.x86_64 0:2.8-12.el7 will be an update
—> Package libX11-common.noarch 0:1.6.5-2.el7 will be installed
—> Package libxcb.x86_64 0:1.13-1.el7 will be installed
–> Processing Dependency: libXau.so.6()(64bit) for package: libxcb-1.13-1.el7.x86_64
–> Running transaction check
—> Package dejavu-fonts-common.noarch 0:2.33-6.el7 will be installed
—> Package libXau.x86_64 0:1.0.8-2.1.el7 will be installed
–> Finished Dependency Resolution

Dependencies Resolved

================================================================================
Package Arch Version Repository
Size
================================================================================
Installing:
nginx x86_64 1:1.12.2-2.el7 epel 530 k
Installing for dependencies:
dejavu-fonts-common noarch 2.33-6.el7 base 64 k
dejavu-sans-fonts noarch 2.33-6.el7 base 1.4 M
fontconfig x86_64 2.13.0-4.3.el7 base 254 k
fontpackages-filesystem noarch 1.44-8.el7 base 9.9 k
gd x86_64 2.0.35-26.el7 base 146 k
gperftools-libs x86_64 2.6.1-1.el7 base 272 k
libX11 x86_64 1.6.5-2.el7 base 606 k
libX11-common noarch 1.6.5-2.el7 base 164 k
libXau x86_64 1.0.8-2.1.el7 base 29 k
libXpm x86_64 3.5.12-1.el7 base 55 k
libpng x86_64 2:1.5.13-7.el7_2 base 213 k
libxcb x86_64 1.13-1.el7 base 214 k
nginx-all-modules noarch 1:1.12.2-2.el7 epel 16 k
nginx-filesystem noarch 1:1.12.2-2.el7 epel 17 k
nginx-mod-http-geoip x86_64 1:1.12.2-2.el7 epel 23 k
nginx-mod-http-image-filter x86_64 1:1.12.2-2.el7 epel 26 k
nginx-mod-http-perl x86_64 1:1.12.2-2.el7 epel 36 k
nginx-mod-http-xslt-filter x86_64 1:1.12.2-2.el7 epel 26 k
nginx-mod-mail x86_64 1:1.12.2-2.el7 epel 54 k
nginx-mod-stream x86_64 1:1.12.2-2.el7 epel 76 k
Updating for dependencies:
freetype x86_64 2.8-12.el7 base 380 k

Transaction Summary
================================================================================
Install 1 Package (+20 Dependent packages)
Upgrade ( 1 Dependent package)

Total download size: 4.6 M
Downloading packages:
Delta RPMs disabled because /usr/bin/applydeltarpm not installed.
(1/22): dejavu-fonts-common-2.33-6.el7.noarch.rpm | 64 kB 00:00
(2/22): fontconfig-2.13.0-4.3.el7.x86_64.rpm | 254 kB 00:00
(3/22): fontpackages-filesystem-1.44-8.el7.noarch.rpm | 9.9 kB 00:00
(4/22): dejavu-sans-fonts-2.33-6.el7.noarch.rpm | 1.4 MB 00:00
(5/22): gd-2.0.35-26.el7.x86_64.rpm | 146 kB 00:00
(6/22): freetype-2.8-12.el7.x86_64.rpm | 380 kB 00:00
(7/22): gperftools-libs-2.6.1-1.el7.x86_64.rpm | 272 kB 00:00
(8/22): libX11-1.6.5-2.el7.x86_64.rpm | 606 kB 00:00
(9/22): libX11-common-1.6.5-2.el7.noarch.rpm | 164 kB 00:00
(10/22): libXau-1.0.8-2.1.el7.x86_64.rpm | 29 kB 00:00
(11/22): libXpm-3.5.12-1.el7.x86_64.rpm | 55 kB 00:00
(12/22): libpng-1.5.13-7.el7_2.x86_64.rpm | 213 kB 00:00
(13/22): libxcb-1.13-1.el7.x86_64.rpm | 214 kB 00:00
(14/22): nginx-1.12.2-2.el7.x86_64.rpm | 530 kB 00:00
(15/22): nginx-filesystem-1.12.2-2.el7.noarch.rpm | 17 kB 00:00
(16/22): nginx-all-modules-1.12.2-2.el7.noarch.rpm | 16 kB 00:00
(17/22): nginx-mod-http-geoip-1.12.2-2.el7.x86_64.rpm | 23 kB 00:00
(18/22): nginx-mod-http-image-filter-1.12.2-2.el7.x86_64.r | 26 kB 00:00
(19/22): nginx-mod-http-perl-1.12.2-2.el7.x86_64.rpm | 36 kB 00:00
(20/22): nginx-mod-http-xslt-filter-1.12.2-2.el7.x86_64.rp | 26 kB 00:00
(21/22): nginx-mod-mail-1.12.2-2.el7.x86_64.rpm | 54 kB 00:00
(22/22): nginx-mod-stream-1.12.2-2.el7.x86_64.rpm | 76 kB 00:00
——————————————————————————–
Total 2.7 MB/s | 4.6 MB 00:01
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : fontpackages-filesystem-1.44-8.el7.noarch 1/23
Installing : 2:libpng-1.5.13-7.el7_2.x86_64 2/23
Updating : freetype-2.8-12.el7.x86_64 3/23
Installing : dejavu-fonts-common-2.33-6.el7.noarch 4/23
Installing : dejavu-sans-fonts-2.33-6.el7.noarch 5/23
Installing : fontconfig-2.13.0-4.3.el7.x86_64 6/23
Installing : libX11-common-1.6.5-2.el7.noarch 7/23
Installing : gperftools-libs-2.6.1-1.el7.x86_64 8/23
Installing : libXau-1.0.8-2.1.el7.x86_64 9/23
Installing : libxcb-1.13-1.el7.x86_64 10/23
Installing : libX11-1.6.5-2.el7.x86_64 11/23
Installing : libXpm-3.5.12-1.el7.x86_64 12/23
Installing : gd-2.0.35-26.el7.x86_64 13/23
Installing : 1:nginx-filesystem-1.12.2-2.el7.noarch 14/23
Installing : 1:nginx-mod-http-xslt-filter-1.12.2-2.el7.x86_64 15/23
Installing : 1:nginx-mod-http-geoip-1.12.2-2.el7.x86_64 16/23
Installing : 1:nginx-mod-stream-1.12.2-2.el7.x86_64 17/23
Installing : 1:nginx-mod-mail-1.12.2-2.el7.x86_64 18/23
Installing : 1:nginx-mod-http-perl-1.12.2-2.el7.x86_64 19/23
Installing : 1:nginx-1.12.2-2.el7.x86_64 20/23
Installing : 1:nginx-mod-http-image-filter-1.12.2-2.el7.x86_64 21/23
Installing : 1:nginx-all-modules-1.12.2-2.el7.noarch 22/23
Cleanup : freetype-2.4.11-15.el7.x86_64 23/23
Verifying : fontconfig-2.13.0-4.3.el7.x86_64 1/23
Verifying : 1:nginx-mod-http-xslt-filter-1.12.2-2.el7.x86_64 2/23
Verifying : 1:nginx-mod-http-geoip-1.12.2-2.el7.x86_64 3/23
Verifying : 1:nginx-1.12.2-2.el7.x86_64 4/23
Verifying : 2:libpng-1.5.13-7.el7_2.x86_64 5/23
Verifying : fontpackages-filesystem-1.44-8.el7.noarch 6/23
Verifying : 1:nginx-mod-stream-1.12.2-2.el7.x86_64 7/23
Verifying : freetype-2.8-12.el7.x86_64 8/23
Verifying : dejavu-fonts-common-2.33-6.el7.noarch 9/23
Verifying : 1:nginx-all-modules-1.12.2-2.el7.noarch 10/23
Verifying : libxcb-1.13-1.el7.x86_64 11/23
Verifying : libXpm-3.5.12-1.el7.x86_64 12/23
Verifying : 1:nginx-filesystem-1.12.2-2.el7.noarch 13/23
Verifying : libX11-1.6.5-2.el7.x86_64 14/23
Verifying : dejavu-sans-fonts-2.33-6.el7.noarch 15/23
Verifying : 1:nginx-mod-mail-1.12.2-2.el7.x86_64 16/23
Verifying : gd-2.0.35-26.el7.x86_64 17/23
Verifying : libXau-1.0.8-2.1.el7.x86_64 18/23
Verifying : gperftools-libs-2.6.1-1.el7.x86_64 19/23
Verifying : libX11-common-1.6.5-2.el7.noarch 20/23
Verifying : 1:nginx-mod-http-perl-1.12.2-2.el7.x86_64 21/23
Verifying : 1:nginx-mod-http-image-filter-1.12.2-2.el7.x86_64 22/23
Verifying : freetype-2.4.11-15.el7.x86_64 23/23

Installed:
nginx.x86_64 1:1.12.2-2.el7

Dependency Installed:
dejavu-fonts-common.noarch 0:2.33-6.el7
dejavu-sans-fonts.noarch 0:2.33-6.el7
fontconfig.x86_64 0:2.13.0-4.3.el7
fontpackages-filesystem.noarch 0:1.44-8.el7
gd.x86_64 0:2.0.35-26.el7
gperftools-libs.x86_64 0:2.6.1-1.el7
libX11.x86_64 0:1.6.5-2.el7
libX11-common.noarch 0:1.6.5-2.el7
libXau.x86_64 0:1.0.8-2.1.el7
libXpm.x86_64 0:3.5.12-1.el7
libpng.x86_64 2:1.5.13-7.el7_2
libxcb.x86_64 0:1.13-1.el7
nginx-all-modules.noarch 1:1.12.2-2.el7
nginx-filesystem.noarch 1:1.12.2-2.el7
nginx-mod-http-geoip.x86_64 1:1.12.2-2.el7
nginx-mod-http-image-filter.x86_64 1:1.12.2-2.el7
nginx-mod-http-perl.x86_64 1:1.12.2-2.el7
nginx-mod-http-xslt-filter.x86_64 1:1.12.2-2.el7
nginx-mod-mail.x86_64 1:1.12.2-2.el7
nginx-mod-stream.x86_64 1:1.12.2-2.el7

Dependency Updated:
freetype.x86_64 0:2.8-12.el7

Complete!

5、配置php-fpm
修改用户名和组都为nginx
7 ; RPM: apache Choosed to be able to access some dir as httpd
8 user = nginx
9 ; RPM: Keep a group allowed to write in log dir.
10 group = nginx
确认监听端口为9000
22 listen = 127.0.0.1:9000
去掉注释
366 env[HOSTNAME] = $HOSTNAME
367 env[PATH] = /usr/local/bin:/usr/bin:/bin
368 env[TMP] = /tmp
369 env[TMPDIR] = /tmp
370 env[TEMP] = /tmp

6、配置session目录,并授权给nginx
[root@fencatn ~]# mkdir -p /var/lib/php/session
[root@fencatn ~]# chown nginx.nginx /var/lib/php/session/
[root@fencatn ~]# ll -d /var/lib/php/session/
drwxr-xr-x 2 nginx nginx 6 12月 7 21:54 /var/lib/php/session/

7、启动nginx和php-fpm服务,并设置为开机自启。
代码如下
[root@fencatn ~]# systemctl restart nginx
[root@fencatn ~]# systemctl restart php-fpm
[root@fencatn ~]# systemctl enable nginx
Created symlink from /etc/systemd/system/multi-user.target.wants/nginx.service to /usr/lib/systemd/system/nginx.service.
[root@fencatn ~]# systemctl enable php-fpm
Created symlink from /etc/systemd/system/multi-user.target.wants/php-fpm.service to /usr/lib/systemd/system/php-fpm.service.

二、配置数据库环境
1、安装mariadb和mariadb-server作为Nextcloud的数据库环境
[root@fencatn ~]# yum install -y mariadb mariadb-server
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.cqu.edu.cn
* epel: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
* webtatic: uk.repo.webtatic.com
Resolving Dependencies
–> Running transaction check
—> Package mariadb.x86_64 1:5.5.60-1.el7_5 will be installed
–> Processing Dependency: mariadb-libs(x86-64) = 1:5.5.60-1.el7_5 for package: 1:mariadb-5.5.60-1.el7_5.x86_64
—> Package mariadb-server.x86_64 1:5.5.60-1.el7_5 will be installed
–> Processing Dependency: perl-DBI for package: 1:mariadb-server-5.5.60-1.el7_5.x86_64
–> Processing Dependency: perl-DBD-MySQL for package: 1:mariadb-server-5.5.60-1.el7_5.x86_64
–> Processing Dependency: perl(DBI) for package: 1:mariadb-server-5.5.60-1.el7_5.x86_64
–> Running transaction check
—> Package mariadb-libs.x86_64 1:5.5.56-2.el7 will be updated
—> Package mariadb-libs.x86_64 1:5.5.60-1.el7_5 will be an update
—> Package perl-DBD-MySQL.x86_64 0:4.023-6.el7 will be installed
—> Package perl-DBI.x86_64 0:1.627-4.el7 will be installed
–> Processing Dependency: perl(RPC::PlServer) >= 0.2001 for package: perl-DBI-1.627-4.el7.x86_64
–> Processing Dependency: perl(RPC::PlClient) >= 0.2000 for package: perl-DBI-1.627-4.el7.x86_64
–> Running transaction check
—> Package perl-PlRPC.noarch 0:0.2020-14.el7 will be installed
–> Processing Dependency: perl(Net::Daemon) >= 0.13 for package: perl-PlRPC-0.2020-14.el7.noarch
–> Processing Dependency: perl(Net::Daemon::Test) for package: perl-PlRPC-0.2020-14.el7.noarch
–> Processing Dependency: perl(Net::Daemon::Log) for package: perl-PlRPC-0.2020-14.el7.noarch
–> Processing Dependency: perl(Compress::Zlib) for package: perl-PlRPC-0.2020-14.el7.noarch
–> Running transaction check
—> Package perl-IO-Compress.noarch 0:2.061-2.el7 will be installed
–> Processing Dependency: perl(Compress::Raw::Zlib) >= 2.061 for package: perl-IO-Compress-2.061-2.el7.noarch
–> Processing Dependency: perl(Compress::Raw::Bzip2) >= 2.061 for package: perl-IO-Compress-2.061-2.el7.noarch
—> Package perl-Net-Daemon.noarch 0:0.48-5.el7 will be installed
–> Running transaction check
—> Package perl-Compress-Raw-Bzip2.x86_64 0:2.061-3.el7 will be installed
—> Package perl-Compress-Raw-Zlib.x86_64 1:2.061-4.el7 will be installed
–> Finished Dependency Resolution

Dependencies Resolved

========================================================================================================================
Package Arch Version Repository Size
========================================================================================================================
Installing:
mariadb x86_64 1:5.5.60-1.el7_5 base 8.9 M
mariadb-server x86_64 1:5.5.60-1.el7_5 base 11 M
Installing for dependencies:
perl-Compress-Raw-Bzip2 x86_64 2.061-3.el7 base 32 k
perl-Compress-Raw-Zlib x86_64 1:2.061-4.el7 base 57 k
perl-DBD-MySQL x86_64 4.023-6.el7 base 140 k
perl-DBI x86_64 1.627-4.el7 base 802 k
perl-IO-Compress noarch 2.061-2.el7 base 260 k
perl-Net-Daemon noarch 0.48-5.el7 base 51 k
perl-PlRPC noarch 0.2020-14.el7 base 36 k
Updating for dependencies:
mariadb-libs x86_64 1:5.5.60-1.el7_5 base 758 k

Transaction Summary
========================================================================================================================
Install 2 Packages (+7 Dependent packages)
Upgrade ( 1 Dependent package)

Total download size: 22 M
Downloading packages:
Delta RPMs disabled because /usr/bin/applydeltarpm not installed.
(1/10): mariadb-libs-5.5.60-1.el7_5.x86_64.rpm | 758 kB 00:00:00
(2/10): mariadb-5.5.60-1.el7_5.x86_64.rpm | 8.9 MB 00:00:01
(3/10): perl-Compress-Raw-Bzip2-2.061-3.el7.x86_64.rpm | 32 kB 00:00:00
(4/10): perl-Compress-Raw-Zlib-2.061-4.el7.x86_64.rpm | 57 kB 00:00:00
(5/10): perl-DBD-MySQL-4.023-6.el7.x86_64.rpm | 140 kB 00:00:00
(6/10): perl-DBI-1.627-4.el7.x86_64.rpm | 802 kB 00:00:00
(7/10): perl-IO-Compress-2.061-2.el7.noarch.rpm | 260 kB 00:00:00
(8/10): perl-Net-Daemon-0.48-5.el7.noarch.rpm | 51 kB 00:00:00
(9/10): perl-PlRPC-0.2020-14.el7.noarch.rpm | 36 kB 00:00:00
(10/10): mariadb-server-5.5.60-1.el7_5.x86_64.rpm | 11 MB 00:00:02
————————————————————————————————————————
Total 6.8 MB/s | 22 MB 00:00:03
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Updating : 1:mariadb-libs-5.5.60-1.el7_5.x86_64 1/11
Installing : 1:mariadb-5.5.60-1.el7_5.x86_64 2/11
Installing : 1:perl-Compress-Raw-Zlib-2.061-4.el7.x86_64 3/11
Installing : perl-Net-Daemon-0.48-5.el7.noarch 4/11
Installing : perl-Compress-Raw-Bzip2-2.061-3.el7.x86_64 5/11
Installing : perl-IO-Compress-2.061-2.el7.noarch 6/11
Installing : perl-PlRPC-0.2020-14.el7.noarch 7/11
Installing : perl-DBI-1.627-4.el7.x86_64 8/11
Installing : perl-DBD-MySQL-4.023-6.el7.x86_64 9/11
Installing : 1:mariadb-server-5.5.60-1.el7_5.x86_64 10/11
Cleanup : 1:mariadb-libs-5.5.56-2.el7.x86_64 11/11
Verifying : 1:mariadb-server-5.5.60-1.el7_5.x86_64 1/11
Verifying : perl-Compress-Raw-Bzip2-2.061-3.el7.x86_64 2/11
Verifying : perl-Net-Daemon-0.48-5.el7.noarch 3/11
Verifying : perl-DBD-MySQL-4.023-6.el7.x86_64 4/11
Verifying : 1:mariadb-libs-5.5.60-1.el7_5.x86_64 5/11
Verifying : 1:perl-Compress-Raw-Zlib-2.061-4.el7.x86_64 6/11
Verifying : 1:mariadb-5.5.60-1.el7_5.x86_64 7/11
Verifying : perl-DBI-1.627-4.el7.x86_64 8/11
Verifying : perl-IO-Compress-2.061-2.el7.noarch 9/11
Verifying : perl-PlRPC-0.2020-14.el7.noarch 10/11
Verifying : 1:mariadb-libs-5.5.56-2.el7.x86_64 11/11

Installed:
mariadb.x86_64 1:5.5.60-1.el7_5 mariadb-server.x86_64 1:5.5.60-1.el7_5

Dependency Installed:
perl-Compress-Raw-Bzip2.x86_64 0:2.061-3.el7 perl-Compress-Raw-Zlib.x86_64 1:2.061-4.el7
perl-DBD-MySQL.x86_64 0:4.023-6.el7 perl-DBI.x86_64 0:1.627-4.el7
perl-IO-Compress.noarch 0:2.061-2.el7 perl-Net-Daemon.noarch 0:0.48-5.el7
perl-PlRPC.noarch 0:0.2020-14.el7

Dependency Updated:
mariadb-libs.x86_64 1:5.5.60-1.el7_5

Complete!

2、重启mariadb,并设置为开机自启
[root@fencatn ~]# systemctl restart mariadb
[root@fencatn ~]# systemctl enable mariadb
Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.service.

3、初始化mariadb的安装
[root@fencatn ~]# mysql_secure_installation

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we’ll need the current
password for the root user. If you’ve just installed MariaDB, and
you haven’t set the root password yet, the password will be blank,
so you should just press enter here.

输入当前root用户密码,默认是空,直接按回车
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.

是否设置root密码,默认回车,选择是
Set root password? [Y/n]
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]
… Success!

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

是否禁止root远程登录,默认回车,选择是(看你自己的实际需求)
Disallow root login remotely? [Y/n]
… 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]
– 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]
… 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!

4、进入数据库,为nextcloud配置相应的库和帐号
[root@fencatn ~]# mysql -uroot -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 11
Server version: 5.5.60-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the current input statement.

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

我设置的库名叫nextcloud_fencatn,用户叫fencatn,密码是fencatn2018,你可以根据自己的需求设置
MariaDB [(none)]> grant all privileges on nextcloud_fencatn.* to fencatn@localhost identified by “fencatn2018”;
Query OK, 0 rows affected (0.00 sec)

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

MariaDB [(none)]> exit
Bye

三、生成自签名证书(因为nextcloud客户端强制要求HTTPS链接),你也可以自己购买商业证书
[root@fencatn ~]# mkdir -p /etc/nginx/cert
[root@fencatn ~]# cd /etc/nginx/cert
[root@fencatn cert]# pwd
/etc/nginx/cert
[root@fencatn cert]# openssl req -new -x509 -days 365 -nodes -out /etc/nginx/cert/nextcloud.crt -keyout /etc/nginx/cert/nextcloud.key
Generating a 2048 bit RSA private key
………………………………………………………………………………………………………………….+++
………………………….+++
writing new private key to ‘/etc/nginx/cert/nextcloud.key’
—–
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter ‘.’, the field will be left blank.
—–
国家
Country Name (2 letter code) [XX]:cn
省份
State or Province Name (full name) []:fencatn
地区
Locality Name (eg, city) [Default City]:fencatn
公司
Organization Name (eg, company) [Default Company Ltd]:fencatn
部门
Organizational Unit Name (eg, section) []:fencatn
CA主机
Common Name (eg, your name or your server’s hostname) []:fencatn
邮箱
Email Address []:[email protected]
证书授权为600,目录给700
[root@fencatn cert]# chmod 700 /etc/nginx/cert
[root@fencatn cert]# chmod 600 /etc/nginx/cert/*
[root@fencatn cert]# ll /etc/nginx/cert/*
-rw——- 1 root root 1419 12月 7 22:12 /etc/nginx/cert/nextcloud.crt
-rw——- 1 root root 1704 12月 7 22:12 /etc/nginx/cert/nextcloud.key
[root@fencatn cert]# ll -d /etc/nginx/cert/
drwx—— 2 root root 48 12月 7 22:12 /etc/nginx/cert/

四、下载安装Nextcloud
(到我写这个教程的时候,Nextcloud官网被墙了,很难打开,不管你怎么下载的,你自己想办法吧)
1、先安装下载、解压程序
[root@fencatn ~]# yum -y install wget unzip
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.cqu.edu.cn
* epel: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
* webtatic: uk.repo.webtatic.com
Resolving Dependencies
–> Running transaction check
—> Package unzip.x86_64 0:6.0-16.el7 will be updated
—> Package unzip.x86_64 0:6.0-19.el7 will be an update
—> Package wget.x86_64 0:1.14-18.el7 will be installed
–> Finished Dependency Resolution

Dependencies Resolved

========================================================================================================================
Package Arch Version Repository Size
========================================================================================================================
Installing:
wget x86_64 1.14-18.el7 base 547 k
Updating:
unzip x86_64 6.0-19.el7 base 170 k

Transaction Summary
========================================================================================================================
Install 1 Package
Upgrade 1 Package

Total download size: 717 k
Downloading packages:
Delta RPMs disabled because /usr/bin/applydeltarpm not installed.
(1/2): unzip-6.0-19.el7.x86_64.rpm | 170 kB 00:00:00
(2/2): wget-1.14-18.el7.x86_64.rpm | 547 kB 00:00:01
————————————————————————————————————————
Total 409 kB/s | 717 kB 00:00:01
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : wget-1.14-18.el7.x86_64 1/3
Updating : unzip-6.0-19.el7.x86_64 2/3
Cleanup : unzip-6.0-16.el7.x86_64 3/3
Verifying : unzip-6.0-19.el7.x86_64 1/3
Verifying : wget-1.14-18.el7.x86_64 2/3
Verifying : unzip-6.0-16.el7.x86_64 3/3

Installed:
wget.x86_64 0:1.14-18.el7

Updated:
unzip.x86_64 0:6.0-19.el7

Complete!

2、下载Nextcloud,我这里已经下载好了,你自己想办法吧
[root@fencatn ~]# cd /usr/local/src/
[root@fencatn src]# ll
total 65120
-rw-r–r– 1 root root 66680842 12月 8 01:51 nextcloud-14.0.4.zip

3、解压下载好的压缩包,并移动到web服务器目录
[root@fencatn src]# unzip nextcloud-14.0.4.zip
[root@fencatn src]# ls
nextcloud nextcloud-14.0.4.zip
[root@fencatn src]# mv nextcloud /usr/share/nginx/
[root@fencatn src]# ls /usr/share/nginx/
html modules nextcloud

4、进入nginx的web目录,并创建nextcloud的data目录,并把整个文件夹的用户和组都授权为nginx
(注意,我这里是把单独的一块硬盘挂在到data目录,你可以根据自己的实际需求来做)
[root@fencatn src]# cd /usr/share/nginx/
[root@fencatn html]# pwd
/usr/share/nginx
[root@fencatn html]# mkdir -p nextcloud/data/

我本机另外添加了一块sdb来做data目录
[root@fencatn html]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 465.8G 0 disk
├─sda1 8:1 0 10G 0 part /boot/efi
├─sda2 8:2 0 10G 0 part /boot
└─sda3 8:3 0 445.8G 0 part
├─centos-root 253:0 0 100G 0 lvm /
├─centos-swap 253:1 0 16G 0 lvm [SWAP]
└─centos-var 253:2 0 329.8G 0 lvm /var
sdb 8:16 0 465.8G 0 disk
└─sdb1 8:17 0 465.8G 0 part
挂载sdb1到/usr/share/nginx/html/nextcloud/data/
[root@fencatn html]# mount /dev/sdb1 /usr/share/nginx/nextcloud/data/
[root@fencatn html]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/centos-root 100G 76G 25G 76% /
devtmpfs 1.8G 0 1.8G 0% /dev
tmpfs 1.9G 0 1.9G 0% /dev/shm
tmpfs 1.9G 17M 1.8G 1% /run
tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup
/dev/sda2 10G 135M 9.9G 2% /boot
/dev/sda1 10G 9.8M 10G 1% /boot/efi
/dev/mapper/centos-var 330G 63G 268G 19% /var
tmpfs 370M 0 370M 0% /run/user/0
/dev/sdb1 466G 33M 466G 1% /usr/share/nginx/nextcloud/data
写入开机fstab
[root@fencatn html]# tail /etc/fstab
#
# Accessible filesystems, by reference, are maintained under ‘/dev/disk’
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
/dev/mapper/centos-root / xfs defaults 0 0
UUID=1ebba211-2749-4e5c-b9e2-73dd329e8594 /boot xfs defaults 0 0
UUID=19C4-024D /boot/efi vfat umask=0077,shortname=winnt 0 0
/dev/mapper/centos-var /var xfs defaults 0 0
/dev/mapper/centos-swap swap swap defaults 0 0
/dev/sdb1 /usr/share/nginx/nextcloud/data/ xfs defaults 0 0

授权web目录所属用户和组都为nginx
[root@fencatn html]# chown -R nginx.nginx /usr/share/nginx/nextcloud/
[root@fencatn html]# ll -d /usr/share/nginxnextcloud/
drwxr-xr-x 15 nginx nginx 4096 12月 8 01:57 /usr/share/nginx/nextcloud/

五、配置nginx虚拟主机
到nginx配置目录,新建一个虚拟主机配置文件
(我把官网的配置文件拖过来了,你可以参看这个网站的nextcloud目录)
upstream php-handler {
server 127.0.0.1:9000;
#server unix:/var/run/php5-fpm.sock;
}

server {
listen 80;
server_name 你自己的域名;
# enforce https
return 301 https://$server_name$request_uri;
}

server {
listen 443 ssl;
server_name 你自己的域名;

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/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|templates|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|jpg|jpeg)$ {
try_files $uri /index.php$uri$is_args$args;
# Optional: Don’t log access to other assets
access_log off;
}
}

完成以后,测试一下配置文件,一切正常就可以重启nginx服务了
[root@fencatn conf.d]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
[root@fencatn conf.d]# systemctl restart nginx

六、更改firewalld和selinux
我已经关了这两个玩意,你非要开的话自己找个官方文档改一下
[root@fencatn ~]# systemctl stop firewalld
[root@fencatn ~]# systemctl disable firewalld
[root@fencatn ~]# setenforce 0
[root@fencatn ~]# getenforce
disable
[root@fencatn ~]# cat /etc/sysconfig/selinux
……
SELINUX=disabled

如果打开了防火墙,则需要设置Firewalld和SELinux
首先需要安装SElinux管理工具policycoreutils-python
[root@fencatn ~]# yum -y install policycoreutils-python

接着设置SELinux
[root@fencatn ~]# semanage fcontext -a -t httpd_sys_rw_content_t ‘/usr/share/nginx/html/nextcloud/data(/.*)?’
[root@fencatn ~]# semanage fcontext -a -t httpd_sys_rw_content_t ‘/usr/share/nginx/html/nextcloud/config(/.*)?’
[root@fencatn ~]# semanage fcontext -a -t httpd_sys_rw_content_t ‘/usr/share/nginx/html/nextcloud/apps(/.*)?’
[root@fencatn ~]# semanage fcontext -a -t httpd_sys_rw_content_t ‘/usr/share/nginx/html/nextcloud/assets(/.*)?’
[root@fencatn ~]# semanage fcontext -a -t httpd_sys_rw_content_t ‘/usr/share/nginx/html/nextcloud/.htaccess’
[root@fencatn ~]# semanage fcontext -a -t httpd_sys_rw_content_t ‘/usr/share/nginx/html/nextcloud/.user.ini’
[root@fencatn ~]# restorecon -Rv ‘/usr/share/nginx/html/nextcloud/’

接下来设置Firewlld防火墙,为Nextcloud开放http和https两个端口
[root@fencatn ~]# systemctl start firewalld
[root@fencatn ~]# systemctl enable firewalld
[root@fencatn ~]# firewall-cmd –permanent –add-service=http
[root@fencatn ~]# firewall-cmd –permanent –add-service=https
[root@fencatn ~]# firewall-cmd –reload

七、安装Nextcloud
访问你的域名,我这里是局域网,直接 http://我的ip
(如果你只能用SQLite,那就是你的php-mysql没装成功,重新装一下)
设置管理员和密码,就可以了。

八、调优和使用
这篇文章已经够长了,我另外写了一篇,请参照另一篇文章。

此条目发表在Nextcloud分类目录,贴了标签。将固定链接加入收藏夹。

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注