Centos 7安装lnmp环境+NextCloud私有网盘

小柒博客 NextCloud评论5352字数 9706阅读32分21秒阅读模式

一、lnmp简介

LNMP代表的就是:Linux系统下Nginx+MySQL+PHP这种网站服务器架构。

Linux是一类Unix计算机操作系统的统称,是目前最流行的免费操作系统。代表版本有:debian、centos、ubuntu、fedora、gentoo等。

Nginx是一个高性能的HTTP和反向代理服务器,也是一个IMAP/POP3/SMTP代理服务器。

Mysql是一个小型关系型数据库管理系统。

PHP是一种在服务器端执行的嵌入HTML文档的脚本语言。

这四种软件均为免费开源软件,组合到一起,成为一个免费、高效、扩展性强的网站服务系统。

二、Nextcloud简介

Nextcloud是一款开源免费的私有云存储网盘项目,可以让你快速便捷地搭建一套属于自己或团队的云同步网盘,从而实现跨平台跨设备文件同步、共享、版本控制、团队协作等功能。它的客户端覆盖了Windows、Mac、Android、iOS、Linux 等各种平台,也提供了网页端以及 WebDAV接口,所以你几乎可以在各种设备上方便地访问你的云盘。

Nextcloud也提供了许多应用安装,包括但不限于Markdown在线编辑、OnlyOffice(需另外部署服务端)、思维导图、日历等,你可以自行选择以丰富个人网盘的功能。

Nextcloud的服务端部署方式有很多种,本文采用基于LNMP环境安装。

三、Yum安装Nginx

1)配置Centos 7 Nginx Yum源仓库

[root@localhost ~]# rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm

Retrieving http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm

warning: /var/tmp/rpm-tmp.PiXlZn: Header V4 RSA/SHA1 Signature, key ID 7bd9bf62: NOKEY

Preparing... ################################# [100%]

Updating / installing...

    1:nginx-release-centos-7-0.el7.ngx ################################# [100%]

2)安装Nginx

[root@localhost ~]# yum -y install nginx

3)启动Nginx

[root@localhost ~]# systemctl start nginx

4)访问Nginx

5)Nginx默认地址和配置

/etc/nginx/nginx.conf          # Yum安装Nginx默认主配置文件

/usr/share/nginx/html        # Nginx默认存放目录

/usr/share/nginx/html/index.html        # Nginx默认主页路径

6)常用基本操作

1、启动Nginx

[root@localhost ~]# systemctl start nginx

2、停止Nginx

[root@localhost ~]# systemctl stop nginx

3、重载Nginx

[root@localhost ~]# systemctl reload nginx

4、重启Nginx

[root@localhost ~]# systemctl restart nginx

5、查询Nginx运行状态

[root@localhost ~]# systemctl status nginx

6、查询Nginx进程

[root@localhost ~]# ps -ef |grep nginx

7、查询Nginx监听端口

[root@localhost ~]# netstat -lntup |grep nginx

8、卸载Nginx

[root@localhost ~]# yum -y remove nginx

9、RPM方式安装升级指定版本Nginx

[root@localhost ~]# rpm -Uvh http://nginx.org/packages/centos/7/x86_64/RPMS/nginx-1.22.0-1.el7.ngx.x86_64.rpm

四、Yum安装MySQL

1)配置清华大学Yum源

[root@localhost ~]# vim /etc/yum.repos.d/mysql-community.repo

[mysql-connectors-community]
name=MySQL Connectors Community
baseurl=https://mirrors.tuna.tsinghua.edu.cn/mysql/yum/mysql-connectors-community-el7-$basearch/
enabled=1
gpgcheck=1
gpgkey=https://repo.mysql.com/RPM-GPG-KEY-mysql

[mysql-tools-community]
name=MySQL Tools Community
baseurl=https://mirrors.tuna.tsinghua.edu.cn/mysql/yum/mysql-tools-community-el7-$basearch/
enabled=1
gpgcheck=1
gpgkey=https://repo.mysql.com/RPM-GPG-KEY-mysql

[mysql-5.7-community]
name=MySQL 5.7 Community Server
baseurl=https://mirrors.tuna.tsinghua.edu.cn/mysql/yum/mysql-5.7-community-el7-$basearch/
enabled=1
gpgcheck=0
gpgkey=https://repo.mysql.com/RPM-GPG-KEY-mysql

2)安装MySQL-5.7

[root@localhost ~]# yum -y install mysql-community-server

3)启动MySQL

[root@localhost ~]# systemctl start mysqld

4)登录MySQL

1、查看初始化后生成的密码

[root@localhost ~]# grep 'password' /var/log/mysqld.log

2023-03-25T12:54:39.593636Z 1 [Note] A temporary password is generated for root@localhost: hiPZY4U6yZ_6

2、登录MySQL

[root@localhost ~]# mysql -uroot -p'hiPZY4U6yZ_6'

mysql: [Warning] Using a password on the command line interface can be insecure.

Welcome to the MySQL monitor. Commands end with ; or \g.

Your MySQL connection id is 2

Server version: 5.7.41

 

Copyright (c) 2000, 2023, Oracle and/or its affiliates.

 

Oracle is a registered trademark of Oracle Corporation and/or its

affiliates. Other names may be trademarks of their respective

owners.

 

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

# 初始化后需重置密码才能执行sql

mysql> set password=password('Aa123456@!');

Query OK, 0 rows affected, 1 warning (0.00 sec)

 

mysql> flush privileges;

Query OK, 0 rows affected (0.00 sec)

 

mysql> exit

# 验证修改后的密码是否正常登陆

[root@localhost ~]# mysql -uroot -p'Aa123456@!'

mysql: [Warning] Using a password on the command line interface can be insecure.

Welcome to the MySQL monitor. Commands end with ; or \g.

Your MySQL connection id is 3

Server version: 5.7.41 MySQL Community Server (GPL)

 

Copyright (c) 2000, 2023, Oracle and/or its affiliates.

 

Oracle is a registered trademark of Oracle Corporation and/or its

affiliates. Other names may be trademarks of their respective

owners.

 

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> select version();

+-----------+

| version()|

+-----------+

| 5.7.41   |

+-----------+

1 row in set (0.00 sec)

 

mysql> exit

五、Yum安装PHP

1)安装remi扩展源

remi源是Remi repository是包含最新版本PHP和MySQL包的Linux源,由Remi 提供维护。有这个源之后,使用YUM安装或更新PHP、MySQL、phpMyAdmin等服务器相关程序的时候就非常方便了。

[root@localhost ~]# yum -y install epel-release

[root@localhost ~]# yum -y install http://rpms.remirepo.net/enterprise/remi-release-7.rpm

2)安装Yum管理工具

[root@localhost ~]# yum -y install yum-utils

3)安装PHP

[root@localhost ~]# yum -y install php74-php-cli php74-php-common php74-php-devel php74-php-embedded php74-php-fpm php74-php-gd php74-php-mbstring php74-php-mysqlnd php74-php-pdo php74-php-opcache php74-php-xml php74-php-soap php74-php-imagick php74-php-intl php74-php-zip php74-php-bcmath

4)查看是否安装成功及php配置文件以及对应目录

[root@localhost ~]# rpm -qa |grep php74

[root@localhost ~]# rpm -ql php74-php-fpm

Centos 7安装lnmp环境+NextCloud私有网盘

5)建立软连接

[root@localhost ~]# ln -sf /opt/remi/php74/root/usr/bin/php* /usr/local/bin

6)查看PHP版本

[root@localhost ~]# php -v

PHP 7.4.33 (cli) (built: Feb 14 2023 08:49:52) ( NTS )

Copyright (c) The PHP Group

Zend Engine v3.4.0, Copyright (c) Zend Technologies

    with Zend OPcache v7.4.33, Copyright (c), by Zend Technologies

7)启动PHP-FPM

[root@localhost ~]# systemctl start php74-php-fpm

8)设置开机自启动

[root@localhost ~]# systemctl enable php74-php-fpm

9)常用基本操作

1、启动PHP

[root@localhost ~]# systemctl start php74-php-fpm

2、停止PHP

[root@localhost ~]# systemctl stop php74-php-fpm

3、重载PHP

[root@localhost ~]# systemctl reload php74-php-fpm

4、重启PHP

[root@localhost ~]# systemctl restart php74-php-fpm

5、查询PHP运行状态

[root@localhost ~]# systemctl status php74-php-fpm

6、查询PHP进程

[root@localhost ~]# ps -ef |grep php-fpm

7、查询PHP监听端口

[root@localhost ~]# netstat -lntup |grep php-fpm

8、卸载PHP

[root@localhost ~]# yum -y remove php74*

六、Nextcloud安装

1)安装依赖包

[root@localhost ~]# yum -y install wget unzip

2)下载Nextcloud软件包

[root@localhost ~]# wget https://download.nextcloud.com/server/releases/nextcloud-25.0.5.zip

3)解压Nextcloud到Nginx发布目录

[root@localhost ~]# unzip nextcloud-25.0.5.zip -d /usr/share/nginx/html

4)创建NextCloud 数据存储目录并为其设置权限

[root@localhost ~]# mkdir /usr/share/nginx/html/nextcloud/data

[root@localhost ~]# chown -R nginx.nginx /usr/share/nginx/html/nextcloud

5)配置nginx.conf

[root@localhost ~]# vim /etc/nginx/nginx.conf

    user nginx nginx;
    worker_processes auto;
    pid /var/run/nginx.pid;
events {
    use epoll;
    worker_connections 10240;
    multi_accept on;
    }
http {
    include       mime.types;
    default_type  application/octet-stream;
    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;
    error_log /var/log/nginx/error.log warn;
    sendfile        on;
    tcp_nopush          on;
    keepalive_timeout  120;
    tcp_nodelay         on;
    server_tokens off;
    gzip    on;
    gzip_min_length 1k;
    gzip_buffers    4 64k;
    gzip_http_version 1.1;
    gzip_comp_level 4;
    gzip_types      text/plain application/x-javascript text/css application/xml;
    gzip_vary       on;
    client_max_body_size 50m;
    client_body_buffer_size 128k;
    proxy_connect_timeout 90;
    proxy_send_timeout 90;
    proxy_buffer_size 4k;
    proxy_buffers 4 32k;
    proxy_busy_buffers_size 64k;
    large_client_header_buffers 4 4k;
    client_header_buffer_size 4k;
    open_file_cache_valid 30s;
    open_file_cache_min_uses 1;
server  {
    listen 80;
    server_name localhost;
    root /usr/share/nginx/html/nextcloud;
    add_header Referrer-Policy "no-referrer" always;
    add_header X-Content-Type-Options "nosniff" always;
    add_header X-Download-Options "noopen" always;
    add_header X-Frame-Options "SAMEORIGIN" always;
    add_header X-Permitted-Cross-Domain-Policies "none" always;
    add_header X-Robots-Tag "none" always;
    add_header X-XSS-Protection "1; mode=block" always;
    fastcgi_hide_header X-Powered-By;
    location ~ ^\/(?:index|remote|public|cron|core\/ajax\/update|status|ocs\/v[12]|updater\/.+|oc[ms]-provider\/.+)\.php(?:$|\/) {
    fastcgi_split_path_info ^(.+?\.php)(\/.*|)$;
    set $path_info $fastcgi_path_info;
    try_files $fastcgi_script_name =404;
    include fastcgi_params;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_param PATH_INFO $path_info;
    fastcgi_param modHeadersAvailable true;
    fastcgi_param front_controller_active true;
    fastcgi_intercept_errors on;
    fastcgi_request_buffering off;
    fastcgi_pass 127.0.0.1:9000;    
    }
    rewrite /.well-known/carddav /remote.php/dav permanent;
    rewrite /.well-known/caldav /remote.php/dav permanent;
    location / {
        rewrite ^ /index.php;
    }
    location ~ \.(?:png|html|ttf|ico|jpg|jpeg|bcmap)$ {
        try_files $uri /index.php$request_uri;
        access_log off;
    }
    location ~ ^\/(?:updater|oc[ms]-provider)(?:$|\/) {
        try_files $uri/ =404;
        index index.php;
    }
    location ~ ^\/(?:\.|autotest|occ|issue|indie|db_|console) {
        deny all;
    }
    location ~ ^\/(?:build|tests|config|lib|3rdparty|templates|data)\/ {
        deny all;
    }
    location ~ \.(?:css|js|woff2?|svg|gif|map)$ {
    try_files $uri /index.php$request_uri;
    add_header Cache-Control "public, max-age=15778463";
    add_header Referrer-Policy "no-referrer" always;
    add_header X-Content-Type-Options "nosniff" always;
    add_header X-Download-Options "noopen" always;
    add_header X-Frame-Options "SAMEORIGIN" always;
    add_header X-Permitted-Cross-Domain-Policies "none" always;
    add_header X-Robots-Tag "none" always;
    add_header X-XSS-Protection "1; mode=block" always;
    access_log off;
    }  
  }
}

