如何在CentOS 7上安装ownCloud 9.1和Nginx和MariaDB
首页 > >    作者:lininn   2020年2月14日 20:53 星期五   热度:1579°   百度已收录  
时间:2020-2-14 20:53   热度:1579° 

第1步 - 安装Nginx和PHP7-FPM

在开始使用Nginx和php7-fpm安装之前,我们必须添加EPEL存储库,其中包含CentOS基本存储库中不可用的其他软件。 使用此yum命令安装EPEL。

yum -y install epel-release

现在从Epel资源库安装Nginx。

yum -y install nginx

现在我们必须为php7-fpm添加另一个存储库。 有几个可用于PHP 7的存储库,我将在这里使用webtatic存储库。

添加webtatic存储库:

rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm

接下来,为自己的Cloud安装安装PHP7-FPM和一些其他软件包。

yum -y install php70w-fpm php70w-cli php70w-gd php70w-mcrypt php70w-mysql php70w-pear php70w-xml php70w-mbstring php70w-pdo php70w-json

从服务器终端检查PHP版本,以确保安装成功。

php -v

检查PHP版本

第2步 - 配置PHP7-FPM

在这一步中,我们将配置php-fpm以运行nginx。 Php7-fpm将在用户nginx下运行,并监听9000端口。

使用vim编辑默认的php7-fpm配置。

vim /etc/php-fpm.d/www.conf

在第8行和第10行中,将用户和组更改为“ nginx ”。

user = nginx
group = nginx

在第22行中,确保php-fpm在服务器端口9000下运行。

listen = 127.0.0.1:9000

取消注释用于php-fpm系统环境变量的366-370行。

env[HOSTNAME] = $HOSTNAME
env[PATH] = /usr/local/bin:/usr/bin:/bin
env[TMP] = /tmp
env[TMPDIR] = /tmp
env[TEMP] = /tmp

保存文件并退出编辑器

接下来,为'/ var / lib /'目录中的会话路径创建一个新目录,并将所有者更改为'nginx'用户。

mkdir -p /var/lib/php/session
chown nginx:nginx -R /var/lib/php/session/

启动php-fpm和nginx,然后将其添加到启动时启动。

sudo systemctl start php-fpm
sudo systemctl start nginx

sudo systemctl enable php-fpm
sudo systemctl enable nginx

在CentOS上配置PHP-FPM

PHP7-FPM配置完成。

第3步 - 安装和配置MariaDB

OwnCloud支持PostgreSQL和MySQL数据库,在本教程中,我们将使用MariaDB作为ownCloud数据库。 使用yum命令从CentOS资源库安装mariadb-server软件包。

yum -y install mariadb mariadb-server

启动MariaDB服务并配置MariaDB root密码。

systemctl start mariadb
mysql_secure_installation

请求时输入您的root密码。

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

MariaDB根密码已经设置好了,现在我们可以登录到MySQL shell来创建一个新的数据库和用户为ownCloud.We将创建新的数据库'

我们将在用户“ ownclouduser ”下创建一个新的数据库“ owncloud_db ”,密码为“ ownclouduser @ ”。 请选择不同的安全密码进行安装!

mysql -u root -p
Type Password

在下面输入MySQL查询来创建一个新的数据库和一个新的用户。

create database owncloud_db;
create user ownclouduser@localhost identified by 'ownclouduser@';
grant all privileges on owncloud_db.* to ownclouduser@localhost identified by 'ownclouduser@';
flush privileges;

为ownCloud创建一个新的MySQL数据库

已创建用户“ownclouduser”的“owncloud_db数据库”。

第4步 - 生成自签名SSL证书

在本教程中,我们将在客户端的https连接下运行owncloud。 您可以使用免费的SSL证书,例如让我们进行加密。 在本教程中,我将使用OpenSSL命令创建自己的SSL证书文件。

为SSL文件创建新目录。

mkdir -p /etc/nginx/cert/

然后使用OpenSSL命令生成新的SSL证书文件。

openssl req -new -x509 -days 365 -nodes -out /etc/nginx/cert/owncloud.crt -keyout /etc/nginx/cert/owncloud.key

按照OpenSSL命令的要求输入SSL证书的详细信息。 然后使用chmod将所有证书文件的权限更改为600。

