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】獲取授權信息。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM