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

小柒助手 NextCloud评论5632字数 2076阅读6分55秒阅读模式

一、lnmp简介

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

Linux是一类Unix计算机操作系统的统称,是目前最流行的免费操作系统。代表版本有:debian、centos、ubuntu、fedora、gentoo等。
文章源自小柒网-https://www.yangxingzhen.cn/8936.html

Nginx是一个高性能的HTTP和反向代理服务器,也是一个IMAP/POP3/SMTP代理服务器。
文章源自小柒网-https://www.yangxingzhen.cn/8936.html

Mysql是一个小型关系型数据库管理系统。
文章源自小柒网-https://www.yangxingzhen.cn/8936.html

PHP是一种在服务器端执行的嵌入HTML文档的脚本语言。
文章源自小柒网-https://www.yangxingzhen.cn/8936.html

这四种软件均为免费开源软件,组合到一起,成为一个免费、高效、扩展性强的网站服务系统。
文章源自小柒网-https://www.yangxingzhen.cn/8936.html

二、Nextcloud简介

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

Nextcloud也提供了许多应用安装,包括但不限于Markdown在线编辑、OnlyOffice(需另外部署服务端)、思维导图、日历等,你可以自行选择以丰富个人网盘的功能。
文章源自小柒网-https://www.yangxingzhen.cn/8936.html

Nextcloud的服务端部署方式有很多种,本文采用基于LNMP环境安装。
文章源自小柒网-https://www.yangxingzhen.cn/8936.html

三、Yum安装Nginx

1)配置Centos 7 Nginx Yum源仓库
文章源自小柒网-https://www.yangxingzhen.cn/8936.html

[root@localhost ~]# rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
文章源自小柒网-https://www.yangxingzhen.cn/8936.html

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

  1. [mysql-connectors-community]
  2. name=MySQL Connectors Community
  3. baseurl=https://mirrors.tuna.tsinghua.edu.cn/mysql/yum/mysql-connectors-community-el7-$basearch/
  4. enabled=1
  5. gpgcheck=1
  6. gpgkey=https://repo.mysql.com/RPM-GPG-KEY-mysql
  7. [mysql-tools-community]
  8. name=MySQL Tools Community
  9. baseurl=https://mirrors.tuna.tsinghua.edu.cn/mysql/yum/mysql-tools-community-el7-$basearch/
  10. enabled=1
  11. gpgcheck=1
  12. gpgkey=https://repo.mysql.com/RPM-GPG-KEY-mysql
  13. [mysql-5.7-community]
  14. name=MySQL 5.7 Community Server
  15. baseurl=https://mirrors.tuna.tsinghua.edu.cn/mysql/yum/mysql-5.7-community-el7-$basearch/
  16. enabled=1
  17. gpgcheck=0
  18. 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

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

  1. user nginx nginx;
  2. worker_processes auto;
  3. pid /var/run/nginx.pid;
  4. events {
  5. use epoll;
  6. worker_connections 10240;
  7. multi_accept on;
  8. }
  9. http {
  10. include mime.types;
  11. default_type application/octet-stream;
  12. log_format main '$remote_addr - $remote_user [$time_local] "$request" '
  13. '$status $body_bytes_sent "$http_referer" '
  14. '"$http_user_agent" "$http_x_forwarded_for"';
  15. access_log /var/log/nginx/access.log main;
  16. error_log /var/log/nginx/error.log warn;
  17. sendfile on;
  18. tcp_nopush on;
  19. keepalive_timeout 120;
  20. tcp_nodelay on;
  21. server_tokens off;
  22. gzip on;
  23. gzip_min_length 1k;
  24. gzip_buffers 4 64k;
  25. gzip_http_version 1.1;
  26. gzip_comp_level 4;
  27. gzip_types text/plain application/x-javascript text/css application/xml;
  28. gzip_vary on;
  29. client_max_body_size 50m;
  30. client_body_buffer_size 128k;
  31. proxy_connect_timeout 90;
  32. proxy_send_timeout 90;
  33. proxy_buffer_size 4k;
  34. proxy_buffers 4 32k;
  35. proxy_busy_buffers_size 64k;
  36. large_client_header_buffers 4 4k;
  37. client_header_buffer_size 4k;
  38. open_file_cache_valid 30s;
  39. open_file_cache_min_uses 1;
  40. server {
  41. listen 80;
  42. server_name localhost;
  43. root /usr/share/nginx/html/nextcloud;
  44. add_header Referrer-Policy "no-referrer" always;
  45. add_header X-Content-Type-Options "nosniff" always;
  46. add_header X-Download-Options "noopen" always;
  47. add_header X-Frame-Options "SAMEORIGIN" always;
  48. add_header X-Permitted-Cross-Domain-Policies "none" always;
  49. add_header X-Robots-Tag "none" always;
  50. add_header X-XSS-Protection "1; mode=block" always;
  51. fastcgi_hide_header X-Powered-By;
  52. location ~ ^\/(?:index|remote|public|cron|core\/ajax\/update|status|ocs\/v[12]|updater\/.+|oc[ms]-provider\/.+)\.php(?:$|\/) {
  53. fastcgi_split_path_info ^(.+?\.php)(\/.*|)$;
  54. set $path_info $fastcgi_path_info;
  55. try_files $fastcgi_script_name =404;
  56. include fastcgi_params;
  57. fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  58. fastcgi_param PATH_INFO $path_info;
  59. fastcgi_param modHeadersAvailable true;
  60. fastcgi_param front_controller_active true;
  61. fastcgi_intercept_errors on;
  62. fastcgi_request_buffering off;
  63. fastcgi_pass 127.0.0.1:9000;
  64. }
  65. rewrite /.well-known/carddav /remote.php/dav permanent;
  66. rewrite /.well-known/caldav /remote.php/dav permanent;
  67. location / {
  68. rewrite ^ /index.php;
  69. }
  70. location ~ \.(?:png|html|ttf|ico|jpg|jpeg|bcmap)$ {
  71. try_files $uri /index.php$request_uri;
  72. access_log off;
  73. }
  74. location ~ ^\/(?:updater|oc[ms]-provider)(?:$|\/) {
  75. try_files $uri/ =404;
  76. index index.php;
  77. }
  78. location ~ ^\/(?:\.|autotest|occ|issue|indie|db_|console) {
  79. deny all;
  80. }
  81. location ~ ^\/(?:build|tests|config|lib|3rdparty|templates|data)\/ {
  82. deny all;
  83. }
  84. location ~ \.(?:css|js|woff2?|svg|gif|map)$ {
  85. try_files $uri /index.php$request_uri;
  86. add_header Cache-Control "public, max-age=15778463";
  87. add_header Referrer-Policy "no-referrer" always;
  88. add_header X-Content-Type-Options "nosniff" always;
  89. add_header X-Download-Options "noopen" always;
  90. add_header X-Frame-Options "SAMEORIGIN" always;
  91. add_header X-Permitted-Cross-Domain-Policies "none" always;
  92. add_header X-Robots-Tag "none" always;
  93. add_header X-XSS-Protection "1; mode=block" always;
  94. access_log off;
  95. }
  96. }
  97. }

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.cn/8936.html
匿名

发表评论

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

拖动滑块以完成验证
加载中...