6)配置php.ini

[root@localhost ~]# sed -i 's/post_max_size =.*/post_max_size = 50M/' /etc/opt/remi/php74/php.ini

[root@localhost ~]# sed -i 's/upload_max_filesize =.*/upload_max_filesize = 50M/' /etc/opt/remi/php74/php.ini

[root@localhost ~]# sed -i 's/memory_limit =.*/memory_limit = 1024M/' /etc/opt/remi/php74/php.ini

[root@localhost ~]# sed -i 's/apache/nginx/g' /etc/opt/remi/php74/php-fpm.d/www.conf

7)重载nginx、php-fpm

[root@localhost ~]# systemctl reload nginx

[root@localhost ~]# systemctl reload php74-php-fpm

8)创建nextcloud数据库及授权

[root@localhost ~]# mysql -hlocalhost -uroot -p'Aa123456@!' 2>/dev/null -e "create database nextcloud character set utf8 collate utf8_bin;"

[root@localhost ~]# mysql -hlocalhost -uroot -p'Aa123456@!' 2>/dev/null -e "create user nextcloud@'localhost' identified by 'Aa123456@';"

[root@localhost ~]# mysql -hlocalhost -uroot -p'Aa123456@!' 2>/dev/null -e "grant all on nextcloud.* to nextcloud@'localhost';"

[root@localhost ~]# mysql -hlocalhost -uroot -p'Aa123456@!' 2>/dev/null -e "flush privileges;"

9)Nextcloud安装配置

1、浏览器访问:http://192.168.0.199/,如下图所示

2、创建管理员账号和配置存储和数据库

3、安装推荐应用

4、安装完成


若文章图片、下载链接等信息出错,请在评论区留言反馈,博主将第一时间更新!如本文“对您有用”,欢迎随意打赏,谢谢!

继续阅读
Wechat
微信扫一扫,加我!
weinxin
微信公众号
微信扫一扫,关注我!
weinxin
小柒博客
  • 本文由 小柒博客 发表于 2023年4月1日20:55:37
  • 声明:本站所有文章,如无特殊说明或标注,本站文章均为原创。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。转载请务必保留本文链接:https://www.yangxingzhen.com/8936.html
匿名

发表评论

匿名网友
:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

拖动滑块以完成验证