chmod 600 /etc/nginx/cert/*

创建自签名SSL证书

第5步 - 下载OwnCloud

我们将使用wget命令下载ownCloud,所以我们需要先安装wget包。 另外,我们需要解压缩包。

yum -y install wget unzip

转到tmp目录,并从具有wget的ownCloud站点下载最新的stable ownCloud 9.1。

cd /tmp
wget http://d2.smzy.com/2018/sort01523/smzy_OwnCloudTarball.zip

提取自己的Cloud zip文件并将其移动到'/ usr / share / nginx / html /'目录。

unzip owncloud-9.1.2.zip
mv owncloud/ /usr/share/nginx/html/

接下来,转到nginx web根目录,并为owncloud创建一个新的'data'目录。

cd /usr/share/nginx/html/
mkdir -p owncloud/data/

将'owncloud'目录的所有者更改为'nginx'用户和组。

chown nginx:nginx -R owncloud/

第6步 - 在Nginx中配置OwnCloud虚拟主机

在第5步,我们已经下载了ownCloud源代码并将其配置为在Nginx Web服务器下运行。 但是我们仍然需要为ownCloud配置虚拟主机。

在'conf.d'目录中创建一个新的虚拟主机配置文件'owncloud.conf'。

cd /etc/nginx/conf.d/
vim owncloud.conf

在下面粘贴ownCloud虚拟主机配置。



upstream php-handler {
    server 127.0.0.1:9000;
    #server unix:/var/run/php5-fpm.sock;
}
 
server {
    listen 80;
    server_name data.owncloud.co;
    # enforce https
    return 301 https://$server_name$request_uri;
}
 
server {
    listen 443 ssl;
    server_name data.owncloud.co;
 
    ssl_certificate /etc/nginx/cert/owncloud.crt;
    ssl_certificate_key /etc/nginx/cert/owncloud.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=15552000; includeSubDomains";
    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/html/owncloud/;
 
    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;
    }
 
    location /.well-known/acme-challenge { }
 
    # 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)/ {
        return 404;
    }
    location ~ ^/(?:\.|autotest|occ|issue|indie|db_|console) {
        return 404;
    }
 
    location ~ ^/(?:index|remote|public|cron|core/ajax/update|status|ocs/v[12]|updater/.+|ocs-provider/.+|core/templates/40[34])\.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;
        fastcgi_param modHeadersAvailable true; #Avoid sending the security headers twice
        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 $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=15552000; includeSubDomains";
        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配置,确保没有错误,然后重新启动服务。

nginx -t
systemctl restart nginx

如何修改挂载路径?

vi /usr/share/nginx/html/owncloud/config/config.php

找到 datadirectory 项,把后面的' /var/www/owncloud/data ‘修改为你想要设置的路径

设置文件访问权限,在终端输入命令

chown -R nginx:nginx /media/disk/data

chmod 777 /media/disk/data



不启用ssl配置owncloud.conf 







upstream php-handler {
    server 127.0.0.1:9000;
    #server unix:/var/run/php5-fpm.sock;
}

server {
    listen 80;
   

    # 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=15552000; includeSubDomains";
    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 /var/www/owncloud/;

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

    location /.well-known/acme-challenge { }

    # set max upload size
    client_max_body_size 16400M;
    fastcgi_buffers 64 4K;
    fastcgi_read_timeout 600;
    client_body_buffer_size 1048576k;
    client_body_temp_path /tmp/owncloud;
    
    # 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)/ {
        return 404;
    }
    location ~ ^/(?:\.|autotest|occ|issue|indie|db_|console) {
        return 404;
    }

    location ~ ^/(?:index|remote|public|cron|core/ajax/update|status|ocs/v[12]|updater/.+|ocs-provider/.+|core/templates/40[34])\.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;
        fastcgi_param modHeadersAvailable true; #Avoid sending the security headers twice
        fastcgi_param front_controller_active true;
        fastcgi_pass php-handler;
        fastcgi_intercept_errors on;
        fastcgi_request_buffering off; #Available since nginx 1.7.11
    }

    location ~ ^/(?:updater|ocs-provider)(?:$|/) {
        try_files $uri $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=15552000; includeSubDomains";
        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;
    }
}

owncloud 安装后提示php intl模块未安装?

 yum install php70w-intl

systemctl restart php-fpm

防止php和nginx上传过大报错413?


PHP.INI

$ sudo vi /etc/php/7.0/fpm/php.ini

##修改以下几个配置参数

; should be bit bigger than upload_max_filesize 16400M = 16G + 16M = 16 * 1025 MB
post_max_size = 16400M

; cannot be bigger than post_max_size
upload_max_filesize = 16G

; on online servers this could require bigger values (my server is at home)
max_input_time = 3600

; from ownCloud documentation - not sure if is required
output_buffering = Off

; not sure if it is required [3] but it seems like ownCloud needs time to move the file to it's
; final place after upload and that can take quite some time for big files
max_execution_time = 1800

; you may also want to point this to a folder having enough space for big files being uploaded
upload_tmp_dir = /tmp/owncloud

编辑nginx.conf


在http{client_max_body_size 50m;}设置允许上传的大小

之后killall nginx;

nginx重启就行了


sudo chown -R www-data:www-data /var/www/owncloud/




如果数据目录是移动硬盘 ,将移动硬盘格式化,mkfs.ext4 /forder ,之后执行权限赋值sudo chown -R www-data:www-data /data 即可

参考文章:


https://www.howtoing.com/owncloud-centos-install

https://anjia0532.github.io/2017/04/05/owncloud/

二维码加载中...
本文作者:lininn      文章标题: 如何在CentOS 7上安装ownCloud 9.1和Nginx和MariaDB
本文地址:?post=433
版权声明:若无注明,本文皆为“覆手为雨”原创,转载请保留文章出处。
分享本文至:

返回顶部    首页    手机版本    后花园   会员注册   
版权所有:覆手为雨    站长: lininn