CentOS8/CentOS7 Nginx+PHP7.2+mysql8的NextCloud安装和容易出现问题的细节配置
本篇主要讲解CentOS8和CentOS7两个系统的nextcloud安装和配置方式,相较于CentOS7,CentOS8的配置就要简单很多。在以下讲解中会详细讲解到两个系统nginx、php、mysql8、mariadb10.3的安装和配置。目前nginx1.14、php7.2、mysql8、mariadb10.3都已经加入centos8官方源,使用和配置都简单很多。
讲在安装配置前:
1、 准备一台pc安装有centos7或centos8的虚拟机
2、 已安装mysql/mariadb
3、nextcloud 最新版
4、已开通指定的端口或者已做本地域名映射
如以上未安装,请自行安装配置。本篇因为篇幅问题,虚拟机和mysql就不再讲解
一、安装并配置php
1、下载php
Centos7需要单独下载php源
yum -y install epel-release rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
安装7.2及各种扩展
yum -y install php72w php72w-cli php72w-common php72w-devel php72w-embedded php72w-fpm php72w-gd php72w-mbstring php72w-mysqlnd php72w-opcache php72w-pdo php72w-xml php72w-json php72w-posix php72w-intl
centos8 安装php就很简单了,因为7.2版本已经放入官方仓库,直接yum install php-* 安装php所有。也可以按照以上的选定扩展方式安装,只需要去掉72w即可。
yum install php-*
启动服务
systemctl start php-fpm.service
查看php版本,php-fpm -v
[root@localhost]# php-fpm -v PHP 7.2.27 (fpm-fcgi) (built: Jan 26 2020 15:52:25) Copyright (c) 1997-2018 The PHP Group Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies with Zend OPcache v7.2.27, Copyright (c) 1999-2018, by Zend Technologies with Xdebug v2.6.1, Copyright (c) 2002-2018, by Derick Rethans
2、配置php
配置php.ini文件
vi /etc/php.ini
memory_limit = 1024M // 内存大小,大小可自行设定 post_max_size = 100M // 表单上传大小。默认为8M file_uploads = on // 是否允许上传文件。默on(开) upload_max_filesize = 100M // 文件上传大小。默认为2M
配置/etc/php-fpm.d/www.conf文件
vi /etc/php-fpm.d/www.conf
将用户和组都改为nginx
user = nginx group = nginx
php-fpm所监听的端口为9000
listen = 127.0.0.1:9000
去掉下面几行注释
env[HOSTNAME] = $HOSTNAME env[PATH] = /usr/local/bin:/usr/bin:/bin env[TMP] = /tmp env[TMPDIR] = /tmp env[TEMP] = /tmp
修复有关nextcloud内OPcache提示的问题
vi /etc/php.d/opcache.ini vi /etc/php.d/10-opcache.ini // CentOS8 php7.2在此位置
修改以下每个参数
opcache.enable=1 opcache.enable_cli=1 opcache.interned_strings_buffer=8 opcache.max_accelerated_files=10000 opcache.memory_consumption=128 opcache.save_comments=1 opcache.revalidate_freq=1
二、安装并配置nginx
Centos7 安装nginx1.16版本
创建nginx镜像源
vi /etc/yum.repos.d/nginx.repo
写入以下内容到nginx.repo
[nginx] name=nginx repo baseurl=http://nginx.org/packages/centos/7/$basearch/ gpgcheck=0 enabled=1
安装nginx
yum install -y nginx
查看版本
nginx –v
centos8 安装更简单了,nginx1.14版本已加入官方仓库,直接下载安装即可
yum install -y nginx
启动nginx
systemctl start nginx
安装完成后访问ip:端口,应该是这一个样子的
配置nginx.conf
vi /etc/nginx/nginx.conf
写入以下内容到nginx.conf
# For more information on configuration, see: # * Official English Documentation: http://nginx.org/en/docs/ # * Official Russian Documentation: http://nginx.org/ru/docs/ user nginx; worker_processes auto; error_log /var/log/nginx/error.log; pid /run/nginx.pid; # Load dynamic modules. See /usr/share/nginx/README.dynamic. 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; client_header_buffer_size 32k; large_client_header_buffers 4 32k; sendfile on; tcp_nopush on; tcp_nodelay on; server_tokens off; keepalive_timeout 60; types_hash_max_size 2048; client_max_body_size 8M; gzip on; gzip_vary on; gzip_min_length 1k; gzip_buffers 4 16k; gzip_http_version 1.0; gzip_comp_level 2; gzip_disable "MSIE [1-6]\."; gzip_types text/plain application/x-javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png; include /etc/nginx/mime.types; default_type application/octet-stream; # Load modular configuration files from the /etc/nginx/conf.d directory. # See http://nginx.org/en/docs/ngx_core_module.html#include # for more information. include /etc/nginx/conf.d/*.conf; }
创建ncloud.conf
vi /etc/nginx/conf.d/ncloud.conf
写入以下内容到ncloud.conf
server { server_name ncloud.rednn.cn; root /opt/ncloud; location / { root /opt/ncloud; index index.php index.html index.htm; try_files $uri $uri/ /index.php$is_args$args; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } location ~ ^\/(?:index|remote|public|cron|core\/ajax\/update|status|ocs\/v[12]|updater\/.+|oc[ms]-provider\/.+)\.php(?:$|\/) { fastcgi_split_path_info ^(.+?\.php)(\/.*|)$; fastcgi_pass 127.0.0.1:9000; fastcgi_intercept_errors on; fastcgi_index index.php; include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param PATH_INFO $fastcgi_path_info; #fastcgi_pass php-fpm; } location ~ ^/(?:build|tests|config|lib|3rdparty|templates|data)/ { deny all; } rewrite /.well-known/carddav /remote.php/dav permanent; rewrite /.well-known/caldav /remote.php/dav permanent; }
三、安装配置mysql8或mariadb10.3
Centos8 直接安装即可
安装mysql8
yum install mysql mysql-server //系统默认安装mysql8
安装mariadb10.3
yum install mariadb mariadb-server //系统默认安装mariadb10.3
Centos7 安装mariadb10.3,需要创建一个mariadb源镜像
创建MariaDB.repo源镜像
vi /etc/yum.repos.d/MariaDB.repo
写入以下内容到MariaDB.repo
# MariaDB 10.3 CentOS repository list - created 2019-02-05 09:00 UTC # http://downloads.mariadb.org/mariadb/repositories/ [mariadb] name = MariaDB baseurl = http://yum.mariadb.org/10.3/centos7-amd64 gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB gpgcheck=1
安装mariadb
yum install MariaDB-server MariaDB-client
启动mariadb
systemctl start mariadb
四、安装nextcloud
上传nextcloud并改名为ncloud(名字自己可以定)后,移动项目到nginx指定的/opt/内
在/var/lib目录下为session路径创建一个新的文件夹,并将用户名和组设为nginx
mkdir -p /var/lib/php/session chown nginx:nginx -R /var/lib/php/session/
并为Nextcloud创建data目录,将Nextcloud的用户和组修改为nginx
mkdir -p /opt/ncloud/data/ chown nginx:nginx -R /opt/cloud/
访问ip地址开始安装
五、安装完成后,在配置中看到一些错误信息的解决方案,以及一些配置技巧
关于缓存和一些其他错误信息,在php配置中就已经解决,如果还在提示错误,请翻到上面仔细部署
部署https后,提示15552000的问题
vi /etc/nginx/ncloud.conf
在443端口下面添加以下字段内容到ncloud.conf
add_header Strict-Transport-Security "max-age=15552000; includeSubDomains";
配置新用户默认语言
vi /opt/ncloud/config/config.php
添加该条指令后,新注册用户默认语言为中文简体
'default_language' => 'zh_CN',
配置新用户默认文件目录
vi /opt/ncloud/config/config.php
'skeletondirectory' => 'core/skeleton', // 配置文件内并没有这条命令,是默认的命令和skeleton目录 'skeletondirectory' => '/opt/skeleton', // 在opt下创建一个skeleton目录,在config.php内添加本段命令即可 'skeletondirectory' => '', // 参数为空时,创建新用户不拷贝任何文件,默认新用户目录为空
在安装应用界面提示:未找到适合当前版本的应用,'timeout' => 10,修改为300
vi /opt/cloud/lib/private/App/AppStore/Fetcher/Fetcher.php
$options = [ 'timeout' => 300, ];
安装Custom CSS(自定义css),安装后在主题选项css定义内添加以下css
/*关闭关于显示选项*/ li[data-id="firstrunwizard-about"] { display: none; } /*关闭帮助显示选项*/ li[data-id="help"] { display: none; } /*关闭移动桌面内容和个人设置内开源说明显示选项*/ div#clientsbox { display: none; } .followupsection { display: none; } /*关闭共享内容显示选项*/ div#fileSharingSettings { display: none; } /*关闭隐私内容显示选项*/ div#themes { display: none; }
其他更多配置可自行摸索,也可以找我交流
内存缓存配置
vi /opt/cloud/config/config.php
加入尾部括号上方
'memcache.locking' => '\OC\Memcache\Redis', 'memcache.local' => '\OC\Memcache\APCu', 'memcache.local' => '\OC\Memcache\Redis', 'redis' => array ( 'host' => 'localhost', 'port' => 6379, ),
同时,官方还推荐加入如下,来用于存储文件锁:
'memcache.locking' => '\OC\Memcache\Redis',
配置定时任务
crontab -u nginx -e
写入以下内容
*/15 * * * * php -f /opt/cloud/cron.php // 定时参数
crontab -u nginx -l // 检查定时任务是否生效
解决数据不能显示和下载的方案
在服务器端移动data.tar.gz数据到data/admin/files内的文件并不能在云盘显示。解决方法是:在本地新建一个记事本,命名为data.tar.gz,通过同步端上传到admin账户,然后删除同步目录。服务器端开始移动需要备份的数据data.tar.gz到data/admin/files替换原本假data.tar.gz文件。再次登录同步端新建同步目录,即可将替换过的data.tar.gz文件同步至本地。
注意:因为本地上传的记事本命名文件大小为0字节,所以服务器端移动数据覆盖后,在网页登录admin账户显示的数据大小还是为0字节,直接同步即可,同步的文件大小是覆盖后的实际文件大小,不影响。
更简单的方法是用命令处理
修改nginx账户的参数
vi /etc/passwd
将/sbin/nologin修改为/bin/bash
nginx:x:996:994:Nginx web server:/var/lib/nginx:/sbin/nologin
开始执行扫描,即可扫描出移动到data/admin/files内的文件
su - nginx -c 'php /opt/cloud/occ files:scan --all'
删除admin用户
su - nginx -c 'php /opt/cloud/occ user:delete admin'
重置admin用户密码,根据提示输入新的密码
su - nginx -c 'php /opt/cloud/occ user:resetpassword admin'
扫描完后记得nginx再修改回来
至此,配置完毕,欢迎指正!
如对配置不太明白或者不懂这些东西,都可以联系我进行交流
已获取点赞 +0
评论 点击评论