新聞中心
在這篇文章中,我將向你展示如何在 centos 7 服務(wù)器中安裝和配置最新版本的 Nextcloud 13。我會(huì)通過(guò) Nginx 和 php7-FPM 來(lái)運(yùn)行 Nextcloud,同時(shí)使用 MariaDB 做為數(shù)據(jù)庫(kù)系統(tǒng)。

創(chuàng)新互聯(lián)主營(yíng)涿州網(wǎng)站建設(shè)的網(wǎng)絡(luò)公司,主營(yíng)網(wǎng)站建設(shè)方案,成都App制作,涿州h5小程序定制開(kāi)發(fā)搭建,涿州網(wǎng)站營(yíng)銷推廣歡迎涿州等地區(qū)企業(yè)咨詢
一、環(huán)境說(shuō)明
- 一個(gè)帶有50G云硬盤的CVM主機(jī)(騰訊云)
- CentOS 7.3 (騰訊云公共鏡像)
- SELinux關(guān)閉
- 已經(jīng)使用
yum update升級(jí)軟件
二、安裝Nginx
添加EPEL包的倉(cāng)庫(kù)源 yum -y install epel-release
通過(guò)EPEL倉(cāng)庫(kù)來(lái)安裝Nginx yum -y install nginx
三、安裝PHP7和PHP7-FPM
添加 PHP7-FPM webtatic 倉(cāng)庫(kù),并安裝PHP7以及功能相關(guān)的包。
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
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
四、配置PHP-FPM
我們需要配置 php-fpm 與 Nginx 協(xié)同運(yùn)行。php7-fpm 將使用 nginx 用戶來(lái)運(yùn)行,并監(jiān)聽(tīng) 9000 端口。
使用 vim 編輯默認(rèn)的 php7-fpm 配置文件。
vim /etc/php-fpm.d/www.conf
修改以下不連續(xù)的記錄點(diǎn),修改用戶,指定端口,啟用環(huán)境變量。
#Line 8-10
user = nginx
group = nginx
#Line 22
listen = 127.0.0.1:9000
#Line 366-370
env[HOSTNAME] = $HOSTNAME
env[PATH] = /usr/local/bin:/usr/bin:/bin
env[TMP] = /tmp
env[TMPDIR] = /tmp
env[TEMP] = /tmp
保存文件并退出 vim 編輯器.
需要在 /var/lib/ 目錄下創(chuàng)建一個(gè)新的文件夾 session,并將其擁有者變更為 nginx 用戶。最后啟動(dòng) php-fpm 和 Nginx,并且將它們?cè)O(shè)置為隨開(kāi)機(jī)啟動(dòng)的服務(wù)。
mkdir -p /var/lib/php/session
chown nginx:nginx -R /var/lib/php/session/
sudo systemctl start php-fpm
sudo systemctl start nginx
sudo systemctl enable php-fpm
sudo systemctl enable nginx
五、安裝MariaDB
這里使用 MariaDB 作為 Nextcloud 的數(shù)據(jù)庫(kù)??梢灾苯邮褂?yum 命令從 CentOS 默認(rèn)遠(yuǎn)程倉(cāng)庫(kù)中安裝 mariadb-server包。
yum -y install mariadb mariadb-server
systemctl start mariadb
systemctl enable mariadb
另外也可以選擇安裝MySQL之前建議更換yum為國(guó)內(nèi)的源,不然下載速度會(huì)很慢。這里有一篇我自己寫的博客,傳送門:http://blog.csdn.net/qq_36731677/article/details/76060519
六、配置MariaDB
使用MySQL初始化指令初始化root用戶,默認(rèn)密碼為空。
mysql_secure_installation
#配置過(guò)程
Set root password? [Y/n] Y
New password:
Re-enter new password:
Remove anonymous users? [Y/n] Y
Disallow root login remotely? [Y/n] Y
Remove test database and access to it? [Y/n] Y
Reload privilege tables now? [Y/n] Y
先使用命令登錄MySQL
mysql -u root -p
輸入以下 mysql 查詢語(yǔ)句來(lái)創(chuàng)建新的數(shù)據(jù)庫(kù)和用戶。
create database nextcloud;
create user nextclouduser@localhost identified by 'nextclouduser@';
grant all privileges on nextcloud_db.* to nextclouduser@localhost identified by 'nextclouduser@';
flush privileges;
exit
七、安裝SSL證書
我們可以自己生成SSL證書,也可以申請(qǐng)專業(yè)的SSL證書。
自簽名的SSL證書在使用的時(shí)候會(huì)報(bào)錯(cuò),建議使用有資質(zhì)的SSL證書。
安裝過(guò)程如下:
為 SSL 文件創(chuàng)建新目錄:
mkdir -p /etc/nginx/cert/
可以使用OpenSSL自簽名證書,但是更推薦使用具有官方認(rèn)證的SSL證書
openssl req -new -x509 -days 365 -nodes -out /etc/nginx/cert/cloud.example.com.crt -keyout /etc/nginx/cert/cloud.example.com.key
在該目錄下儲(chǔ)存申請(qǐng)過(guò)的SSL證書,并設(shè)置證書的權(quán)限:]
chmod 700 /etc/nginx/cert
chmod 600 /etc/nginx/cert/*
八、下載和初步安裝 Nextcloud
找到正確的官方下載庫(kù):https://download.nextcloud.com/server/releases/
安裝必要的下載解壓工具
yum -y install wget unzip
先進(jìn)入 /tmp 目錄,然后使用 wget 從官網(wǎng)下載最新的 Nextcloud 13。
cd /tmp
wget https://download.nextcloud.com/server/releases/nextcloud-13.0.0.zip
解壓 Nextcloud,并將其移動(dòng)到 /var/www 目錄。
mkdir /var/www/
unzip nextcloud-13.0.0.zip
mv nextcloud/ /var/www/
為NextCloud創(chuàng)建文件儲(chǔ)存文件夾,并授予一定的權(quán)限。
cd /var/www
mkdir -p nextcloud/data
chown nginx:nginx -R nextcloud/
手動(dòng)指定文件儲(chǔ)存位置
若想修改文件儲(chǔ)存的位置(比如你另外購(gòu)買了一塊云硬盤)
這時(shí)則需要編輯nextcloud的配置文件,修改datadirectory指向的文件夾。
vim /var/www/nextcloud/config/config.sample.php
將'datadirectory' => '/var/www/owncloud_data/'
修改為'datadirectory' => '你的路徑'
九、配置Nginx轉(zhuǎn)發(fā)規(guī)則
我們需要在Nginx的配置文件下寫入有關(guān)nextcloud的轉(zhuǎn)發(fā)協(xié)議。
我們可以直接新建一個(gè)配置文件并寫入信息,當(dāng)Nginx重新加載后就能使用配置文件了。
cd /etc/nginx/conf.d/
vim nextcloud.conf
根據(jù)個(gè)人需要修改并寫入配置:
- server_name需要改為域名
- ssl_certificate和ssl_certificate_key需要改為SSL證書對(duì)應(yīng)的文件
- root需要改為nextcloud文件夾所在路徑
- 配置數(shù)據(jù)來(lái)自nextcloud官方文檔
upstream php-handler {
server 127.0.0.1:9000;
#server unix:/var/run/php5-fpm.sock;
}
server {
listen 80;
listen [::]:80;
server_name cloud.example.com;
# enforce https
return 301 https://$server_name$request_uri;
}
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name cloud.example.com;
ssl_certificate /etc/ssl/nginx/cloud.example.com.crt;
ssl_certificate_key /etc/ssl/nginx/cloud.example.com.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;";
#
# WARNING: Only add the preload option once you read about
# the consequences in https://hstspreload.org/. This option
# will add the domain to a hardcoded list that is shipped
# in all major browsers and getting removed from this list
# could take several months.
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;
# Path to the root of your installation
root /var/www/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;
# Enable gzip but do not remove ETag headers
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;
# Uncomment if your server is build with the ngx_pagespeed module
# This module is currently not supported.
#pagespeed off;
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/.+)\.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 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|woff|svg|gif)$ {
try_files $uri /index.php$uri$is_args$args;
add_header Cache-Control "public, max-age=15778463";
# 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;";
#
# WARNING: Only add the preload option once you read about
# the consequences in https://hstspreload.org/. This option
# will add the domain to a hardcoded list that is shipped
# in all major browsers and getting removed from this list
# could take several months.
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;
# Optional: Don't log access to assets
access_log off;
}
location ~ \.(?:png|html|ttf|ico|jpg|jpeg)$ {
try_files $uri /index.php$uri$is_args$args;
# Optional: Don't log access to other assets
access_log off;
}
}
檢驗(yàn)一下配置的正確性之后就能用域名訪問(wèn)網(wǎng)盤了
nginx -t
systemctl restart nginx
常見(jiàn)錯(cuò)誤
有可能你在訪問(wèn)頁(yè)面時(shí)可以正常顯示但是提示你“內(nèi)部服務(wù)器錯(cuò)誤”,若出現(xiàn)這個(gè)情況有兩個(gè)可能:
- Nginx對(duì)nextcloud文件夾的訪問(wèn)權(quán)限不夠,使用如下操作重新給予權(quán)限
cd /var/www
mkdir -p nextcloud/data
chown nginx:nginx -R nextcloud/
- SELinux未關(guān)閉
永久關(guān)閉SELinux需要編輯文件/etc/selinux/config,將SELINUX=enforcing修改為SELINUX=disabled,重啟后生效
臨時(shí)關(guān)閉SELinux只需要在shell中輸入setenforce 0就可以臨時(shí)關(guān)閉SELinux。
文章標(biāo)題:CentOS7使用Nginx+MariaDB+PHP安裝Nextcloud13
分享路徑:http://fisionsoft.com.cn/article/cdepegc.html


咨詢
建站咨詢
