zoukankan      html  css  js  c++  java
  • nginx + php-fpm 搭建owncloud

    本文首发:https://www.cnblogs.com/somata/p/NgnixAndPhp-fpmBuildOwncloud.html

    今天新研究的nginx,用owncloud来测试一下学的怎么样。
    大部分都还是按之前的那篇来《Centos7 搭建owncloud云存储》。

    配置国内yum源

    mkdir /root/back
    mv /etc/yum.repos.d/* /root/back/    # 备份yum源
    curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo    # 配置国内yum源
    curl -o /etc/yum.repos.d/CentOS-epel.repo http://mirrors.aliyun.com/repo/epel-7.repo    # 添加扩展yun源
    curl -o /etc/yum.repos.d/CentOS-remi.repo https://mirrors.tuna.tsinghua.edu.cn/remi/enterprise/remi.repo    # 添加php源
    yum clean all    # 清除原始缓存
    rm -rf /var/cache/yum/x86_64/7/*    # 彻底删除缓存
    yum makecache    # 建立新的缓存
    

    remi的配置文件还不一定会使用国内源,这里还可是再改进以下关于remi的配置文件,强制生效:

    # file: rule
    
    s@mirrorlist@#mirrorlist@g
    s@#baseurl=http://rpms.remirepo.net@baseurl=http://mirrors.tuna.tsinghua.edu.cn/remi@g
    
    sed -i -f rule  /etc/yum.repos.d/CentOS-remi.repo
    

    安装LAMP环境

    yum -y install vim bzip2 bash-completion nginx mariadb mariadb-server php72-php-opcache php72-php php72-php-mysqlnd php72-php-cli php72-php-xml php72-php-mbstring php72-php-intl php72-php-gd php72-php-pecl-zip php72-php-fpm     # 安装必要软件
    

    配置使LAMP环境生效

    首先配置mariadb数据库。

    systemctl start mariadb	# 启动数据库
    mysql_secure_installation	# 使用命令快速设置数据库
    

    # 进入mysql 创建数据库用户
    mysql -uroot -p123456    # -p 后面跟设置的用户密码
    > CREATE DATABASE owncloud;     # 创建数据库
    > GRANT ALL PRIVILEGES ON owncloud.* TO 'owncloud'@'localhost' IDENTIFIED BY '123456';    # 创建用户,和相对应的用户权限
    > FLUSH PRIVILEGES;        # 刷新权限
    > exit
    

    然后配置nginx WEB服务

    # file: /etc/nginx/nginx.conf
    
    user nginx;
    worker_processes 1;
    worker_cpu_affinity 10;
    worker_priority -5;
    error_log /var/log/nginx/error.log;
    pid /run/nginx.pid;
    include /usr/share/nginx/modules/*.conf;
    events {
        worker_connections 1024;
    }
    http {
        log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                          '$status $body_bytes_sent "$http_referer" '
                          '"$http_user_agent" "$http_x_forwarded_for"';
        access_log  /var/log/nginx/access.log  main;
        sendfile            on;
        tcp_nopush          on;
        tcp_nodelay         on;
        keepalive_timeout   65;
        types_hash_max_size 2048;
        include             /etc/nginx/mime.types;
        default_type        application/octet-stream;
        include /etc/nginx/conf.d/*.conf;
        server {
            listen       80 default_server;
            listen       [::]:80 default_server;
            server_name  _;
            root         /var/www/html;
            include /etc/nginx/default.d/*.conf;
            location / {
            }
            error_page 404 /404.html;
                location = /40x.html {
            }
            error_page 500 502 503 504 /50x.html;
                location = /50x.html {
            }
            # 最主要的就是修改添加一下参数:
            # 这个我是之间从 https://blog.csdn.net/tojohnonly/article/details/78680779 这里复制过来的,然后稍微改了一点点。
            location ~ .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_pass 127.0.0.1:9000; 
            }
        }
    }
    

    启动服务

    systemctl start nginx
    systemctl start php72-php-fpm
    firewall-cmd --permanent --add-service=http
    firewall-cmd --reload
    

    装载owncloud云

    首先将下载的owncloud-10.2.0.tar.bz2 导入虚拟机。
    我这里使用了xshell自带的sftp命令传输文件。 如果使用的是putty可以使用psftp.exe 来完成。 注意该软件不支持图形化需要在命令行执行。详情用法自行百度

    # 进入上传owncloud文件的位置
    tar -xf owncloud-10.2.0.tar.bz2 -C /var/www/html/    # 解压网页
    # 调整一下默认的owncloud权限
    chown nobody:nobody -R /var/www/html/owncloud    # 修改属主为nobody,不能为apache. 因为里面有很多有写入权限的文件。不能让apache拥有
    mkdir data apps-external    # 手动创建文件
    chown apache:apache data apps apps-external config    # 设置这几个文件为apache权限
    chmod 775 apps config    # 2个文件权限配置
    # 配置SELinux的相关权限
    semanage fcontext -a -t httpd_sys_rw_content_t '/var/www/html/owncloud/data(/.*)?'
    semanage fcontext -a -t httpd_sys_rw_content_t '/var/www/html/owncloud/config(/.*)?'
    semanage fcontext -a -t httpd_sys_rw_content_t '/var/www/html/owncloud/apps(/.*)?'
    semanage fcontext -a -t httpd_sys_rw_content_t '/var/www/html/owncloud/apps-external(/.*)?'
    semanage fcontext -a -t httpd_sys_rw_content_t '/var/www/html/owncloud/.htaccess'
    semanage fcontext -a -t httpd_sys_rw_content_t '/var/www/html/owncloud/.user.ini'
    restorecon -Rv '/var/www/html/owncloud/'
    

    进入网页继续配置owncloud

    完成所有配置。 即可开始正常访问。

    根据之前配置的管理用户登录即可。


    本文经「原本」原创认证,作者乾坤盘,访问yuanben.io查询【2Z6774JB】获取授权信息。

  • 相关阅读:
    如何用Python实现网络请求库中的UR解析器,面试必学
    为什么有人说 Python 多线程是鸡肋?
    router-view 与 动态组件 区别
    keep-alive
    vue 客户端渲染和服务端渲染
    js 数组对象深拷贝
    vue template标签
    Jquery中的日历插件
    HTML5中的canvas基本概念及绘图
    HTML5中的音视频处理
  • 原文地址:https://www.cnblogs.com/somata/p/NgnixAndPhp-fpmBuildOwncloud.html
Copyright © 2011-2022 走看看