一、# 先删除系统可能自带的PHP和nginx,用来面命令查找是否有安装
$ rpm -qa |grep php
$ rpm -qa |grep nginx
如果没有数据出来,就代表是干净的。
二、其实安装# 安装yum的epel源,这个是必须的 。
$ yum -y install epel-release
# 安装nginx
$ yum install -y nginx
# 安装php的源
$ rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
# 安装php已经会用到扩展(扩展我这里提一句,已经要安装完,不然会有一些莫名其妙的报错)
$ yum install -y php70w-devel php70w-pear php70w-pecl php70w-gd php70w-opcache php70w-cli php70w-pdo php70w-process php70w-pecl-apcu php70w-mcrypt php70w-mysql php70w-fpm php70w-pecl-memcached php70w-common php70w-xml php70w-mbstring php70w-pecl-igbinary php70w-json php70w-pecl-apcu-devel php70w-intl
# 检查是否安装成功
# nginx -v
nginx version: nginx/1.12.2
# php -v
PHP 7.0.31 (cli) (built: Jul 20 2018 08:55:22) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies
with Zend OPcache v7.0.31, Copyright (c) 1999-2017, by Zend Technologies
到此,这两个重要组件就安装成功了,然后我们来安装mysql.
三、nextcloud 还需要数据库,这里我使用的mysql,mysql提前安装好或使用已有的数据库服务器在mysql种创建一个新的databse用于nextcloud使用.
mysql 的安装我基本提一下,我安装的5.6的版本,建议小白也不要安装太高的版本。5.7以上需要去日志文件找随机的管理员密码,5.6默认管理员密码为空。
首先去mysql官网下载一个mysql80-community-release-el7-1.noarch.rpm 的链接,
然后 $ rpm -ivh mysql80-community-release-el7-1.noarch.rpm
开始可以安装mysql了,安装步骤:
Shell> vim /etc/yum.repos.d/mysql-community.repo
# Enable to use MySQL 5.6
[mysql56-community]
name=MySQL 5.6 Community Server
baseurl=http://repo.mysql.com/yum/mysql-5.6-community/el/6/$basearch/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
查看选择要使用的版本
#yum repolist all | grep mysql
查看已经开启需要安装的版本
#yum repolist enabled | grep mysql
Shell> yum clean all
Shell> yum makecache fast
Shell> yum install mysql-community-server mysql-community-devel mysql-community-client –y
Shell> service mysqld start
Shell> chkconfig mysqld on
Shell> mysqlsecure_installation
建议在修改yum源的时候,默认选一种数据库就好了。
然后进去mysql里面做一个向导就可以建库了。
四、
# 在装有mysql的服务器上执行
$ mysql -u root -p
> create database nextcloud_db;
# 授权给自定义用户,这里以用户名:nextclouduser,密码:nextcloudpasswd,代替。
> grant all privileges on nextcloud_db.* to nextclouduser@localhost identified by
‘nextcloudpasswd’;
> flush privileges;
五、
为nextcloud 生成自签名ssl证书
$ cd /etc/nginx/cert/ # 没有则创建此文件夹
$ openssl req -new -x509 -days 365 -nodes -out /etc/nginx/cert/nextcloud.crt -keyout /etc/nginx/cert/nextcloud.key #这里默认是365天,我本来想多搞几年,忘记了。还不知道下次怎么续订证书。呵呵
# 会出现下面的选项需要填写,可以随便填。
Country Name (2 letter code) [XX]:cn
//国家
State or Province Name (full name) []:guangdong
//省份
Locality Name (eg, city) [Default City]:guangzhou
//地区名字
Organization Name (eg, company) [Default Company Ltd]:Amos
//公司名
Organizational Unit Name (eg, section) []:Technology
//部门
Common Name (eg, your name or your server’s hostname) []:Amos //CA主机名
Email Address []:Amos@Amos.com //Email地址
# 修改证书和文件夹权限
$ chmod 600 /etc/nginx/cert/*
$ chmod 700 /etc/nginx/cert
六、
下载nextcloud,并配置php和nginx(这里我说一下,你也可以直接官网下载这个zip的包,然后直接放在服务器解压出来然后给相对应的权限)
# 下载nextcloud,官网地址为: https://nextcloud.com/install/#instructions-server
$ cd /usr/local/src
$ yum install -y wget unzip
$ wget https:
//download.nextcloud.com/server/releases/nextcloud-13.0.2.zip # 下载(这里虽然是13.0.2,后续会自动更新版本)
$ unzip nextcloud-13.0.2.zip
# 解压
$ mv nextcloud /usr/share/nginx/html/
# 移动到指定文件夹内
$ cd /usr/share/nginx/html/nextcloud
# 进行nextcloud 目录中
$ mkdir data
# 创建数据文件夹
$ chown nginx:nginx -R nextcloud/
# 将nextcloud文件授权给nginx_

配置php-fpm
$ vim /etc/php-fpm.d/www.conf
————————————————————————————————————————————-
user = nginx //将用户和组都改为nginx
group = nginx
listen = 127.0.0.1:9000
env[HOSTNAME] = $HOSTNAME //将以下几行,去掉注释
env[PATH] = /usr/local/bin:/usr/bin:/bin
env[TMP] = /tmp
env[TMPDIR] = /tmp
env[TEMP] = /tmp
—————————————————————————————————————————————

为php创建session文件夹
$ mkdir -p /var/lib/php/session
$ chown nginx:nginx -R /var/lib/php/session/

配置nginx
$ cd /etc/nginx/conf.d/
$ vim nextcloud.conf (这里说一下,这个代码一定要copy,我亲测过,没有报错)
—————————————————————————————————————————————-
upstream php-handler {
server 127.0.0.1:9000;
#server unix:/var/run/php5-fpm.sock;
}

server {
listen 80;
server_name localhost;
# enforce https
rewrite ^(.*)$ https://$host$1 permanent;
}

server {
listen 443 ssl;
server_name localhost;

  1. ssl_certificate /etc/nginx/cert/nextcloud.crt;<br /> ssl_certificate_key /etc/nginx/cert/nextcloud.key;
  2. # Add headers to serve security related headers<br /> # Before enabling Strict-Transport-Security headers please read into this<br /> # topic first.<br /> add_header Strict-Transport-Security "max-age=15768000;<br /> includeSubDomains; preload;";<br /> add_header X-Content-Type-Options nosniff;<br /> add_header X-Frame-Options "SAMEORIGIN";<br /> add_header X-XSS-Protection "1; mode=block";<br /> add_header X-Robots-Tag none;<br /> add_header X-Download-Options noopen;<br /> add_header X-Permitted-Cross-Domain-Policies none;
  3. # Path to the root of your installation<br /> root /usr/share/nginx/html/nextcloud/;
  4. location = /robots.txt {<br /> allow all;<br /> log_not_found off;<br /> access_log off;<br /> }
  5. # The following 2 rules are only needed for the user_webfinger app.<br /> # Uncomment it if you're planning to use this app.<br /> #rewrite ^/.well-known/host-meta /public.php?service=host-meta last;<br /> #rewrite ^/.well-known/host-meta.json /public.php?service=host-meta-json<br /> # last;
  6. location = /.well-known/carddav {<br /> return 301 $scheme://$host/remote.php/dav;<br /> }<br /> location = /.well-known/caldav {<br /> return 301 $scheme://$host/remote.php/dav;<br /> }
  7. # set max upload size<br /> client_max_body_size 10240M; # 上传文件最大限制,php.ini中也要修改,最后优化时会提及。<br /> fastcgi_buffers 64 4K;
  8. # Disable gzip to avoid the removal of the ETag header<br /> gzip on;<br /> gzip_vary on;<br /> gzip_comp_level 4;<br /> gzip_min_length 256;<br /> gzip_proxied expired no-cache no-store private no_last_modified no_etag auth;<br /> 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;
  9. # Uncomment if your server is build with the ngx_pagespeed module<br /> # This module is currently not supported.<br /> #pagespeed off;
  10. error_page 403 /core/templates/403.php;<br /> error_page 404 /core/templates/404.php;
  11. location / {<br /> rewrite ^ /index.php$uri;<br /> }
  12. location ~ ^/(?:build|tests|config|lib|3rdparty|templates|data)/ {<br /> deny all;<br /> }<br /> location ~ ^/(?:\.|autotest|occ|issue|indie|db_|console) {<br /> deny all;<br /> }
  13. location ~ ^/(?:index|remote|public|cron|core/ajax/update|status|ocs/v[12]|updater/.+|ocs-provider/.+|core/templates/40[34])\.php(?:$|/) {<br /> include fastcgi_params;<br /> fastcgi_split_path_info ^(.+\.php)(/.*)$;<br /> fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;<br /> fastcgi_param PATH_INFO $fastcgi_path_info;<br /> fastcgi_param HTTPS on;<br /> #Avoid sending the security headers twice<br /> fastcgi_param modHeadersAvailable true;<br /> fastcgi_param front_controller_active true;<br /> fastcgi_pass php-handler;<br /> fastcgi_intercept_errors on;<br /> fastcgi_request_buffering off;<br /> }
  14. location ~ ^/(?:updater|ocs-provider)(?:$|/) {<br /> try_files $uri/ =404;<br /> index index.php;<br /> }
  15. # Adding the cache control header for js and css files<br /> # Make sure it is BELOW the PHP block<br /> location ~* \.(?:css|js)$ {<br /> try_files $uri /index.php$uri$is_args$args;<br /> add_header Cache-Control "public, max-age=7200";<br /> # Add headers to serve security related headers (It is intended to<br /> # have those duplicated to the ones above)<br /> # Before enabling Strict-Transport-Security headers please read into<br /> # this topic first.<br /> add_header Strict-Transport-Security "max-age=15768000;includeSubDomains; preload;";<br /> add_header X-Content-Type-Options nosniff;<br /> add_header X-Frame-Options "SAMEORIGIN";<br /> add_header X-XSS-Protection "1; mode=block";<br /> add_header X-Robots-Tag none;<br /> add_header X-Download-Options noopen;<br /> add_header X-Permitted-Cross-Domain-Policies none;<br /> # Optional: Don't log access to assets<br /> access_log off;<br /> }
  16. location ~* \.(?:svg|gif|png|html|ttf|woff|ico|jpg|jpeg)$ {<br /> try_files $uri /index.php$uri$is_args$args;<br /> # Optional: Don't log access to other assets<br /> access_log off;<br /> }<br />}<br />-------------------------------------------------------------------------------------------

修改nginx原配置中80端口的配置
$ vim /etc/nginx/nginx.conf (这里我原来遇到一个坑,我是删除了80,但是不行,后来别人给我一份conf文件就行了,我把原来的文件代码贴出来。)

————————————————————————————
七、启动nginx和php-fpm

$ nginx -t # 检查nginx配置是否正确,出现下面输入则正确。
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

启动并设为开机启动 nginx,php-fpm
$ systemctl start nginx
$ systemctl enable nginx
$ systemctl start php-fpm
$ systemctl enable php-fpm

配置防火墙,开放http和https的端口。
$ firewall-cmd —add-port=80/tcp —permanent
$ firewall-cmd —add-port=443/tcp —permanent
$ firewall-cmd —reload

PS: 这里我的selinux是关闭的,如果selinux没有关闭,则执行下面命令关闭selinux
$ setenforce 0 # 关闭selinux
$ vim /etc/selinux/config # 修改配置,永久关闭。
———————————————————————————
SELINUX=disabled(添加这句话写在中间)
———————————————————————————
访问网页界面,完成安装。访问搭建nextcloud服务器的ip地址。(如果有域名就访问域名) 按照实际情况进行配置,配置完成后,点击安装完成。上图中mysql的主机名,使用上面我们自己的数据库服务器地址和端口

到此,如果一步一步安装,应该就可以看到成果了,也能进入到这个画面了。
下面我开始介绍我遇到的各种坑。